More TODO resolution.

This commit is contained in:
Pietro Gagliardi 2015-04-11 09:39:04 -04:00
parent 1ab2a81903
commit 42b8e40816
1 changed files with 9 additions and 4 deletions

View File

@ -3,7 +3,7 @@
intmax_t uiWindowsWindowTextWidth(HWND hwnd) intmax_t uiWindowsWindowTextWidth(HWND hwnd)
{ {
int len; LRESULT len;
WCHAR *text; WCHAR *text;
HDC dc; HDC dc;
HFONT prevfont; HFONT prevfont;
@ -11,13 +11,17 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd)
size.cx = 0; size.cx = 0;
size.cy = 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 if (len == 0) // no text; nothing to do
return 0; return 0;
text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); 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()"); logLastError("error getting window text in uiWindowsWindowTextWidth()");
// now we can do the calculations
dc = GetDC(hwnd); dc = GetDC(hwnd);
if (dc == NULL) if (dc == NULL)
logLastError("error getting DC in uiWindowsWindowTextWidth()"); logLastError("error getting DC in uiWindowsWindowTextWidth()");
@ -31,5 +35,6 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd)
if (ReleaseDC(hwnd, dc) == 0) if (ReleaseDC(hwnd, dc) == 0)
logLastError("error releasing DC in uiWindowsWindowTextWidth()"); logLastError("error releasing DC in uiWindowsWindowTextWidth()");
uiFree(text); uiFree(text);
return size.cx; return size.cx;
} }