Mercurial > sdl-ios-xcode
annotate 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 |
rev | line source |
---|---|
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_win32video.h" |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
1718
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
26 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
27 static LRESULT CALLBACK |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
28 WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
29 { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
30 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
31 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
32 |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 void |
1718
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
34 WIN_PumpEvents(_THIS) |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
35 { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
36 MSG msg; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
37 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
38 TranslateMessage(&msg); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
39 DispatchMessage(&msg); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
40 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
41 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
42 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
43 static int app_registered = 0; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
44 LPTSTR SDL_Appname = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
45 Uint32 SDL_Appstyle = 0; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
46 HINSTANCE SDL_Instance = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
47 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
48 /* Register the class for this application */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
49 int |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
50 SDL_RegisterApp(char *name, Uint32 style, void *hInst) |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 { |
1718
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
52 WNDCLASS class; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
53 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
54 /* Only do this once... */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
55 if (app_registered) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
56 ++app_registered; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
57 return (0); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
58 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
59 if (!name && !SDL_Appname) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
60 name = "SDL_app"; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
61 SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
62 SDL_Instance = hInst ? hInst : GetModuleHandle(NULL); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
63 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
64 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
65 if (name) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
66 SDL_Appname = SDL_iconv_utf8_ucs2(name); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
67 SDL_Appstyle = style; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
68 SDL_Instance = hInst ? hInst : GetModuleHandle(NULL); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
69 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
70 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
71 /* Register the application class */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
72 class.hCursor = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
73 class.hIcon = LoadImage(SDL_Instance, SDL_Appname, |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
74 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
75 class.lpszMenuName = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
76 class.lpszClassName = SDL_Appname; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
77 class.hbrBackground = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
78 class.hInstance = SDL_Instance; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
79 class.style = SDL_Appstyle; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
80 class.lpfnWndProc = WinMessage; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
81 class.cbWndExtra = 0; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
82 class.cbClsExtra = 0; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
83 if (!RegisterClass(&class)) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
84 SDL_SetError("Couldn't register application class"); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
85 return (-1); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
86 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
87 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
88 app_registered = 1; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
89 return (0); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
90 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
91 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
92 /* Unregisters the windowclass registered in SDL_RegisterApp above. */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
93 void |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
94 SDL_UnregisterApp() |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
95 { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
96 WNDCLASS class; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
97 |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
98 /* SDL_RegisterApp might not have been called before */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
99 if (!app_registered) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
100 return; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
101 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
102 --app_registered; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
103 if (app_registered == 0) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
104 /* Check for any registered window classes. */ |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
105 if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) { |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
106 UnregisterClass(SDL_Appname, SDL_Instance); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
107 } |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
108 SDL_free(SDL_Appname); |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
109 SDL_Appname = NULL; |
ed4d4f1ea201
Further progress on the new Windows video driver:
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
110 } |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 } |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 /* vi: set ts=4 sw=4 expandtab: */ |