Fixed compiler warnings. Stack works!

This commit is contained in:
Pietro Gagliardi 2015-04-07 19:36:46 -04:00
parent 42204af086
commit 12021269b7
4 changed files with 12 additions and 11 deletions

View File

@ -60,15 +60,15 @@ void resize(uiControl *control, HWND parent, RECT r)
{
uiSizing d;
HDC dc;
HFONT prevFont;
HFONT prevfont;
TEXTMETRICW tm;
SIZE size;
dc = GetDC(parent);
if (dc == NULL)
logLastError("error getting DC for preferred size calculations");
prevFont = (HFONT) SelectObject(dc, hMessageFont);
if (prevFont == NULL)
prevfont = (HFONT) SelectObject(dc, hMessageFont);
if (prevfont == NULL)
logLastError("error loading control font into device context for preferred size calculation");
if (GetTextMetricsW(dc, &tm) == 0)
logLastError("error getting text metrics for preferred size calculations");
@ -77,7 +77,7 @@ void resize(uiControl *control, HWND parent, RECT r)
d.baseX = (int) ((size.cx / 26 + 1) / 2);
d.baseY = (int) tm.tmHeight;
d.internalLeading = tm.tmInternalLeading;
if (SelectObject(dc, prevFont) != hMessageFont)
if (SelectObject(dc, prevfont) != hMessageFont)
logLastError("error restoring previous font into device context after preferred size calculations");
if (ReleaseDC(parent, dc) == 0)
logLastError("error releasing DC for preferred size calculations");

View File

@ -20,7 +20,7 @@ static void loadLastError(uiInitError *err, const char *message)
le = GetLastError();
// TODO FormatMessageW() it
// TODO make sure argument is right; _snprintf_s() isn't supported on Windows XP
sprintf(err->failbuf, 256, "error %s (last error %I32u)", message, le);
snprintf(err->failbuf, 256, "error %s (last error %I32u)", message, le);
err->msg = err->failbuf;
}

View File

@ -43,7 +43,7 @@ int main(int argc, char *argv[])
uiWindowSetChild(w, stack);
button2 = uiNewButton("Change Me");
uiButtonOnClicked(button, onClicked2, NULL);
uiButtonOnClicked(button2, onClicked2, NULL);
button = uiNewButton("Click Me");
uiButtonOnClicked(button, onClicked, button2);

View File

@ -24,6 +24,7 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd)
WCHAR *text;
HDC dc;
HFONT prevfont;
SIZE size;
// TODO check for error
len = GetWindowTextLengthW(hwnd);
@ -32,17 +33,17 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd)
text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR));
if (GetWindowText(hwnd, text, len + 1) == 0) // should only happen on error given explicit test for len == 0 above
logLastError("error getting window text in uiWindowsWindowTextWidth()");
dc = GetDC(parent);
dc = GetDC(hwnd);
if (dc == NULL)
logLastError("error getting DC in uiWindowsWindowTextWidth()");
prevFont = (HFONT) SelectObject(dc, hMessageFont);
if (prevFont == NULL)
prevfont = (HFONT) SelectObject(dc, hMessageFont);
if (prevfont == NULL)
logLastError("error loading control font into device context in uiWindowsWindowTextWidth()");
if (GetTextExtentPoint32W(dc, text, len, &size) == 0)
logLastError("error getting text extent point in uiWindowsWindowTextWidth()");
if (SelectObject(dc, prevFont) != hMessageFont)
if (SelectObject(dc, prevfont) != hMessageFont)
logLastError("error restoring previous font into device context in uiWindowsWindowTextWidth()");
if (ReleaseDC(parent, dc) == 0)
if (ReleaseDC(hwnd, dc) == 0)
logLastError("error releasing DC in uiWindowsWindowTextWidth()");
uiFree(text);
return size.cx;