+/* RegisterGdkClass
+ * is a wrapper function for RegisterWindowClassEx.
+ * It creates at least one unique class for every
+ * GdkWindowType. If support for single window-specific icons
+ * is ever needed (e.g Dialog specific), every such window should
+ * get its own class
+ */
+ATOM
+RegisterGdkClass(GdkWindowType wtype)
+{
+ static ATOM klassTOPLEVEL = 0;
+ static ATOM klassDIALOG = 0;
+ static ATOM klassCHILD = 0;
+ static ATOM klassTEMP = 0;
+ static HICON hAppIcon = NULL;
+ static WNDCLASSEX wcl;
+ ATOM klass = 0;
+
+#ifdef MULTIPLE_WINDOW_CLASSES
+Error: Not yet implemented!
+#endif
+
+ wcl.cbSize = sizeof(WNDCLASSEX);
+ wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw
+ * on WM_SIZE and WM_MOVE. Flicker, Performance!
+ */
+ wcl.lpfnWndProc = gdk_WindowProc;
+ wcl.cbClsExtra = 0;
+ wcl.cbWndExtra = 0;
+ wcl.hInstance = gdk_ProgInstance;
+ wcl.hIcon = 0;
+ /* initialize once! */
+ if (0 == hAppIcon)
+ {
+ gchar sLoc [_MAX_PATH+1];
+ HINSTANCE hInst = GetModuleHandle(NULL);
+
+ if (0 != GetModuleFileName(hInst, sLoc, _MAX_PATH))
+ {
+ hAppIcon = ExtractIcon(hInst, sLoc, 0);
+ if (0 == hAppIcon)
+ {
+ char *gdklibname = g_strdup_printf ("gdk-%s.dll", GDK_VERSION);
+
+ hAppIcon = ExtractIcon(hInst, gdklibname, 0);
+ g_free (gdklibname);
+ }
+
+ if (0 == hAppIcon)
+ hAppIcon = LoadIcon (NULL, IDI_APPLICATION);
+ }
+ }
+
+ wcl.lpszMenuName = NULL;
+ wcl.hIconSm = 0;
+
+ /* initialize once per class */
+#define ONCE_PER_CLASS() \
+ wcl.hIcon = CopyIcon (hAppIcon); \
+ wcl.hIconSm = CopyIcon (hAppIcon); \
+ wcl.hbrBackground = CreateSolidBrush( RGB(0,0,0)); \
+ wcl.hCursor = LoadCursor (NULL, IDC_ARROW);
+
+ switch (wtype)
+ {
+ case GDK_WINDOW_TOPLEVEL:
+ if (0 == klassTOPLEVEL)
+ {
+ wcl.lpszClassName = "gdkWindowToplevel";
+
+ ONCE_PER_CLASS();
+ klassTOPLEVEL = RegisterClassEx(&wcl);
+ }
+ klass = klassTOPLEVEL;
+ break;
+ case GDK_WINDOW_CHILD:
+ if (0 == klassCHILD)
+ {
+ wcl.lpszClassName = "gdkWindowChild";
+
+ wcl.style |= CS_PARENTDC; /* MSDN: ... enhances system performance. */
+ ONCE_PER_CLASS();
+ klassCHILD = RegisterClassEx(&wcl);
+ }
+ klass = klassCHILD;
+ break;
+ case GDK_WINDOW_DIALOG:
+ if (0 == klassDIALOG)
+ {
+ wcl.lpszClassName = "gdkWindowDialog";
+ wcl.style |= CS_SAVEBITS;
+ ONCE_PER_CLASS();
+ klassDIALOG = RegisterClassEx(&wcl);
+ }
+ klass = klassDIALOG;
+ break;
+ case GDK_WINDOW_TEMP:
+ if (0 == klassTEMP)
+ {
+ wcl.lpszClassName = "gdkWindowTemp";
+ wcl.style |= CS_SAVEBITS;
+ ONCE_PER_CLASS();
+ klassTEMP = RegisterClassEx(&wcl);
+ }
+ klass = klassTEMP;
+ break;
+ case GDK_WINDOW_ROOT:
+ g_error ("cannot make windows of type GDK_WINDOW_ROOT");
+ break;
+ case GDK_WINDOW_PIXMAP:
+ g_error ("cannot make windows of type GDK_WINDOW_PIXMAP (use gdk_pixmap_new)");
+ break;
+ }
+
+ return klass;
+} /* RegisterGdkClass */
+
+