diff src/video/win32/SDL_win32events.c @ 1718:ed4d4f1ea201 SDL-1.3

Further progress on the new Windows video driver: * SDL_SetModuleHandle() is obsolete, I hope. * SDL 1.3 uses the UNICODE API * I'm ignoring Windows CE for the moment, we'll reevaluate what needs to be different for Windows CE later. * Pulled the stdio redirection from WinMain()
author Sam Lantinga <slouken@libsdl.org>
date Tue, 27 Jun 2006 07:46:36 +0000
parents 931d111e737a
children 5b9f50c957ed
line wrap: on
line diff
--- a/src/video/win32/SDL_win32events.c	Tue Jun 27 04:59:10 2006 +0000
+++ b/src/video/win32/SDL_win32events.c	Tue Jun 27 07:46:36 2006 +0000
@@ -23,9 +23,91 @@
 
 #include "SDL_win32video.h"
 
+
+static LRESULT CALLBACK
+WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
+}
+
 void
-WIN32_PumpEvents(_THIS)
+WIN_PumpEvents(_THIS)
+{
+    MSG msg;
+    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
+    }
+}
+
+static int app_registered = 0;
+LPTSTR SDL_Appname = NULL;
+Uint32 SDL_Appstyle = 0;
+HINSTANCE SDL_Instance = NULL;
+
+/* Register the class for this application */
+int
+SDL_RegisterApp(char *name, Uint32 style, void *hInst)
 {
+    WNDCLASS class;
+
+    /* Only do this once... */
+    if (app_registered) {
+        ++app_registered;
+        return (0);
+    }
+    if (!name && !SDL_Appname) {
+        name = "SDL_app";
+        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
+        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
+    }
+
+    if (name) {
+        SDL_Appname = SDL_iconv_utf8_ucs2(name);
+        SDL_Appstyle = style;
+        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
+    }
+
+    /* Register the application class */
+    class.hCursor = NULL;
+    class.hIcon = LoadImage(SDL_Instance, SDL_Appname,
+                            IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
+    class.lpszMenuName = NULL;
+    class.lpszClassName = SDL_Appname;
+    class.hbrBackground = NULL;
+    class.hInstance = SDL_Instance;
+    class.style = SDL_Appstyle;
+    class.lpfnWndProc = WinMessage;
+    class.cbWndExtra = 0;
+    class.cbClsExtra = 0;
+    if (!RegisterClass(&class)) {
+        SDL_SetError("Couldn't register application class");
+        return (-1);
+    }
+
+    app_registered = 1;
+    return (0);
+}
+
+/* Unregisters the windowclass registered in SDL_RegisterApp above. */
+void
+SDL_UnregisterApp()
+{
+    WNDCLASS class;
+
+    /* SDL_RegisterApp might not have been called before */
+    if (!app_registered) {
+        return;
+    }
+    --app_registered;
+    if (app_registered == 0) {
+        /* Check for any registered window classes. */
+        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
+            UnregisterClass(SDL_Appname, SDL_Instance);
+        }
+        SDL_free(SDL_Appname);
+        SDL_Appname = NULL;
+    }
 }
 
 /* vi: set ts=4 sw=4 expandtab: */