From 34265146e9a9f05bba653f5abc99950e4f9ff607 Mon Sep 17 00:00:00 2001 From: Cheesenthusiast <111305449+Cheesenthusiast@users.noreply.github.com> Date: Mon, 30 Jan 2023 10:27:24 -0800 Subject: [PATCH 1/2] Update _pygetwindow_win.py --- src/pygetwindow/_pygetwindow_win.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pygetwindow/_pygetwindow_win.py b/src/pygetwindow/_pygetwindow_win.py index 0e126d5..2303b82 100644 --- a/src/pygetwindow/_pygetwindow_win.py +++ b/src/pygetwindow/_pygetwindow_win.py @@ -291,13 +291,15 @@ def isActive(self): @property def title(self): - """Returns the window title as a string.""" + """Returns the window title as a string.""" textLenInCharacters = ctypes.windll.user32.GetWindowTextLengthW(self._hWnd) stringBuffer = ctypes.create_unicode_buffer(textLenInCharacters + 1) # +1 for the \0 at the end of the null-terminated string. + ctypes.windll.kernel32.SetLastError(0) ctypes.windll.user32.GetWindowTextW(self._hWnd, stringBuffer, textLenInCharacters + 1) - - # TODO it's ambiguous if an error happened or the title text is just empty. Look into this later. - return stringBuffer.value + if ctypes.windll.kernel32.GetLastError() != 0: + _raiseWithLastError() + else: + return stringBuffer.value @property def visible(self): From baaa4f2418527160baf383b3a163d46730d31f1e Mon Sep 17 00:00:00 2001 From: Cheesenthusiast <111305449+Cheesenthusiast@users.noreply.github.com> Date: Tue, 31 Jan 2023 15:38:29 -0800 Subject: [PATCH 2/2] Update _pygetwindow_win.py --- src/pygetwindow/_pygetwindow_win.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pygetwindow/_pygetwindow_win.py b/src/pygetwindow/_pygetwindow_win.py index 2303b82..ffc5b8d 100644 --- a/src/pygetwindow/_pygetwindow_win.py +++ b/src/pygetwindow/_pygetwindow_win.py @@ -291,7 +291,7 @@ def isActive(self): @property def title(self): - """Returns the window title as a string.""" + """Returns the window title as a string.""" textLenInCharacters = ctypes.windll.user32.GetWindowTextLengthW(self._hWnd) stringBuffer = ctypes.create_unicode_buffer(textLenInCharacters + 1) # +1 for the \0 at the end of the null-terminated string. ctypes.windll.kernel32.SetLastError(0)