Skip to content

Bastitron/Win32Chrome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Win32Chrome

Win32Chrome is a lightweight C++20 library to help implement fully custom, native window titlebars (Window Chrome) for Windows applications. When building user interfaces with GLFW and Dear ImGui, for example, achieving a seamless dark mode or a modern, borderless design usually requires stripping away the native window frame, which breaks default OS behaviors.

This library solves that problem by implementing non-intrusive Window Subclassing. It hooks into the Win32 message pipeline, sits transparently between the OS and your windows original logic (WndProc), and intercepts non-client area messages (such as WM_NCHITTEST) using your UIs layout coordinates.

Screenshots

ImGui & GLFW example App Screenshot

Personal Project: Otari Otari Screenshot

Usage

Important: Windows only. The library links against Win32 system libraries and will not build on other platforms.

The library does not draw a custom title bar. This must be done on your end. See GLFW & ImGUI example.

Manual

git clone https://github.com/Bastitron/Win32Chrome
add_subdirectory(win32chrome)

target_link_libraries(MyApp PRIVATE Win32Chrome)

FetchContent

include(FetchContent)

FetchContent_Declare(
        win32chrome
        GIT_REPOSITORY https://github.com/Bastitron/Win32Chrome.git
        GIT_TAG main
)

FetchContent_MakeAvailable(win32chrome)

target_link_libraries(MyApp PRIVATE Win32Chrome)

// ...
Win32Chrome::Callbacks callbacks{
    .TitlebarBoundingBox = [window] {
        int width, height;
        glfwGetWindowSize(window, &width, &height);
        return Win32Chrome::Rect{
            0, 0, width, TITLEBAR_HEIGHT
        };
    },
    .TitlebarControlsBoundingBox = [window] {
        int width, height;
        glfwGetWindowSize(window, &width, &height);

        return Win32Chrome::ControlRects{
            .Close = Win32Chrome::Rect{
                width - TITLEBAR_CONTROL_WIDTH, 0, TITLEBAR_CONTROL_WIDTH, TITLEBAR_HEIGHT
            },
            .Maximize = Win32Chrome::Rect{
                width - (TITLEBAR_CONTROL_WIDTH * 2), 0, TITLEBAR_CONTROL_WIDTH, TITLEBAR_HEIGHT
            },
            .Minimize = Win32Chrome::Rect{
                width - (TITLEBAR_CONTROL_WIDTH * 3), 0, TITLEBAR_CONTROL_WIDTH, TITLEBAR_HEIGHT
            }
        };
    },
    .TitlebarControlHittest = [](int x, int y) {
        bool inside = (x >= 0 && x < (0 + TITLEBAR_TITLE_SPACE)) && (y >= 0 && y < (0 + TITLEBAR_HEIGHT));
        return inside;
    }
};

HWND hwnd = glfwGetWin32Window(window);
//                                                             Window, Callbacks, Max, Min
Win32Chrome::Win32Chrome chrome = Win32Chrome::Win32Chrome(hwnd, callbacks, true, true);
// ...

Acknowledgements

About

A lightweight C++20 Win32 abstraction library to create fully custom, native window titlebars (Window Chrome). Seamlessly integrates with GLFW and Dear ImGui to handle dragging, snapping, and window controls while maintaining native Windows OS behavior.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors