1 mesaj
Nou Venit Nou Venit
  • Mesaje: 1
  • Reacții: 32
  • Mesaje utile: 0
  • Medalii

    *Descriere:[C++] Metin2 Client Window Centering Bug (Win10/11) – Real Cause and Permanent Solution

    Before: the window is slightly shifted to the right

    *Poze / Video:[C++] Metin2 Client Window Centering Bug (Win10/11) – Real Cause and Permanent Solution - Mesaj 1 - Imagine 1

    After: the window is perfectly centered, regardless of taskbar position

    *Poze / Video:https://youtu.be/3nt14bw2VYU

    How to

    Client\Source\EterLib\MSWindow.cpp:
    Code:
    // Find and erase
    
    void CMSWindow::GetWindowRect(RECT* prc)
    {
        ::GetWindowRect(m_hWnd, prc);
    }
    
    // Add new helper functions
    
    static bool GetVisualWindowRect(HWND hwnd, RECT& outRect)
    {
        if (!::GetWindowRect(hwnd, &outRect))
            return false;
    
        using DwmGetWindowAttributeFn = HRESULT(WINAPI*)(HWND, DWORD, PVOID, DWORD);
        constexpr DWORD ExtendedFrameBounds = 9;
    
        static HMODULE s_dwm = ::LoadLibraryA("dwmapi.dll");
        if (!s_dwm)
            return true;
    
        static auto s_getAttr =
            reinterpret_cast<DwmGetWindowAttributeFn>(
                ::GetProcAddress(s_dwm, "DwmGetWindowAttribute"));
    
        if (!s_getAttr)
            return true;
    
        RECT visual{};
        if (SUCCEEDED(s_getAttr(hwnd, ExtendedFrameBounds, &visual, sizeof(visual))))
        {
            outRect = visual;
        }
    
        return true;
    }
    
    static POINT GetCenteredPosition(const RECT& visualRect, const RECT& workArea, const RECT& windowRect)
    {
        const int width = visualRect.right - visualRect.left;
        const int height = visualRect.bottom - visualRect.top;
    
        const int dx = visualRect.left - windowRect.left;
        const int dy = visualRect.top - windowRect.top;
    
        POINT pt{};
        pt.x = workArea.left + ((workArea.right - workArea.left) - width) / 2 - dx;
        pt.y = workArea.top + ((workArea.bottom - workArea.top) - height) / 2 - dy;
        return pt;
    }
    
    // change function void CMSWindow::SetCenterPosition()
    
    void CMSWindow::SetCenterPosition()
    {
        RECT window{};
        RECT visual{};
        RECT workArea{};
    
        if (!::GetWindowRect(m_hWnd, &window))
            return;
    
        visual = window;
        GetVisualWindowRect(m_hWnd, visual);
    
        ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
    
        const POINT pos = GetCenteredPosition(visual, workArea, window);
        SetPosition(pos.x, pos.y);
    }
    Client\Source\EterLib\MSWindow.h:
    Code:
    // Find and erase
    
            void GetWindowRect(RECT* prc);
    Client\Source\UserInterface\PythonApplication.cpp:
    Code:
    // Find and erase
    
        bool bAnotherWindow = false;
    
        if (FindWindow(NULL, c_szName))
        {
            bAnotherWindow = true;
        }
    
    // Find @@ bool CPythonApplication::Create(PyObject * poSelf, const char* c_szName, int wid
    
            AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());
    
    // Add this underneath
    
            CMSWindow::SetCenterPosition();
    
    // Find and erase @@ bool CPythonApplication::Create(PyObject * poSelf, const char* c_szName, int wid
    
    
                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);
                }
    Client\Source\UserInterface\UserInterface.cpp:
    Code:
    // Add to the top of the file
    
    #include <shellscalingapi.h>
    #pragma comment(lib, "Shcore.lib")
    
    // Find
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    
    // Add this
        SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
    Thanks but did you tried change DPI or multi monitor when secondary is not locked or multi gpu???

    i solved this problem some long time ago like this way:

    Code:
    UserInterface.cpp
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); // this is what we need add before ini and create window
    
    PythonApplication.cpp
    
    		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());
    
    		if (Windowed)
    		{
    			RECT rcWorkArea{};
    			SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
    
    			RECT rc{};
    			GetWindowRect(&rc);
    			int windowWidth  = rc.right - rc.left;
    			int windowHeight = rc.bottom - rc.top;
    
    			int x = rcWorkArea.left + (rcWorkArea.right - rcWorkArea.left - windowWidth) / 2;
    			int y = rcWorkArea.top  + (rcWorkArea.bottom - rcWorkArea.top - windowHeight) / 2;
    
    			SetWindowPos(GetWindowHandle(), NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
    		}
    		else
    		{
    			m_isWindowed = false;
    			SetPosition(0, 0);
    		}

    Nou Cum descarc de pe TeraBox?

    Afișează detalii Ascunde detalii
    • Este asemănător cu Mega.nz
    • Instalați-vă clientul lor de Download de aici
    • Faceți-vă un cont (vă puteți loga cu Facebook / Google / etc)
    • Nou Dacă nu vreți să descărcați clientul de Download, folosiți acest site
    • Gata! Acum puteți descărca resursele rapid & simplu.

    De ce folosim TeraBox?

    • Este gratuit
    • Primești 1TB de spațiu gratuit la orice cont creat!
    • Este ușor de folosit și varianta premium este foarte ieftină
    • Fișierele nu sunt șterse niciodată
    TeraBox logo

    🔥 Hai pe Discord! - Chat activ și support direct

    Te așteptăm și pe serverul de Discord - aici ne-am strâns toată comunitatea de Metin2 din România.

    Alătură-te acum!
    Suntem aproape: 
    Robot Discord
    Roboțelu'
    Anunț

    Creează-ți un cont sau autentifică-te pentru a participa la discuție

    Trebuie să fii membru pentru a răspunde

    Creează-ți un cont

    Membrii pot crea subiecte noi și pot descărca resurse Metin2 Gratuit!


    Te poți înregistra sau conecta rapid utilizând contul tău de Discord, Github sau Google.

    Înregistrare

    Autentifică-te

    Înapoi la “FIX-uri”

    Informații

    Utilizatori ce navighează pe acest forum: Alexandra Badea, Anthony NR1, gpss, strategic2 și 2 vizitatori

    Discord ID copiat: