From 12021269b7789a680bf1286616505a7546f26d93 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 19:36:46 -0400 Subject: [PATCH] Fixed compiler warnings. Stack works! --- new/container_windows.c | 8 ++++---- new/init_windows.c | 2 +- new/test.c | 2 +- new/util_windows.c | 11 ++++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/new/container_windows.c b/new/container_windows.c index 152ce3a..90ebab1 100644 --- a/new/container_windows.c +++ b/new/container_windows.c @@ -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"); diff --git a/new/init_windows.c b/new/init_windows.c index bfc92a9..7b01b1a 100644 --- a/new/init_windows.c +++ b/new/init_windows.c @@ -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; } diff --git a/new/test.c b/new/test.c index 1d9cec5..ac07996 100644 --- a/new/test.c +++ b/new/test.c @@ -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); diff --git a/new/util_windows.c b/new/util_windows.c index c0d3d6c..8e0532b 100644 --- a/new/util_windows.c +++ b/new/util_windows.c @@ -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;