diff --git a/windows/area.cpp b/windows/area.cpp index 061335fa..df2bc4c3 100644 --- a/windows/area.cpp +++ b/windows/area.cpp @@ -79,7 +79,6 @@ ATOM registerAreaClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) void unregisterArea(void) { - unregisterAreaFilter(); if (UnregisterClassW(areaClass, hInstance) == 0) logLastError(L"error unregistering uiArea window class"); } diff --git a/windows/area.hpp b/windows/area.hpp index 52261c5b..6b82532d 100644 --- a/windows/area.hpp +++ b/windows/area.hpp @@ -38,7 +38,6 @@ extern void areaUpdateScroll(uiArea *a); // areaevents.cpp extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern void unregisterAreaFilter(void); // areautil.cpp extern void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height); diff --git a/windows/areaevents.cpp b/windows/areaevents.cpp index 516690d7..82be7c29 100644 --- a/windows/areaevents.cpp +++ b/windows/areaevents.cpp @@ -395,7 +395,7 @@ BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *l // TODO affect visibility properly // TODO what did this mean -static BOOL areaFilter(MSG *msg) +BOOL areaFilter(MSG *msg) { LRESULT handled; diff --git a/windows/debug.cpp b/windows/debug.cpp index 2c1ad629..7b0f35f8 100644 --- a/windows/debug.cpp +++ b/windows/debug.cpp @@ -1,6 +1,14 @@ // 25 february 2015 #include "uipriv_windows.hpp" +// TODO +void complain(const char *format, ...) +{ + OutputDebugStringA(format); + DebugBreak(); + abort(); +} + // TODO disable logging and stopping on no-debug builds // TODO are the newlines needed? diff --git a/windows/parent.cpp b/windows/parent.cpp index 7076b20b..3b727665 100644 --- a/windows/parent.cpp +++ b/windows/parent.cpp @@ -9,15 +9,15 @@ static HBRUSH parentBrush = NULL; static HWND parentWithBackground(HWND hwnd) { HWND parent; - int class; + int cls; parent = hwnd; for (;;) { parent = parentOf(parent); // skip groupboxes; they're (supposed to be) transparent // skip uiContainers; they don't draw anything - class = windowClassOf(parent, L"button", containerClass, NULL); - if (class != 0 && class != 1) + cls = windowClassOf(parent, L"button", containerClass, NULL); + if (cls != 0 && cls != 1) break; } return parent; @@ -41,7 +41,7 @@ static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd) pd->bitmap = CreateCompatibleBitmap(dc, r.right - r.left, r.bottom - r.top); if (pd->bitmap == NULL) return logLastError(L"error creating compatible bitmap"); - pd->prevbitmap = SelectObject(pd->cdc, pd->bitmap); + pd->prevbitmap = (HBITMAP) SelectObject(pd->cdc, pd->bitmap); if (pd->prevbitmap == NULL) return logLastError(L"error selecting bitmap into compatible DC"); SendMessageW(parent, WM_PRINTCLIENT, (WPARAM) (pd->cdc), PRF_CLIENT); @@ -52,7 +52,7 @@ static void endParentDraw(struct parentDraw *pd) { // continue in case of any error if (pd->prevbitmap != NULL) - if (SelectObject(pd->cdc, pd->prevbitmap) != pd->bitmap) + if (((HBITMAP) SelectObject(pd->cdc, pd->prevbitmap)) != pd->bitmap) logLastError(L"error selecting previous bitmap back into compatible DC"); if (pd->bitmap != NULL) if (DeleteObject(pd->bitmap) == 0) @@ -69,6 +69,7 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) RECT hwndScreenRect; struct parentDraw pd; HBRUSH brush; + HRESULT hr; parent = parentWithBackground(hwnd); @@ -107,7 +108,7 @@ void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect) parent = parentWithBackground(hwnd); hr = parentDraw(dc, parent, &pd); if (hr != S_OK) // we couldn't get it; draw nothing - return NULL; + return; paintRectParent = *paintRect; mapWindowRect(hwnd, parent, &paintRectParent); diff --git a/windows/radiobuttons.cpp b/windows/radiobuttons.cpp index c95d32a1..3a754224 100644 --- a/windows/radiobuttons.cpp +++ b/windows/radiobuttons.cpp @@ -27,11 +27,10 @@ static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult uiRadioButtons *r = uiRadioButtons(c); WPARAM check; uintmax_t i; - HWND hwnd; if (code != BN_CLICKED) return FALSE; - for (hwnd : *(r->hwnds)) { + for (const HWND &hwnd : *(r->hwnds)) { check = BST_UNCHECKED; if (clicked == hwnd) check = BST_CHECKED; @@ -43,9 +42,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult static void onDestroy(uiRadioButtons *r) { - HWND hwnd; - - for (hwnd : *(r->hwnds)) { + for (const HWND &hwnd : *(r->hwnds)) { uiWindowsUnregisterWM_COMMANDHandler(hwnd); uiWindowsEnsureDestroyWindow(hwnd); } @@ -69,7 +66,7 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width maxwid = wid; } *width = uiWindowsDlgUnitsToX(radiobuttonXFromLeftOfBoxToLeftOfLabel, d->BaseX) + maxwid; - *height = uiWindowsDlgUnitsToY(radiobuttonHeight, d->BaseY) * r->hwnds->len; + *height = uiWindowsDlgUnitsToY(radiobuttonHeight, d->BaseY) * r->hwnds->size(); } static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) @@ -78,7 +75,6 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in uiWindowsSizing *d; intmax_t height1; intmax_t h; - HWND hwnd; uiWindowsEnsureMoveWindowDuringResize(r->hwnd, x, y, width, height); @@ -87,7 +83,7 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in d = uiWindowsNewSizing(r->hwnd); height1 = uiWindowsDlgUnitsToY(radiobuttonHeight, d->BaseY); uiWindowsFreeSizing(d); - for (hwnd : *(r->hwnds)) { + for (const HWND &hwnd : *(r->hwnds)) { h = height1; if (h > height) // clip to height h = height; @@ -105,13 +101,12 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in static void redoControlIDsZOrder(uiRadioButtons *r) { - HWND hwnd; LONG_PTR controlID; HWND insertAfter; controlID = 100; insertAfter = NULL; - for (hwnd : *(r->hwnds)) { + for (const HWND &hwnd : *(r->hwnds)) { uiWindowsEnsureAssignControlIDZOrder(hwnd, controlID, insertAfter); controlID++; insertAfter = hwnd; diff --git a/windows/text.cpp b/windows/text.cpp index 785a94a3..4beeccd7 100644 --- a/windows/text.cpp +++ b/windows/text.cpp @@ -67,7 +67,7 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd) goto noTextOrError; } if (GetTextExtentPoint32W(dc, text, len, &size) == 0) { - logLastError("error getting text extent point"); + logLastError(L"error getting text extent point"); // continue anyway, assuming size is 0 size.cx = 0; size.cy = 0; diff --git a/windows/utf16.cpp b/windows/utf16.cpp index 701efb5a..02c1872f 100644 --- a/windows/utf16.cpp +++ b/windows/utf16.cpp @@ -62,7 +62,7 @@ WCHAR *utf16dup(const WCHAR *orig) } // if recursing is TRUE, do NOT recursively call wstrf() in logHRESULT() -static WCHAR *strfcore(BOOL recursing, WCHAR *format, va_list ap) +static WCHAR *strfcore(BOOL recursing, const WCHAR *format, va_list ap) { va_list ap2; WCHAR *buf; @@ -73,13 +73,13 @@ static WCHAR *strfcore(BOOL recursing, WCHAR *format, va_list ap) return emptyUTF16(); va_copy(ap2, ap); - hr = SafeCchVPrintfEx(NULL, 0, + hr = StringCchVPrintfExW(NULL, 0, NULL, &n, STRSAFE_IGNORE_NULLS, format, ap2); va_end(ap2); if (hr != S_OK && hr != STRSAFE_E_INSUFFICIENT_BUFFER) { - if (!failing) + if (!recursing) logHRESULT(L"error determining needed buffer size", hr); return emptyUTF16(); } @@ -87,12 +87,12 @@ static WCHAR *strfcore(BOOL recursing, WCHAR *format, va_list ap) // n includes the terminating L'\0' buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - hr = SafeCchVPrintfEx(buf, n, // TODO what about this? + hr = StringCchVPrintfExW(buf, n, // TODO what about this? NULL, NULL, 0, format, ap); if (hr != S_OK) { - if (!failing) + if (!recursing) logLastError(L"error formatting string", hr); // and return an empty string *buf = L'\0'; @@ -117,7 +117,7 @@ WCHAR *vstrf(const WCHAR *format, va_list ap) return strfcore(FALSE, format, ap); } -WCHAR *debugstrf(const WCHAR *format, ..) +WCHAR *debugstrf(const WCHAR *format, ...) { va_list ap; WCHAR *str; @@ -141,7 +141,7 @@ char *LFtoCRLF(const char *lfonly) char *out; len = strlen(lfonly); - crlf = (char *) uiAlloc((only * 2 + 1) * sizeof (char), "char[]"); + crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]"); out = crlf; for (i = 0; i < len; i++) { if (*lfonly == '\n') @@ -160,7 +160,7 @@ void CRLFtoLF(char *s) // be sure to preserve \rs that are genuinely there if (*s == '\r' && *(s + 1) == '\n') continue; - *t++ = s; + *t++ = *s; } *t = '\0'; // TODO null pad t to s? diff --git a/windows/winapi.hpp b/windows/winapi.hpp index 434144a1..0ba286fe 100644 --- a/windows/winapi.hpp +++ b/windows/winapi.hpp @@ -29,10 +29,12 @@ // Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle #ifndef RC_INVOKED #include +#include #include #include #include #include +#include #include #include diff --git a/windows/winutil.cpp b/windows/winutil.cpp index 52273862..208c5ab9 100644 --- a/windows/winutil.cpp +++ b/windows/winutil.cpp @@ -106,7 +106,7 @@ void clientSizeToWindowSize(HWND hwnd, intmax_t *width, intmax_t *height, BOOL h window.right = *width; window.bottom = *height; if (AdjustWindowRectEx(&window, getStyle(hwnd), hasMenubar, getExStyle(hwnd)) == 0) { - logLastError("error getting adjusted window rect"); + logLastError(L"error getting adjusted window rect"); // on error, don't give up; the window will be smaller but whatever window.left = 0; window.top = 0;