changeset 1532:3c33f3e44f71

Fix and clean aWinProc and related Fixed #31
author yoctozepto
date Fri, 06 Sep 2013 16:32:08 +0200
parents 2ae4c5a5b4e5
children 6e4980797714
files Arcomage.cpp Arcomage.h mm7_2.cpp mm7_data.cpp mm7_data.h
diffstat 5 files changed, 328 insertions(+), 377 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage.cpp	Fri Sep 06 16:43:54 2013 +0600
+++ b/Arcomage.cpp	Fri Sep 06 16:32:08 2013 +0200
@@ -447,10 +447,10 @@
 }
 
 //----- (0040DFC1) --------------------------------------------------------
-void ArcomageGame::OnMouseMove(POINT *pXY)
+void ArcomageGame::OnMouseMove(int x, int y)
 {
-  pArcomageGame->mouse_x = pXY->x;
-  pArcomageGame->mouse_y = pXY->y;
+  pArcomageGame->mouse_x = x;
+  pArcomageGame->mouse_y = y;
 }
 
 
--- a/Arcomage.h	Fri Sep 06 16:43:54 2013 +0600
+++ b/Arcomage.h	Fri Sep 06 16:32:08 2013 +0200
@@ -141,7 +141,7 @@
   static bool MsgLoop(int a1, ArcomageGame_stru1 *a2);
   static void PlaySound(unsigned int event_id);
   static void OnMouseClick(char right_left, bool bDown);
-  static void OnMouseMove(POINT *pXY);
+  static void OnMouseMove(int x, int y);
   static void GetCardRect(unsigned int uCardID, RECT *pCardRect);
 
   static void Loop();
--- a/mm7_2.cpp	Fri Sep 06 16:43:54 2013 +0600
+++ b/mm7_2.cpp	Fri Sep 06 16:32:08 2013 +0200
@@ -685,7 +685,7 @@
   char *v9; // eax@14
   unsigned int v10; // eax@25
   GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
-  MSG Msg; // [sp+88h] [bp-48h]@22
+  //MSG Msg; // [sp+88h] [bp-48h]@22
   unsigned int v14; // [sp+A4h] [bp-2Ch]@5
   void *v15; // [sp+A8h] [bp-28h]@1
   char *pInString; // [sp+ACh] [bp-24h]@5
@@ -805,15 +805,12 @@
     LODWORD(v23) = GetTickCount() + 5000;
     while ( (unsigned int)v23 > GetTickCount() )
       ;
-    while ( 1 )
+    for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
     {
-      v10 = PeekMessageA(&Msg, 0, 0, 0, 1u);
-      if ( !v10 )
-        break;
-      if ( Msg.message == 18 )
+      if (msg.message == WM_QUIT)
         Game_DeinitializeAndTerminate(0);
-      TranslateMessage(&Msg);
-      DispatchMessageA(&Msg);
+      TranslateMessage(&msg);
+      DispatchMessage(&msg);
     }
     if ( pMessageQueue_50CBD0->uNumMessages )
     {
@@ -824,12 +821,12 @@
     pKeyActionMap->uLastKeyPressed = 0;
     do
     {
-      while ( PeekMessageA(&Msg, 0, 0, 0, 1u) )
+      for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
       {
-        if ( Msg.message == 18 )
+        if (msg.message == WM_QUIT)
           Game_DeinitializeAndTerminate(0);
-        TranslateMessage(&Msg);
-        DispatchMessageA(&Msg);
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
       }
     }
     while ( !pKeyActionMap->uLastKeyPressed );
@@ -3171,13 +3168,12 @@
       pWindow = pGUIWindow_CurrentMenu;
     }
 
-    MSG msg;
-    while ( PeekMessageA(&msg, 0, 0, 0, PM_REMOVE) )
+    for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
     {
       if (msg.message == WM_QUIT)
         Game_DeinitializeAndTerminate(0);
       TranslateMessage(&msg);
-      DispatchMessageA(&msg);
+      DispatchMessage(&msg);
     }
     if (dword_6BE364_game_settings_1 & 0x0100)
     {
@@ -3258,33 +3254,41 @@
 }
 
 //----- (004637EB) --------------------------------------------------------
-int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam)
+LRESULT CALLBACK aWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-  HANDLE v6; // eax@32
-  HDC v10; // edi@50
-  int v11; // esi@50
-  signed int v13; // eax@135
-  char v29; // dl@209
-  bool v31; // ebx@211
-  float v33; // ST04_4@246
-  float v34; // ST04_4@254
-  struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
-  int pXY[2]; // [sp+64h] [bp-8h]@261
-  int a2; // [sp+7Ch] [bp+10h]@50
-
-  switch (Msg)
-  {
-    case WM_SIZING:  return 1;
+  //HANDLE v6; // eax@32
+  //HDC v10; // edi@50
+  //int v11; // esi@50
+  //signed int v13; // eax@135
+  //char v29; // dl@209
+  //bool v31; // ebx@211
+  //float v33; // ST04_4@246
+  //float v34; // ST04_4@254
+  //struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
+  //int pXY[2]; // [sp+64h] [bp-8h]@261
+  //int a2; // [sp+7Ch] [bp+10h]@50
+
+  switch (uMsg)
+  {
+    case WM_SIZING: 
+      return 1;
+
     case WM_SHOWWINDOW:
     case WM_GETTEXT:
-    case WM_SETTEXT: return DefWindowProcW(hWnd, Msg, wParam, lParam);
+    case WM_SETTEXT:
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_DESTROY:
+      SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+      PostQuitMessage(0);
+      return 0;
 
     case WM_WINDOWPOSCHANGED:
     {
       if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer)
         BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0);
 
-      return DefWindowProcW(hWnd, Msg, wParam, lParam);
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
     }
 
     case WM_CHAR:
@@ -3292,13 +3296,13 @@
       if (!pKeyActionMap->_459F10(wParam) && !viewparams->field_4C)
         GUI_HandleHotkey(wParam);
     }
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
+    return DefWindowProc(hWnd, uMsg, wParam, lParam);
 
 
     case WM_DEVICECHANGE:
     {
       if (wParam == 0x8000)          // CD or some device has been inserted - notify InsertCD dialog
-        PostMessageA(hInsertCDWindow, WM_USER + 1, 0, 0);
+        PostMessage(hInsertCDWindow, WM_USER + 1, 0, 0);
       return 0;
     }
 
@@ -3310,7 +3314,7 @@
 
         case 101:  // Quit game
         case 40001:
-          SendMessageA(::hWnd, WM_DESTROY, 0, 0);
+          SendMessage(hWnd, WM_DESTROY, 0, 0);
         return 0;
 
 
@@ -3479,355 +3483,311 @@
 
       }
     }
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  };
-
-  if ( Msg > WM_SYSCOMMAND )
-  {
-    switch ( Msg )
-    {
-      case WM_LBUTTONDOWN:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->stru1.field_0 = 7;
-          ArcomageGame::OnMouseClick(0, 1);
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        goto __handle_mouse_click;
-
-      case WM_RBUTTONDOWN:
-        v31 = 0;
-        if ( !pArcomageGame->bGameInProgress )
-          //goto LABEL_240;
-        {
-          if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
-            pVideoPlayer->bStopBeforeSchedule = 1;
-
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-          if (pGame)
-          {
-            v33 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
-          }
-
-            sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-        }
-
+    return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_LBUTTONDOWN:
+      if (pArcomageGame->bGameInProgress)
+      {
+        pArcomageGame->stru1.field_0 = 7;
+        ArcomageGame::OnMouseClick(0, true);
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+
+      goto __handle_mouse_click;
+
+    case WM_RBUTTONDOWN:
+      if (pArcomageGame->bGameInProgress)
+      {
         pArcomageGame->stru1.field_0 = 8;
-        ArcomageGame::OnMouseClick(1, 1);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_LBUTTONUP:
-        if ( !pArcomageGame->bGameInProgress )
-          //goto LABEL_218;
-        {
-          back_to_game();
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        pArcomageGame->stru1.field_0 = 3;
-        ArcomageGame::OnMouseClick(0, 0);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_RBUTTONUP:
-        if ( !pArcomageGame->bGameInProgress )
-        {
-//LABEL_218:
-
-          back_to_game();
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        pArcomageGame->stru1.field_0 = 4;
-        ArcomageGame::OnMouseClick(1, false);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-      case WM_LBUTTONDBLCLK:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->stru1.field_0 = 7;
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
+        ArcomageGame::OnMouseClick(1, true);
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+
+      if (pVideoPlayer->pVideoFrame.pPixels)
+        pVideoPlayer->bStopBeforeSchedule = 1;
+
+      pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+      if (pGame)
+      {
+        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 0, &vis_sprite_filter_2, &vis_door_filter);
+      }
+
+      sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+
+    case WM_LBUTTONUP:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        back_to_game();
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+      pArcomageGame->stru1.field_0 = 3;
+      ArcomageGame::OnMouseClick(0, 0);
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+    case WM_RBUTTONUP:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        back_to_game();
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+      pArcomageGame->stru1.field_0 = 4;
+      ArcomageGame::OnMouseClick(1, false);
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_LBUTTONDBLCLK:
+      if ( pArcomageGame->bGameInProgress )
+      {
+        pArcomageGame->stru1.field_0 = 7;
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
         
 __handle_mouse_click:
-        if ( pVideoPlayer->pVideoFrame.pPixels )
+      if (pVideoPlayer->pVideoFrame.pPixels)
+        pVideoPlayer->bStopBeforeSchedule = 1;
+
+      pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+      if (GetCurrentMenuID() == MENU_CREATEPARTY)
+      {
+        UI_OnKeyDown(VK_SELECT);
+      }
+
+      if (pGame)
+        pGame->PickMouse(512.0, LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_3, &vis_door_filter);
+
+      UI_OnMouseLeftClick(0);
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_RBUTTONDBLCLK:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        if (pVideoPlayer->pVideoFrame.pPixels)
           pVideoPlayer->bStopBeforeSchedule = 1;
 
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-
-        if (GetCurrentMenuID() != MENU_CREATEPARTY)
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        else
+        pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+        if (pGame)
         {
-          UI_OnKeyDown(VK_SELECT);
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        }
-
-
-          if (pGame)
-            pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, false, &vis_sprite_filter_3, &vis_door_filter);
-
-          UI_OnMouseLeftClick(0);
-
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-      case WM_RBUTTONDBLCLK:
-        v31 = 0;
-        if ( !pArcomageGame->bGameInProgress )
-        {
-//LABEL_240:
-          if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
-            pVideoPlayer->bStopBeforeSchedule = 1;
-
-            pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-          if (pGame)
-          {
-            v33 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
-          }
-
-            sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
+          pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
         }
-        pArcomageGame->stru1.field_0 = 8;
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_MBUTTONDOWN:
-        if ( pRenderer->pRenderD3D )
-        {
-          if ( pGame )
-          {
-            v34 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v34, (unsigned __int16)lParam, lParam >> 16, 1, &vis_sprite_filter_3, &vis_face_filter);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-          }
-        }
-        if ( !pGame )
-          //goto _def_wnd_proc;
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_MOUSEMOVE:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pXY[0] = (unsigned __int16)lParam;
-          pXY[1] = lParam >> 16;
-          ArcomageGame::OnMouseMove((POINT *)pXY);
-          ArcomageGame::OnMouseClick(0, wParam & 1);
-          v29 = (wParam >> 1) & 1;
-          ArcomageGame::OnMouseClick(1, v29 != 0);
-        }
-        else
-        {
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        }
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      default:
-        //goto _def_wnd_proc;
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-  }
-  if ( Msg == WM_SYSCOMMAND )
-  {
-    if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
-      return 0;
-    //goto _def_wnd_proc;
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( Msg > WM_ACTIVATEAPP )
-  {
-    if ( Msg != WM_KEYFIRST && Msg != WM_WINDOWPOSCHANGED)
-    {
-      if ( Msg == WM_KEYUP && wParam == VK_CONTROL )
+
+        sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+
+      pArcomageGame->stru1.field_0 = 8;
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_MBUTTONDOWN:
+      if (pRenderer->pRenderD3D && pGame)
+      {
+        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
+      }
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_MOUSEMOVE:
+      if ( pArcomageGame->bGameInProgress )
+      {
+        ArcomageGame::OnMouseMove(LOWORD(lParam), HIWORD(lParam));
+        ArcomageGame::OnMouseClick(0, wParam == MK_LBUTTON);
+        ArcomageGame::OnMouseClick(1, wParam == MK_RBUTTON);
+      }
+      else
+      {
+        pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+      }
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_SYSCOMMAND:
+      if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
+        return 0;
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_KEYUP:
+      if (wParam == VK_CONTROL)
       {
         dword_507B98_ctrl_pressed = 0;
       }
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
-    {
-      pKeyActionMap->_459F10(wParam);
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( !pArcomageGame->bGameInProgress )
-    {
-      if ( pVideoPlayer->pVideoFrame.pPixels )
-        pVideoPlayer->bStopBeforeSchedule = 1;
-      if ( wParam == VK_RETURN )
-      {
-        if ( !viewparams->field_4C )
-          UI_OnKeyDown(wParam);
-        return 0;
-      }
-      if ( wParam == VK_CONTROL )
+
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_KEYDOWN:
+      if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
       {
-        dword_507B98_ctrl_pressed = 1;
-        return 0;
-      }
-      if ( wParam == VK_ESCAPE )
-      {
-        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
-        return 0;
+        pKeyActionMap->_459F10(wParam);
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
       }
-      if ( wParam <= VK_HOME )
-        return 0;
-      if ( wParam > VK_DOWN )
+      if ( !pArcomageGame->bGameInProgress )
       {
-        if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
-          return 0;
-        SendMessageA(hWnd, WM_COMMAND, 104, 0);
-        return 0;
-      }
-      if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
-      {
-        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+        if ( pVideoPlayer->pVideoFrame.pPixels )
+          pVideoPlayer->bStopBeforeSchedule = 1;
+        if ( wParam == VK_RETURN )
         {
           if ( !viewparams->field_4C )
             UI_OnKeyDown(wParam);
           return 0;
         }
-      }
-      if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
-        return 0;
-    }
-
-    pArcomageGame->stru1.field_0 = 1;
-
-    v13 = (unsigned __int16)MapVirtualKeyA((unsigned __int16)wParam, 2u);
-    set_stru1_field_8_InArcomage(v13);
-    if ( wParam == 27 )
-    {
-      pArcomageGame->GameOver = 1;
-      pArcomageGame->field_F4 = 1;
-      pArcomageGame->uGameResult = 2;
-      pArcomageGame->field_B0 = -2;
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( wParam != 114 )
-    {
-      if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
-        SendMessageA(hWnd, 0x111u, 0x68u, 0);
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    SendMessageA(hWnd, WM_COMMAND, 103, 0);
-    return 0;
-  }
-  if ( Msg == WM_ACTIVATEAPP )
-  {
-    if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
-    {
-      if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
-      {
-        dword_4E98BC_bApplicationActive = 1;
-        if ( pRenderer->bWindowMode )
+        if ( wParam == VK_CONTROL )
+        {
+          dword_507B98_ctrl_pressed = 1;
+          return 0;
+        }
+        if ( wParam == VK_ESCAPE )
         {
-          v10 = GetDC(0);
-          a2 = GetDeviceCaps(v10, BITSPIXEL);
-          v11 = GetDeviceCaps(v10, PLANES);
-          ReleaseDC(0, v10);
-          if ( a2 != 16 || v11 != 1 )
-            Abortf(pGlobalTXT_LocalizationStrings[62]);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
+          return 0;
         }
-        BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
-
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->field_F9 = 1;
-        }
-        else
+        if ( wParam <= VK_HOME )
+          return 0;
+        if ( wParam > VK_DOWN )
         {
-          if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
-            BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
-          else
-            pEventTimer->Resume();
-          if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
-            BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
-          else
-            pMiscTimer->Resume();
-
-          viewparams->bRedrawGameUI = true;
-          if ( pVideoPlayer->pSmackerMovie )
+          if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
+            return 0;
+          SendMessage(hWnd, WM_COMMAND, 104, 0);
+          return 0;
+        }
+        if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
+        {
+          if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
           {
-            pRenderer->RestoreFrontBuffer();
-            pRenderer->_4A184C();
-            pVideoPlayer->_4BF5B2();
+            if ( !viewparams->field_4C )
+              UI_OnKeyDown(wParam);
+            return 0;
           }
         }
-        if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
-          AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+          return 0;
       }
-    }
-    else
-    {
-      if ( !(dword_6BE364_game_settings_1 & 0x100) )
+
+      pArcomageGame->stru1.field_0 = 1;
+
+      set_stru1_field_8_InArcomage(MapVirtualKey(wParam, MAPVK_VK_TO_CHAR));
+      if ( wParam == 27 )
       {
-        while(initing); //ADDED spinlock to allow int players ets! Gloval
-          dword_4E98BC_bApplicationActive = 0;
-        if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
-          pVideoPlayer->bStopBeforeSchedule = 1;
-
-        if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
-          SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
-        ClipCursor(0);
-        dword_6BE364_game_settings_1 |= 0x100u;
-        if ( pEventTimer->bPaused )
-          BYTE1(dword_6BE364_game_settings_1) |= 2u;
-        else
-          pEventTimer->Pause();
-        if ( pMiscTimer->bPaused )
-          BYTE1(dword_6BE364_game_settings_1) |= 4u;
-        else
-          pMiscTimer->Pause();
-
-        pAudioPlayer->StopChannels(-1, -1);
-        if ( pAudioPlayer->hAILRedbook )
-          AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+        pArcomageGame->GameOver = 1;
+        pArcomageGame->field_F4 = 1;
+        pArcomageGame->uGameResult = 2;
+        pArcomageGame->field_B0 = -2;
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+      }
+      if ( wParam != 114 )
+      {
+        if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
+          SendMessage(hWnd, WM_COMMAND, 0x68u, 0);
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
       }
-    }
-    return 0;
-  }
-  if (Msg == WM_CREATE)
-  {
-    auto hDC = GetDC(hWnd);
-    {
-      if (GetDeviceCaps(hDC, BITSPIXEL) < 8)
+      SendMessage(hWnd, WM_COMMAND, 103, 0);
+      return 0;
+
+    case WM_ACTIVATEAPP:
+      if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
       {
-        ReleaseDC(hWnd, hDC);
-        Log::Warning(L"You must be running in 256 color mode or higher.");
-        Abortf("You must be running in 256 color mode or higher. You can change the screen depth with the control panel display icon.");
+        if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
+        {
+          dword_4E98BC_bApplicationActive = 1;
+          if ( pRenderer->bWindowMode )
+          {
+            HDC hDC = GetDC(hWnd);
+            int bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
+            int planes = GetDeviceCaps(hDC, PLANES);
+            ReleaseDC(hWnd, hDC);
+            if (bitsPerPixel != 16 || planes != 1)
+              Abortf(pGlobalTXT_LocalizationStrings[62]);
+          }
+          BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
+
+          if ( pArcomageGame->bGameInProgress )
+          {
+            pArcomageGame->field_F9 = 1;
+          }
+          else
+          {
+            if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
+              BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
+            else
+              pEventTimer->Resume();
+            if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
+              BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
+            else
+              pMiscTimer->Resume();
+
+            viewparams->bRedrawGameUI = true;
+            if ( pVideoPlayer->pSmackerMovie )
+            {
+              pRenderer->RestoreFrontBuffer();
+              pRenderer->_4A184C();
+              pVideoPlayer->_4BF5B2();
+            }
+          }
+          if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
+            AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+        }
       }
-    }
-    ReleaseDC(hWnd, hDC);
-    return 0;
-  }
-  if ( Msg == WM_DESTROY )
-  {
-    v6 = GetCurrentProcess();
-    SetPriorityClass(v6, 0x20u);
-    if ( pGame )
-    {
-
-    }
-
-    PostQuitMessage(0);
-    return 0;
-  }
-  if ( Msg == WM_SETFOCUS )
-  {
-    if ( ::hWnd == (HWND)wParam )
-    {
+      else
+      {
+        if (!(dword_6BE364_game_settings_1 & 0x100))
+        {
+          dword_4E98BC_bApplicationActive = 0;
+          if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
+            pVideoPlayer->bStopBeforeSchedule = 1;
+
+          if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
+            SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+          ClipCursor(0);
+          dword_6BE364_game_settings_1 |= 0x100u;
+          if ( pEventTimer->bPaused )
+            BYTE1(dword_6BE364_game_settings_1) |= 2u;
+          else
+            pEventTimer->Pause();
+          if ( pMiscTimer->bPaused )
+            BYTE1(dword_6BE364_game_settings_1) |= 4u;
+          else
+            pMiscTimer->Pause();
+
+          pAudioPlayer->StopChannels(-1, -1);
+          if ( pAudioPlayer->hAILRedbook )
+            AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+        }
+      }
+      return 0;
+
+    case WM_CREATE:
+      {
+        auto hDC = GetDC(hWnd);
+        {
+          if (GetDeviceCaps(hDC, BITSPIXEL) < 8)
+          {
+            ReleaseDC(hWnd, hDC);
+            Log::Warning(L"You must be running in 256 color mode or higher.");
+            Abortf("You must be running in 256 color mode or higher. You can change the screen depth with the control panel display icon.");
+          }
+        }
+        ReleaseDC(hWnd, hDC);
+      }
+      return 0;
+
+    case WM_SETFOCUS:
       dword_4E98BC_bApplicationActive = 0;
       if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
-        SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+        SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
       ClipCursor(0);
-
-    }
-//_def_wnd_proc:
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( Msg != WM_KILLFOCUS )
-  {
-    if ( Msg == WM_PAINT )
-    {
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_KILLFOCUS:
+      dword_4E98BC_bApplicationActive = 1;
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+    case WM_PAINT:
       if ( !GetUpdateRect(hWnd, 0, 0) || !dword_4E98BC_bApplicationActive && !pRenderer->bWindowMode )
         return 0;
+      PAINTSTRUCT Paint;
       BeginPaint(hWnd, &Paint);
       if ( pArcomageGame->bGameInProgress )
       {
@@ -3844,13 +3804,10 @@
       pRenderer->Present();
       EndPaint(hWnd, &Paint);
       return 0;
-    }
-    //goto _def_wnd_proc;
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( ::hWnd != (HWND)wParam || (dword_4E98BC_bApplicationActive = 1, pRenderer->bWindowMode) || true )
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
+
+    default:
+      return DefWindowProc(hWnd, uMsg, wParam, lParam);
+  }
 }
 
 //----- (00464479) --------------------------------------------------------
@@ -4384,7 +4341,6 @@
 //----- (004651F4) --------------------------------------------------------
 bool MM7_Initialize()
 {
-initing=true; //ADDED Gloval
   wchar_t pCurrentDir[1024];
   _wgetcwd(pCurrentDir, 1024);
 
@@ -4447,15 +4403,14 @@
   uWindowY = uDesktopHeight / 2 - 480 / 2;
   WriteWindowsRegistryInt("window Y", uWindowY);
 
-  hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and MagicŪ VII",
-                         uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER,
-                         uWindowX, uWindowY,
-                         640, 480,
-                         nullptr,
-                         hOSMenu = nullptr,
-                         wcxw.hInstance,
-                         nullptr);
-  SetWindowTextW(hWnd, L"Might and MagicŪ VII");
+  hWnd = CreateWindowEx(0, wcxw.lpszClassName, L"Might and MagicŪ VII",
+                        uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER,
+                        uWindowX, uWindowY,
+                        640, 480,
+                        nullptr,
+                        hOSMenu = nullptr,
+                        wcxw.hInstance,
+                        nullptr);
 
   HMENU menu = CreateMenu();
   {
@@ -4664,7 +4619,6 @@
   MoveWindow(hWnd, uWindowX, uWindowY,
     rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640,
     rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0);
-  ShowWindow(hWnd, SW_SHOWNORMAL);
 
   pIcons_LOD = new LODFile_IconsBitmaps;
   if (!pIcons_LOD->Load("data\\icons.lod", "icons"))
@@ -4999,7 +4953,7 @@
       break;
     }
 
-  initing = false; //ADDED Gloval
+  ShowWindow(hWnd, SW_SHOWNORMAL);
   return true;
 }
 
--- a/mm7_data.cpp	Fri Sep 06 16:43:54 2013 +0600
+++ b/mm7_data.cpp	Fri Sep 06 16:32:08 2013 +0200
@@ -1376,5 +1376,3 @@
 std::array<__int16, 104> intersect_face_vertex_coords_list_b; // word_F8BD18
 int dword_F93F20; // weak
 int dword_F93F70; // weak
-
-volatile bool initing;
\ No newline at end of file
--- a/mm7_data.h	Fri Sep 06 16:43:54 2013 +0600
+++ b/mm7_data.h	Fri Sep 06 16:32:08 2013 +0200
@@ -1040,7 +1040,6 @@
 extern int dword_F93F20; // weak
 extern int dword_F93F70; // weak
 
-extern volatile bool initing; //ADDED