From e1d14a08cb6c56ba129ac6600e3eb5dade7ab01d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 11 Apr 2015 09:39:04 -0400 Subject: [PATCH] More TODO resolution. --- util_windows.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/util_windows.c b/util_windows.c index 4959a703..e3332be7 100644 --- a/util_windows.c +++ b/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; }