Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential solution to differentiate an error with an empty string on line 299 todo #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pygetwindow/_pygetwindow_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ def title(self):
"""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):
Expand Down