Jump to content

Recommended Posts

Window Mode Centered on Screen

I saw a lot of posts about the wrong window position (7-pixel offset and similar bugs), but none of them actually fixed it for me.

So I wrote a quick and clean solution — simple but works 100%.

Code is wrapped in 
#ifdef ENABLE_WINDOW_START_CENTER_FRATELLO
so you can toggle it easily.

 

Windowed mode: starts centered on the screen

Fullscreen: starts at (0, 0)

Without define: keeps the default behavior (bAnotherWindow bottom-right)

Nothing fancy, just practical saved me some time, maybe it’ll save yours too.

 

Step 1:

defines.h / locale_inc.h

#define ENABLE_WINDOW_START_CENTER_FRATELLO

Step 2:

SEARCH

Userinterface/Pythonapplication.cpp

 if (Windowed)
 {
 m_isWindowed = true;

 if (bAnotherWindow)
 {
 RECT rc;

 GetClientRect(&rc);

 int windowWidth = rc.right - rc.left;
 int windowHeight = (rc.bottom - rc.top);

 CMSApplication::SetPosition(GetScreenWidth() - windowWidth, GetScreenHeight() - 60 - windowHeight);
 }
 }
 else
 {
 m_isWindowed = false;
 SetPosition(0, 0);
 }




Step 3:


replace


#ifdef ENABLE_WINDOW_START_CENTER_FRATELLO
 if (Windowed)
 {
 m_isWindowed = true;
 RECT rcScreen;
 ::GetWindowRect(GetDesktopWindow(), &rcScreen);
 int screenW = rcScreen.right - rcScreen.left;
 int screenH = rcScreen.bottom - rcScreen.top;
 RECT rcWindow;
 ::GetWindowRect(GetWindowHandle(), &rcWindow);
 int windowW = rcWindow.right - rcWindow.left;
 int windowH = rcWindow.bottom - rcWindow.top;
 int posX = (screenW - windowW) / 2;
 int posY = (screenH - windowH) / 2;
 SetPosition(posX, posY);
 }
 else
 {
 m_isWindowed = false;
 SetPosition(0, 0);
 }
#else
 if (Windowed)
 {
 m_isWindowed = true;
 if (bAnotherWindow)
 {
 RECT rc;
 GetClientRect(&rc);
 int windowWidth = rc.right - rc.left;
 int windowHeight = (rc.bottom - rc.top);
 CMSApplication::SetPosition(GetScreenWidth() - windowWidth, GetScreenHeight() - 60 - windowHeight);
 }
 }
 else
 {
 m_isWindowed = false;
 SetPosition(0, 0);
 }
#endif


FINISH

 

  • Metin2 Dev 1
  • Love 1
Link to comment
https://metin2.dev/topic/34418-fix-window-mode-centered-on-screen/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.