diff mm7_2.cpp @ 1802:633f81bb3ae7

HWND -> class OSWindow
author Nomad
date Mon, 07 Oct 2013 11:52:33 +0200
parents cecb080929c4
children 9f93b5700e2d
line wrap: on
line diff
--- a/mm7_2.cpp	Tue Oct 01 06:19:58 2013 +0200
+++ b/mm7_2.cpp	Mon Oct 07 11:52:33 2013 +0200
@@ -3108,8 +3108,8 @@
   pTexture_PCX.Release();
   pTexture_PCX.Load("title.pcx", 0);
   SetCurrentMenuID(MENU_MAIN);
-  SetForegroundWindow(hWnd);
-  SendMessageW(hWnd, WM_ACTIVATEAPP, 1, 0);
+  //SetForegroundWindow(hWnd);
+  //SendMessageW(hWnd, WM_ACTIVATEAPP, 1, 0);
   while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
   {
     POINT pt;
@@ -3213,549 +3213,6 @@
   pIcons_LOD->RemoveTexturesPackFromTextureList();
 }
 
-//----- (004637EB) --------------------------------------------------------
-int __stdcall 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 (uMsg)
-  {
-    case WM_SIZING: return 1;
-    
-    case WM_CREATE:  case WM_NCCREATE:
-    case WM_GETTEXT: case WM_SETTEXT:
-    case WM_SHOWWINDOW:
-      return DefWindowProcW(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, uMsg, wParam, lParam);
-    }
-
-    case WM_CHAR:
-    {
-      if (!pKeyActionMap->_459F10(wParam) && !viewparams->field_4C)
-        GUI_HandleHotkey(wParam);
-    }
-    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-
-    case WM_DEVICECHANGE:
-    {
-      if (wParam == 0x8000)          // CD or some device has been inserted - notify InsertCD dialog
-        PostMessageW(hInsertCDWindow, WM_USER + 1, 0, 0);
-      return 0;
-    }
-
-    case WM_COMMAND:
-    {
-      switch (wParam)
-      {
-        case 103:  pRenderer->SavePCXScreenshot();  return 0;
-
-        case 101:  // Quit game
-        case 40001:
-          SendMessageW(hWnd, WM_DESTROY, 0, 0);
-        return 0;
-
-
-        case 104:
-          pRenderer->ChangeBetweenWinFullscreenModes();
-          if ( pArcomageGame->bGameInProgress )
-            pArcomageGame->field_F6 = 1;
-        return 0;
-
-        //SubMenu "Party"
-        case 40007:  pParty->SetGold(pParty->uNumGold + 10000); return 0;
-        case 40008:  GivePartyExp(20000);  return 0;
-        case 40013:  pParty->SetGold(0);   return 0;
-
-        case 40059:
-          for (uint i = 0; i < 4; ++i)
-            pParty->pPlayers[i].uSkillPoints = 50;
-        return 0;
-        
-        case 40029:  pPlayers[uActiveCharacter]->SetPertified(true);  return 0;
-        case 40030:  pPlayers[uActiveCharacter]->SetWeak(true);       return 0;
-        case 40031:  pPlayers[uActiveCharacter]->SetPoison3(true);    return 0;
-        case 40032:  pPlayers[uActiveCharacter]->SetPoison2(true);    return 0;
-        case 40033:  pPlayers[uActiveCharacter]->SetPoison1(true);    return 0;
-        case 40034:  pPlayers[uActiveCharacter]->SetDisease3(true);   return 0;
-        case 40035:  pPlayers[uActiveCharacter]->SetDisease2(true);   return 0;
-        case 40036:  pPlayers[uActiveCharacter]->SetDisease1(true);   return 0;
-        case 40037:  pPlayers[uActiveCharacter]->SetCursed(true);     return 0;
-        case 40038:  pPlayers[uActiveCharacter]->SetInsane(true);     return 0;
-        case 40039:  pPlayers[uActiveCharacter]->SetDrunk(true);      return 0;
-        case 40040:  pPlayers[uActiveCharacter]->SetUnconcious(true); return 0;
-        case 40041:  pPlayers[uActiveCharacter]->SetDead(true);       return 0;
-        case 40042:  pPlayers[uActiveCharacter]->SetEradicated(true); return 0;
-        case 40043:  pPlayers[uActiveCharacter]->SetAsleep(true);     return 0;
-        case 40044:  pPlayers[uActiveCharacter]->SetAfraid(true);     return 0;
-        case 40045:  pPlayers[uActiveCharacter]->SetParalyzed(true);  return 0;
-        case 40073:  pPlayers[uActiveCharacter]->SetZombie(true);     return 0;
-
-        case 40006:  pParty->SetFood(pParty->uNumFoodRations + 20);   return 0;
-
-        case 40062:
-          pParty->alignment = PartyAlignment_Good;
-          SetUserInterface(pParty->alignment, true);
-          return 0;
-        case 40063:
-          pParty->alignment = PartyAlignment_Neutral;
-          SetUserInterface(pParty->alignment, true);
-          return 0;
-        case 40064:
-          pParty->alignment = PartyAlignment_Evil;
-          SetUserInterface(pParty->alignment, true);
-          return 0;
-
-        //SubMenu "Time"
-        case 40009:  pParty->uTimePlayed += Timer::Day;   return 0;
-        case 40010:  pParty->uTimePlayed += Timer::Week;   return 0;
-        case 40011:  pParty->uTimePlayed += Timer::Month;   return 0;
-        case 40012:  pParty->uTimePlayed += Timer::Year;   return 0;
-
-        //SubMenu "Items"
-        case 40015:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 1 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40016:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 2 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40017:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 3 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40018:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 4 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40019:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 5 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40020:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St == 6 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-        case 40061:
-        {
-          int pItemID = rand() % 500;
-          for ( uint i = 0; i < 500; ++i )
-          {
-            if ( pItemID + i > 499 )
-              pItemID = 0;
-            if ( pItemsTable->pItems[pItemID + i].uItemID_Rep_St > 6 )
-            {
-              pPlayers[uActiveCharacter]->AddItem(-1, pItemID + i);
-              return 0;
-            }
-          }
-        }
-        return 0;
-
-      }
-    }
-    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_LBUTTONDOWN:
-      if (pArcomageGame->bGameInProgress)
-      {
-        pArcomageGame->stru1.field_0 = 7;
-        ArcomageGame::OnMouseClick(0, true);
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-
-      goto __handle_mouse_click;
-
-    case WM_RBUTTONDOWN:
-      if (pArcomageGame->bGameInProgress)
-      {
-        pArcomageGame->stru1.field_0 = 8;
-        ArcomageGame::OnMouseClick(1, true);
-        return DefWindowProcW(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 DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-
-    case WM_LBUTTONUP:
-      if ( !pArcomageGame->bGameInProgress )
-      {
-        back_to_game();
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-      pArcomageGame->stru1.field_0 = 3;
-      ArcomageGame::OnMouseClick(0, 0);
-      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-    case WM_RBUTTONUP:
-      if ( !pArcomageGame->bGameInProgress )
-      {
-        back_to_game();
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-      pArcomageGame->stru1.field_0 = 4;
-      ArcomageGame::OnMouseClick(1, false);
-      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_LBUTTONDBLCLK:
-      if ( pArcomageGame->bGameInProgress )
-      {
-        pArcomageGame->stru1.field_0 = 7;
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-        
-__handle_mouse_click:
-      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 DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_RBUTTONDBLCLK:
-      if ( !pArcomageGame->bGameInProgress )
-      {
-        if (pVideoPlayer->pVideoFrame.pPixels)
-          pVideoPlayer->bStopBeforeSchedule = 1;
-
-        pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
-
-        if (pGame)
-        {
-          pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
-        }
-
-        sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-
-      pArcomageGame->stru1.field_0 = 8;
-
-      return DefWindowProcW(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 DefWindowProcW(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 DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_SYSCOMMAND:
-      if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
-        return 0;
-
-      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_KEYUP:
-      if (wParam == VK_CONTROL)
-      {
-        dword_507B98_ctrl_pressed = 0;
-      }
-
-      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_KEYDOWN:
-      if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
-      {
-        pKeyActionMap->_459F10(wParam);
-        return DefWindowProcW(hWnd, uMsg, 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 )
-        {
-          dword_507B98_ctrl_pressed = 1;
-          return 0;
-        }
-        if ( wParam == VK_ESCAPE )
-        {
-          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
-          return 0;
-        }
-        if ( wParam <= VK_HOME )
-          return 0;
-        if ( wParam > VK_DOWN )
-        {
-          if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
-            return 0;
-          SendMessageW(hWnd, WM_COMMAND, 104, 0);
-          return 0;
-        }
-        if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
-        {
-          if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
-          {
-            if ( !viewparams->field_4C )
-              UI_OnKeyDown(wParam);
-            return 0;
-          }
-        }
-        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
-          return 0;
-      }
-
-      pArcomageGame->stru1.field_0 = 1;
-
-      set_stru1_field_8_InArcomage(MapVirtualKey(wParam, MAPVK_VK_TO_CHAR));
-      if ( wParam == 27 )
-      {
-        pArcomageGame->GameOver = 1;
-        pArcomageGame->field_F4 = 1;
-        pArcomageGame->uGameResult = 2;
-        pArcomageGame->field_B0 = -2;
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-      if ( wParam != 114 )
-      {
-        if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
-          SendMessage(hWnd, WM_COMMAND, 0x68u, 0);
-        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-      }
-      SendMessageW(hWnd, WM_COMMAND, 103, 0);
-      return 0;
-
-    case WM_ACTIVATEAPP:
-      if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
-      {
-        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)
-              Error(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);
-        }
-      }
-      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_SETFOCUS:
-      dword_4E98BC_bApplicationActive = 0;
-      if (pRenderer)
-      {
-        if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
-          SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
-      }
-      ClipCursor(0);
-      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
-
-    case WM_KILLFOCUS:
-      dword_4E98BC_bApplicationActive = 1;
-      return DefWindowProcW(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 )
-      {
-        pArcomageGame->field_F9 = 1;
-      }
-      else
-      {
-        if ( !pRenderer->pRenderD3D && !pRenderer->UsingDirect3D() || !AreRenderSurfacesOk() )
-        {
-          EndPaint(hWnd, &Paint);
-          return 0;
-        }
-      }
-      pRenderer->Present();
-      EndPaint(hWnd, &Paint);
-      return 0;
-
-    default:
-      return DefWindowProcA(hWnd, uMsg, wParam, lParam);
-  }
-}
 
 //----- (00464479) --------------------------------------------------------
 void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows()
@@ -3812,9 +3269,9 @@
   ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
   pGame->Deinitialize();
   pRenderer->Release2();
-  if ( !DestroyWindow(hWnd) )
-    GetLastError();
-  hWnd = 0;
+  delete window;
+  //if ( !DestroyWindow(hWnd) )
+  //  GetLastError();
   exit(exitCode);
 }
 
@@ -4274,7 +3731,7 @@
         }
     }
 
-    if (DialogBoxParamA(GetModuleHandleW(nullptr), "InsertCD", ::hWnd, (DLGPROC)InsertMM7CDDialogFunc, 0))
+    if (DialogBoxParamA(GetModuleHandleW(nullptr), "InsertCD", hWnd, (DLGPROC)InsertMM7CDDialogFunc, 0))
       continue;
     return false;
   }
@@ -4282,35 +3739,6 @@
 
 
 
-void CenterWindowAndAdjustSize(HWND hwnd, int client_width, int client_height)
-{
-  RECT rcWindow;
-  GetWindowRect(hWnd, &rcWindow);
-
-  RECT rcClient;
-  GetClientRect(hWnd, &rcClient);
-
-  int window_borders_width = (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left),
-      window_borders_height = (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top);
-  int window_total_width = client_width + window_borders_width,
-      window_total_height = client_height + window_borders_height;
-
-  
-  if (GetMenu(hwnd))
-    window_total_height += GetSystemMetrics(SM_CYMENU);
-
-  MoveWindow(hWnd, (GetSystemMetrics(SM_CXSCREEN) - window_total_width) / 2,
-                   (GetSystemMetrics(SM_CYSCREEN) - window_total_height) / 2,
-                   window_total_width,
-                   window_total_height, 0);
-/*
-  auto hDesktopDC = GetDC(nullptr);
-  uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES);
-  uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES);
-  ReleaseDC(nullptr, hDesktopDC);
-*/
-}
-
 //----- (004651F4) --------------------------------------------------------
 bool MM7_Initialize(int game_width, int game_height)
 {
@@ -4325,187 +3753,14 @@
     bCanLoadFromCD = false;
   if (bCanLoadFromCD)
   {
-    if (!FindMM7CD(hWnd, &cMM7GameCDDriveLetter))
+    if (!FindMM7CD(nullptr, &cMM7GameCDDriveLetter))
       return false;
   }
 
 
   srand(GetTickCount());
-  
-  WNDCLASSEXW wcxw;
-  {
-    wcxw.cbSize = sizeof(wcxw);
-    wcxw.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
-    wcxw.lpfnWndProc = (WNDPROC)aWinProc;
-    wcxw.cbClsExtra = 0;
-    wcxw.cbWndExtra = 0;
-    wcxw.hInstance = GetModuleHandleW(nullptr);
-    wcxw.hCursor = 0;
-    wcxw.hIcon = wcxw.hIconSm = LoadIconW(wcxw.hInstance, L"MM7_ICON");
-    wcxw.lpszMenuName = nullptr;
-    wcxw.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
-    wcxw.lpszClassName = L"M&MTrilogy";
-  }
-  if (!RegisterClassExW(&wcxw))
-  {
-    Log::Warning(L"Cannot register window class");
-    return false;
-  }
-
-  hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and MagicŪ VII",
-                         WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER,
-                         0, 0,
-                         1, 1,
-                         nullptr,
-                         nullptr,
-                         wcxw.hInstance,
-                         nullptr);
-
-  HMENU menu = CreateMenu();
-  {
-    HMENU file = CreatePopupMenu();
-    AppendMenuW(menu, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)file, L"&File");
-    {
-      AppendMenuW(file, MF_ENABLED | MF_STRING, 40001, L"Exit");
-    }
-
-    HMENU debug = CreatePopupMenu();
-    AppendMenuW(menu, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug, L"&Debug");
-    {
-      HMENU debug_party = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_party, L"&Party");
-      {
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING, 40007, L"Give Gold (10 000)");
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING, 40008, L"Give Exp (20 000)");
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING, 40059, L"Give Skills (50 each)");
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING, 40013, L"Remove Gold");
-
-        HMENU debug_party_setconditions = CreatePopupMenu();
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_party_setconditions, L"Set Condition");
-        {
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40044, L"Afraid");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40043, L"Asleep");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40037, L"Curse");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40036, L"Disease1");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40035, L"Disease2");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40034, L"Disease3");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40041, L"Dead");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40039, L"Drunk");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40042, L"Eradicated");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40038, L"Insane");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40045, L"Paralyzed");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40033, L"Poison1");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40032, L"Poison2");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40031, L"Poison3");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40029, L"&Stone");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40040, L"Unconscious");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40030, L"Weak");
-          AppendMenuW(debug_party_setconditions, MF_ENABLED | MF_STRING, 40073, L"Zombie");
-        }
-
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING, 40006, L"Set Food (20)");
-
-        HMENU debug_party_alignment = CreatePopupMenu();
-        AppendMenuW(debug_party, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_party_alignment, L"Alignment");
-        {
-          AppendMenuW(debug_party_alignment, MF_ENABLED | MF_STRING, 40062, L"Good");
-          AppendMenuW(debug_party_alignment, MF_ENABLED | MF_STRING | MF_CHECKED, 40063, L"Neutral");
-          AppendMenuW(debug_party_alignment, MF_ENABLED | MF_STRING, 40064, L"Evil");
-        }
-      }
-
-      HMENU debug_time = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_time, L"&Time");
-      {
-        AppendMenuW(debug_time, MF_ENABLED | MF_STRING, 40009, L"Add 1 Day");
-        AppendMenuW(debug_time, MF_ENABLED | MF_STRING, 40010, L"Add 1 Week");
-        AppendMenuW(debug_time, MF_ENABLED | MF_STRING, 40011, L"Add 1 Month");
-        AppendMenuW(debug_time, MF_ENABLED | MF_STRING, 40012, L"Add 1 Year");
-      }
-
-      HMENU debug_items = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_items, L"&Items");
-      {
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40015, L"Generate level &1 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40016, L"Generate level &2 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40017, L"Generate level &3 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40018, L"Generate level &4 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40019, L"Generate level &5 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40020, L"Generate level &6 item");
-        AppendMenuW(debug_items, MF_ENABLED | MF_STRING, 40061, L"Generate special item");
-      }
-
-      HMENU debug_graphics = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_graphics, L"&Graphics");
-      {
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40023, L"Lighting Mode");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40024, L"Lighting Geometry");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING | MF_GRAYED, 40104, L"Lights Off");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40105, L"Colored Lights");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40025, L"Debug Lights");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40101, L"Debug Decals");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40027, L"HWID Portals");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40047, L"SWID Portals");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40051, L"OD Frustum");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40054, L"SWOD Constant Redraw");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40055, L"SWOD Lit Rasterizer");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40056, L"Party Light off");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40060, L"SWOD Nice Lighting off");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40067, L"HWOD Additive Fog Lights");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40072, L"HWID Nice Lighting");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40048, L"Wireframe");
-        AppendMenuW(debug_graphics, MF_ENABLED | MF_STRING, 40049, L"Fog");
-      }
-
-      HMENU debug_misc = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_misc, L"&Misc");
-      {
-        AppendMenuW(debug_misc, MF_ENABLED | MF_STRING, 40066, L"Object Viewcone Culling");
-        AppendMenuW(debug_misc, MF_ENABLED | MF_STRING, 40068, L"Red Tint");
-        AppendMenuW(debug_misc, MF_ENABLED | MF_STRING, 40071, L"Display Secrets");
-        AppendMenuW(debug_misc, MF_ENABLED | MF_STRING, 40102, L"Massive Bloodsplat");
-        AppendMenuW(debug_misc, MF_ENABLED | MF_STRING, 40103, L"Underwater Gravity");
-      }
-      
-      HMENU debug_eax = CreatePopupMenu();
-      AppendMenuW(debug, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)debug_eax, L"EAX Environs");
-      {
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40074, L"NONE");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40075, L"GENERIC");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40076, L"PADDEDCELL");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40077, L"ROOM");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40078, L"BATHROOM");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40079, L"LIVINGROOM");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40080, L"STONEROOM");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40081, L"AUDITORIUM");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40082, L"CONCERTHALL");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40083, L"CAVE");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40084, L"ARENA");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40085, L"HANGAR");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40086, L"CARPETEDHALLWAY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40087, L"HALLWAY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40088, L"STONECORRIDOR");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40089, L"ALLEY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40090, L"FOREST");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40091, L"CITY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40092, L"MOUNTAINS");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40093, L"QUARRY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40094, L"PLAIN");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40095, L"PARKINGLOT");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40096, L"SEWERPIPE");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40097, L"UNDERWATER");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40098, L"DRUGGED");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40099, L"DIZZY");
-        AppendMenuW(debug_eax, MF_ENABLED | MF_STRING, 40100, L"PSICHOTIC");
-      }
-    }
-  }
-
-  SetMenu(hWnd, menu);
-  CenterWindowAndAdjustSize(hWnd, game_width, game_height);
-  ShowWindow(hWnd, SW_SHOWNORMAL);
-  
-  SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+
+  window = OSWindow::Create(L"Might and MagicŪ Trilogy", game_width, game_height);
 
   pRenderer = Render::Create();
   if (!pRenderer)
@@ -4516,12 +3771,12 @@
   else
   {
     bool bWindowMode = ReadWindowsRegistryInt("startinwindow", false);
-    uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
+    //uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
     bool bColoredLights = ReadWindowsRegistryInt("Colored Lights", false);
     uint uLevelOfDetail = ReadWindowsRegistryInt("Detail Level", 1);
     uint bTinting = ReadWindowsRegistryInt("Tinting", 1) != 0;
 
-    if (!pRenderer->Initialize(bWindowMode, game_width, game_height, uDefaultDevice, bColoredLights, uLevelOfDetail, bTinting))
+    if (!pRenderer->Initialize(bWindowMode, window, bColoredLights, uLevelOfDetail, bTinting))
     {
       Log::Warning(L"Render failed to initialize");
       return false;
@@ -4797,15 +4052,13 @@
                                                 // or
                                                 //   not in window
   {
-    SetMenu(hWnd, 0);
-    SetWindowLongA(hWnd, GWL_EXSTYLE, 0);
-    SetWindowLongA(hWnd, GWL_STYLE, WS_VISIBLE);
-    pRenderer->InitializeFullscreen(hWnd);
+    window->SetFullscreenMode();
+    pRenderer->InitializeFullscreen();
   }
   else
   {
-    ClipCursor(nullptr);
-    pRenderer->SwitchToWindow(hWnd);
+    window->SetWindowedMode(game_width, game_height);
+    pRenderer->SwitchToWindow();
   }
 
   uSoundVolumeMultiplier = ReadWindowsRegistryInt("soundflag", 9);
@@ -4836,10 +4089,10 @@
   dword_6BE384_2dacceloff = ReadWindowsRegistryInt("2dacceloff", 0);
 
   if (!bNoSound)
-    pAudioPlayer->Initialize(hWnd);
+    pAudioPlayer->Initialize();
 
   pVideoPlayer = new VideoPlayer();
-  pVideoPlayer->Initialize();
+  pVideoPlayer->Initialize(window);
 
   dword_6BE364_game_settings_1 |= 0x4000;
 
@@ -4869,7 +4122,7 @@
 }
 
 //----- (00465D0B) --------------------------------------------------------
-void  SecondaryInitialization()
+void SecondaryInitialization()
 {
   __int16 v4; // ax@4
   signed int v5; // esi@5
@@ -4878,7 +4131,7 @@
   ObjectDesc *v8; // eax@7
   char pContainer[32]; // [sp+10h] [bp-Ch]@9
 
-  pMouse->Initialize(hWnd);
+  pMouse->Initialize(window);
 
   pItemsTable = new ItemsTable;
   pItemsTable->Initialize();