6969// GLOBALS ////////////////////////////////////////////////////////////////////
7070HINSTANCE ApplicationHInstance = NULL ; // /< our application instance
7171HWND ApplicationHWnd = NULL ; // /< our application window handle
72- Win32Mouse *TheWin32Mouse= NULL ; // /< for the WndProc() only
72+ Win32Mouse *TheWin32Mouse = NULL ; // /< for the WndProc() only
7373DWORD TheMessageTime = 0 ; // /< For getting the time that a message was posted from Windows.
7474
7575const Char *g_strFile = " data\\ Generals.str" ;
@@ -315,77 +315,59 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
315315 {
316316 // -------------------------------------------------------------------------
317317 case WM_NCHITTEST:
318- // Prevent the user from selecting the menu in fullscreen mode
319- if ( !TheGlobalData->m_windowed )
320- return HTCLIENT;
321- break ;
318+ // Prevent the user from selecting the menu in fullscreen mode
319+ if ( !TheGlobalData->m_windowed )
320+ return HTCLIENT;
321+ break ;
322322
323323 // -------------------------------------------------------------------------
324324 case WM_POWERBROADCAST:
325- switch ( wParam )
326- {
327- #ifndef PBT_APMQUERYSUSPEND
328- #define PBT_APMQUERYSUSPEND 0x0000
329- #endif
330- case PBT_APMQUERYSUSPEND:
331- // At this point, the app should save any data for open
332- // network connections, files, etc., and prepare to go into
333- // a suspended mode.
334- return TRUE ;
335-
336- #ifndef PBT_APMRESUMESUSPEND
337- #define PBT_APMRESUMESUSPEND 0x0007
338- #endif
339- case PBT_APMRESUMESUSPEND:
340- // At this point, the app should recover any data, network
341- // connections, files, etc., and resume running from when
342- // the app was suspended.
343- return TRUE ;
344- }
345- break ;
325+ switch ( wParam )
326+ {
327+ #ifndef PBT_APMQUERYSUSPEND
328+ #define PBT_APMQUERYSUSPEND 0x0000
329+ #endif
330+ case PBT_APMQUERYSUSPEND:
331+ // At this point, the app should save any data for open
332+ // network connections, files, etc., and prepare to go into
333+ // a suspended mode.
334+ return TRUE ;
335+
336+ #ifndef PBT_APMRESUMESUSPEND
337+ #define PBT_APMRESUMESUSPEND 0x0007
338+ #endif
339+ case PBT_APMRESUMESUSPEND:
340+ // At this point, the app should recover any data, network
341+ // connections, files, etc., and resume running from when
342+ // the app was suspended.
343+ return TRUE ;
344+ }
345+ break ;
346346 // -------------------------------------------------------------------------
347347 case WM_SYSCOMMAND:
348- // Prevent moving/sizing and power loss in fullscreen mode
349- switch ( wParam )
350- {
351- case SC_KEYMENU:
352- // TheSuperHackers @bugfix Mauller 10/05/2025 Always handle this command to prevent halting the game when left Alt is pressed.
353- return 1 ;
354- case SC_MOVE:
355- case SC_SIZE:
356- case SC_MAXIMIZE:
357- case SC_MONITORPOWER:
358- if ( !TheGlobalData->m_windowed )
359- return 1 ;
360- break ;
361- }
362- break ;
348+ // Prevent moving/sizing and power loss in fullscreen mode
349+ switch ( wParam )
350+ {
351+ case SC_KEYMENU:
352+ // TheSuperHackers @bugfix Mauller 10/05/2025 Always handle this command to prevent halting the game when left Alt is pressed.
353+ return 1 ;
354+ case SC_MOVE:
355+ case SC_SIZE:
356+ case SC_MAXIMIZE:
357+ case SC_MONITORPOWER:
358+ if ( !TheGlobalData->m_windowed )
359+ return 1 ;
360+ break ;
361+ }
362+ break ;
363363
364364 // ------------------------------------------------------------------------
365365 case WM_CLOSE:
366- TheGameEngine->checkAbnormalQuitting ();
367- TheGameEngine->reset ();
368- TheGameEngine->setQuitting (TRUE );
369- _exit (EXIT_SUCCESS);
370- return 0 ;
371-
372- // ------------------------------------------------------------------------
373- case WM_SETFOCUS:
374- {
375-
376- //
377- // reset the state of our keyboard cause we haven't been paying
378- // attention to the keys while focus was away
379- //
380- if ( TheKeyboard )
381- TheKeyboard->resetKeys ();
382-
383- if (TheMouse)
384- TheMouse->regainFocus ();
385-
386- break ;
387-
388- }
366+ TheGameEngine->checkAbnormalQuitting ();
367+ TheGameEngine->reset ();
368+ TheGameEngine->setQuitting (TRUE );
369+ _exit (EXIT_SUCCESS);
370+ return 0 ;
389371
390372 // -------------------------------------------------------------------------
391373 case WM_MOVE:
@@ -409,6 +391,22 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
409391 break ;
410392 }
411393
394+ // ------------------------------------------------------------------------
395+ case WM_SETFOCUS:
396+ {
397+ //
398+ // reset the state of our keyboard cause we haven't been paying
399+ // attention to the keys while focus was away
400+ //
401+ if ( TheKeyboard )
402+ TheKeyboard->resetKeys ();
403+
404+ if (TheMouse)
405+ TheMouse->regainFocus ();
406+
407+ break ;
408+ }
409+
412410 // -------------------------------------------------------------------------
413411 case WM_KILLFOCUS:
414412 {
@@ -439,13 +437,15 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
439437 TheGameEngine->setIsActive (isWinMainActive);
440438
441439 if (isWinMainActive)
442- { // restore mouse cursor to our custom version.
440+ {
441+ // restore mouse cursor to our custom version.
443442 if (TheWin32Mouse)
444443 TheWin32Mouse->setCursor (TheWin32Mouse->getMouseCursor ());
445444 }
446445 }
447446 return 0 ;
448447 }
448+
449449 // -------------------------------------------------------------------------
450450 case WM_ACTIVATE:
451451 {
@@ -466,7 +466,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
466466 TheMouse->refreshCursorCapture ();
467467 }
468468 break ;
469-
470469 }
471470
472471 // -------------------------------------------------------------------------
@@ -476,21 +475,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
476475
477476 switch ( key )
478477 {
479-
480- // ---------------------------------------------------------------------
481478 case VK_ESCAPE:
482479 {
483-
484480 PostQuitMessage ( 0 );
485481 break ;
486-
487482 }
488-
489-
490483 }
491-
492484 return 0 ;
493-
494485 }
495486
496487 // -------------------------------------------------------------------------
@@ -506,17 +497,18 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
506497 case WM_RBUTTONUP:
507498 case WM_RBUTTONDBLCLK:
508499 {
509-
510500 if ( TheWin32Mouse )
511501 TheWin32Mouse->addWin32Event ( message, wParam, lParam, TheMessageTime );
512502
513503 return 0 ;
514-
515504 }
516505
517506 // -------------------------------------------------------------------------
518507 case 0x020A : // WM_MOUSEWHEEL
519508 {
509+ if ( TheWin32Mouse == NULL )
510+ return 0 ;
511+
520512 long x = (long ) LOWORD (lParam);
521513 long y = (long ) HIWORD (lParam);
522514 RECT rect;
@@ -526,32 +518,28 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
526518 if ( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
527519 return 0 ;
528520
529- if ( TheWin32Mouse )
530- TheWin32Mouse->addWin32Event ( message, wParam, lParam, TheMessageTime );
531-
521+ TheWin32Mouse->addWin32Event ( message, wParam, lParam, TheMessageTime );
532522 return 0 ;
533-
534523 }
535524
536-
537525 // -------------------------------------------------------------------------
538526 case WM_MOUSEMOVE:
539527 {
528+ if ( TheWin32Mouse == NULL )
529+ return 0 ;
530+
540531 Int x = (Int)LOWORD ( lParam );
541532 Int y = (Int)HIWORD ( lParam );
542533 RECT rect;
543- // Int keys = wParam;
544534
545535 // ignore when outside of client area
546536 GetClientRect ( ApplicationHWnd, &rect );
547537 if ( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
548538 return 0 ;
549539
550- if ( TheWin32Mouse )
551- TheWin32Mouse->addWin32Event ( message, wParam, lParam, TheMessageTime );
552540
541+ TheWin32Mouse->addWin32Event ( message, wParam, lParam, TheMessageTime );
553542 return 0 ;
554-
555543 }
556544
557545 // -------------------------------------------------------------------------
0 commit comments