diff options
Diffstat (limited to 'uisimulator/win32/uisw32.c')
-rw-r--r-- | uisimulator/win32/uisw32.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/uisimulator/win32/uisw32.c b/uisimulator/win32/uisw32.c index 0b2f88066c..77ad917461 100644 --- a/uisimulator/win32/uisw32.c +++ b/uisimulator/win32/uisw32.c | |||
@@ -22,6 +22,8 @@ | |||
22 | #include "uisw32.h" | 22 | #include "uisw32.h" |
23 | #include "resource.h" | 23 | #include "resource.h" |
24 | #include "button.h" | 24 | #include "button.h" |
25 | #include "thread.h" | ||
26 | #include "thread-win32.h" | ||
25 | 27 | ||
26 | // extern functions | 28 | // extern functions |
27 | extern void app_main (void *); // mod entry point | 29 | extern void app_main (void *); // mod entry point |
@@ -32,6 +34,7 @@ HWND hGUIWnd; // the GUI window handle | |||
32 | unsigned int uThreadID; // id of mod thread | 34 | unsigned int uThreadID; // id of mod thread |
33 | PBYTE lpKeys; | 35 | PBYTE lpKeys; |
34 | bool bActive; // window active? | 36 | bool bActive; // window active? |
37 | HANDLE hGUIThread; // thread for GUI | ||
35 | 38 | ||
36 | // GUIWndProc | 39 | // GUIWndProc |
37 | // window proc for GUI simulator | 40 | // window proc for GUI simulator |
@@ -186,6 +189,11 @@ LRESULT GUIWndProc ( | |||
186 | hGUIWnd = NULL; | 189 | hGUIWnd = NULL; |
187 | PostQuitMessage (0); | 190 | PostQuitMessage (0); |
188 | break; | 191 | break; |
192 | case WM_DESTROY: | ||
193 | // close simulator | ||
194 | hGUIWnd = NULL; | ||
195 | PostQuitMessage (0); | ||
196 | break; | ||
189 | } | 197 | } |
190 | 198 | ||
191 | return DefWindowProc (hWnd, uMsg, wParam, lParam); | 199 | return DefWindowProc (hWnd, uMsg, wParam, lParam); |
@@ -229,8 +237,16 @@ BOOL GUIStartup () | |||
229 | // destroy window, unregister window class | 237 | // destroy window, unregister window class |
230 | int GUIDown () | 238 | int GUIDown () |
231 | { | 239 | { |
240 | int i; | ||
241 | |||
232 | DestroyWindow (hGUIWnd); | 242 | DestroyWindow (hGUIWnd); |
233 | _endthreadex (uThreadID); | 243 | CloseHandle (hGUIThread); |
244 | for (i = 0; i < nThreads; i++) | ||
245 | { | ||
246 | ResumeThread (lpThreads[i]); | ||
247 | WaitForSingleObject (lpThreads[i], 1); | ||
248 | CloseHandle (lpThreads[i]); | ||
249 | } | ||
234 | return 0; | 250 | return 0; |
235 | } | 251 | } |
236 | 252 | ||
@@ -239,10 +255,17 @@ int GUIDown () | |||
239 | void GUIMessageLoop () | 255 | void GUIMessageLoop () |
240 | { | 256 | { |
241 | MSG msg; | 257 | MSG msg; |
242 | while (GetMessage (&msg, hGUIWnd, 0, 0) && hGUIWnd != NULL) | 258 | while (GetMessage (&msg, NULL, 0, 0)) |
243 | { | 259 | { |
244 | TranslateMessage (&msg); | 260 | TranslateMessage (&msg); |
245 | DispatchMessage (&msg); | 261 | DispatchMessage (&msg); |
262 | if (msg.message == TM_YIELD) | ||
263 | { | ||
264 | SuspendThread (lpThreads[nPos]); | ||
265 | if (++nPos >= nThreads) | ||
266 | nPos = 0; | ||
267 | ResumeThread (lpThreads[nPos]); | ||
268 | } | ||
246 | } | 269 | } |
247 | } | 270 | } |
248 | 271 | ||
@@ -256,12 +279,15 @@ int WINAPI WinMain ( | |||
256 | int nShowCmd // show command | 279 | int nShowCmd // show command |
257 | ) | 280 | ) |
258 | { | 281 | { |
282 | DWORD dwThreadID; | ||
259 | if (!GUIStartup ()) | 283 | if (!GUIStartup ()) |
260 | return 0; | 284 | return 0; |
261 | 285 | ||
262 | uThreadID = _beginthread (app_main, 0, NULL); | 286 | hGUIThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)app_main, |
263 | if (uThreadID == -0L) | 287 | NULL, 0, &dwThreadID); |
264 | return MessageBox (NULL, "Error creating mod thread!", "Error", MB_OK); | 288 | |
289 | if (hGUIThread == NULL) | ||
290 | return MessageBox (NULL, "Error creating gui thread!", "Error", MB_OK); | ||
265 | 291 | ||
266 | GUIMessageLoop (); | 292 | GUIMessageLoop (); |
267 | 293 | ||