summaryrefslogtreecommitdiff
path: root/common_windows.c
diff options
context:
space:
mode:
Diffstat (limited to 'common_windows.c')
-rw-r--r--common_windows.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/common_windows.c b/common_windows.c
index 9e67a0c..e0142c8 100644
--- a/common_windows.c
+++ b/common_windows.c
@@ -45,6 +45,39 @@ void *getWindowData(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT
return data;
}
+// this is a helper function that takes the logic of determining window classes and puts it all in one place
+// there are a number of places where we need to know what window class an arbitrary handle has
+// theoretically we could use the class atom to avoid a _wcsicmp()
+// however, raymond chen advises against this - http://blogs.msdn.com/b/oldnewthing/archive/2004/10/11/240744.aspx (and we're not in control of the Tab class, before you say anything)
+// usage: windowClassOf(hwnd, L"class 1", L"class 2", ..., NULL)
+int windowClassOf(HWND hwnd, ...)
+{
+// MSDN says 256 is the maximum length of a class name; add a few characters just to be safe (because it doesn't say whether this includes the terminating null character)
+#define maxClassName 260
+ WCHAR classname[maxClassName + 1];
+ va_list ap;
+ WCHAR *curname;
+ int i;
+
+ if (GetClassNameW(hwnd, classname, maxClassName) == 0)
+ xpanic("error getting name of window class in windowClassOf()", GetLastError());
+ va_start(ap, hwnd);
+ i = 0;
+ for (;;) {
+ curname = va_arg(ap, WCHAR *);
+ if (curname == NULL)
+ break;
+ if (_wcsicmp(classname, curname) == 0) {
+ va_end(ap);
+ return i;
+ }
+ i++;
+ }
+ // no match
+ va_end(ap);
+ return -1;
+}
+
/*
all container windows (including the message-only window, hence this is not in container_windows.c) have to call the sharedWndProc() to ensure messages go in the right place and control colors are handled properly
*/
@@ -100,7 +133,6 @@ void paintControlBackground(HWND hwnd, HDC dc)
HWND parent;
RECT r;
POINT p, pOrig;
- WCHAR classname[maxClassName + 1] = L"";
parent = hwnd;
for (;;) {
@@ -110,10 +142,8 @@ void paintControlBackground(HWND hwnd, HDC dc)
// wine sends these messages early, yay...
if (parent == msgwin)
return;
- if (GetClassNameW(parent, classname, maxClassName) == 0)
- xpanic("error getting name of focused window class in paintControlBackground()", GetLastError());
// skip groupboxes; they're (supposed to be) transparent
- if (_wcsicmp(classname, L"button") != 0)
+ if (windowClassOf(parent, L"button", NULL) != 0)
break;
}
if (GetWindowRect(hwnd, &r) == 0)