diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-11 09:39:04 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-11 09:39:04 -0400 |
| commit | 42b8e408164d3478326d8b73acbacd667efc6fa6 (patch) | |
| tree | 20991bce44caa7f127e00f39815052b305602d6c /new/util_windows.c | |
| parent | 1ab2a819036d07eb70252712eabd4e9e4d653c59 (diff) | |
More TODO resolution.
Diffstat (limited to 'new/util_windows.c')
| -rw-r--r-- | new/util_windows.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/new/util_windows.c b/new/util_windows.c index 4959a70..e3332be 100644 --- a/new/util_windows.c +++ b/new/util_windows.c @@ -3,7 +3,7 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd) { - int len; + LRESULT len; WCHAR *text; HDC dc; HFONT prevfont; @@ -11,13 +11,17 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd) size.cx = 0; size.cy = 0; - // TODO check for error - len = GetWindowTextLengthW(hwnd); + + // first we need the window text + len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); if (len == 0) // no text; nothing to do return 0; text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); - if (GetWindowText(hwnd, text, len + 1) == 0) // should only happen on error given explicit test for len == 0 above + // note the comparison: the size includes the null terminator, but the return does not + if (GetWindowText(hwnd, text, len + 1) != len) logLastError("error getting window text in uiWindowsWindowTextWidth()"); + + // now we can do the calculations dc = GetDC(hwnd); if (dc == NULL) logLastError("error getting DC in uiWindowsWindowTextWidth()"); @@ -31,5 +35,6 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd) if (ReleaseDC(hwnd, dc) == 0) logLastError("error releasing DC in uiWindowsWindowTextWidth()"); uiFree(text); + return size.cx; } |
