Giter Site home page Giter Site logo

Comments (2)

texus avatar texus commented on August 26, 2024

This is unrelated to TGUI and specific about the Windows API. I have no experience with functions like DwmExtendFrameIntoClientArea, so I can't help with this.

from tgui.

xland avatar xland commented on August 26, 2024

Thanks for reply.

I found out a way.
But only for windows.

#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <Windows.h>
#include <windowsx.h>
#include <dwmapi.h>

WNDPROC SFMLWndProc;
const POINT border{
    GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER),
    GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)
};

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
    switch (msg) {
        case WM_NCCALCSIZE:
        {
            if (wparam == TRUE)
            {
                WINDOWPLACEMENT placement;
                GetWindowPlacement(hwnd, &placement);
                if (placement.showCmd == SW_MAXIMIZE) {                        
                    auto monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL);
                    MONITORINFO monitor_info{};
                    monitor_info.cbSize = sizeof(monitor_info);
                    GetMonitorInfo(monitor, &monitor_info);
                    auto& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(lparam);
                    params.rgrc[0] = monitor_info.rcWork;
                }
                return false;
            }
            break;
        }
        case WM_NCHITTEST: {
            POINT cursor{ GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam) };
            RECT winRect;
            if (!GetWindowRect(hwnd, &winRect)) {
                return HTNOWHERE;
            }
            static const unsigned client{ 0b0000 }, left{ 0b0001 }, 
                right{ 0b0010 }, top{ 0b0100 }, bottom{ 0b1000 };
            const auto result =
                left * (cursor.x < (winRect.left + border.x)) |
                right * (cursor.x >= (winRect.right - border.x)) |
                top * (cursor.y < (winRect.top + border.y)) |
                bottom * (cursor.y >= (winRect.bottom - border.y));
            switch (result) {
                case left: return HTLEFT;
                case right: return HTRIGHT;
                case top: return HTTOP;
                case bottom: return HTBOTTOM;
                case top | left: return HTTOPLEFT;
                case top | right: return HTTOPRIGHT;
                case bottom | left: return HTBOTTOMLEFT;
                case bottom | right: return HTBOTTOMRIGHT;
                case client: return HTCAPTION;
                default: return HTNOWHERE;
            }
            break;
        }
    }
    return CallWindowProc(SFMLWndProc, hwnd, msg, wparam, lparam);
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
     _In_ LPTSTR lpCmdLine, _In_ int nCmdShow)
{
    sf::RenderWindow window(sf::VideoMode(sf::Vector2u(800, 600)), "MyWin");
    tgui::Gui gui{ window };
    auto hwnd = window.getNativeHandle();
    SFMLWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
    SetWindowPos(hwnd, nullptr, 0, 0, 0, 0,
        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
    const MARGINS shadowState{ 0,0,0,1 };
    DwmExtendFrameIntoClientArea(hwnd, &shadowState);
    gui.mainLoop();
}

from tgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.