Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the maximize region of a win32 window using InputNonClientPointerSource secretly reverts back to default #10379

Open
HO-COOH opened this issue Feb 19, 2025 · 0 comments
Labels
needs-triage Issue needs to be triaged by the area owners

Comments

@HO-COOH
Copy link

HO-COOH commented Feb 19, 2025

Describe the bug

I am using InputNonClientPointerSource to set the maximize button region of a win32 window (created with CreateWindow), but it secretly reverts back to default 32px width and position when the window is activated the second time. This event can even be caught using RegionsChanged event.

Steps to reproduce the bug

  1. Create a normal win32 window
static HWND CreateWin32Window()
{
    const wchar_t CLASS_NAME[] = L"Sample Window Class";

    WNDCLASS wc = {};
    wc.lpfnWndProc = WindowProc; // Pointer to the window procedure
    wc.lpszClassName = CLASS_NAME; // Window class name

    // Register the window class
    RegisterClass(&wc);

    // Create the window
    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles
        CLASS_NAME,                     // Window class
        L"Sample Window",                // Window text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

        NULL,       // Parent window
        NULL,       // Menu
        NULL,  // Instance handle
        NULL        // Additional application data
    );
    ShowWindow(hwnd, SW_SHOW);
    return hwnd;
}
  1. Set the region
auto hwnd = CreateWin32Window();
auto windowId = winrt::Microsoft::UI::GetWindowIdFromWindow(hwnd);
auto appWindow = winrt::Microsoft::UI::Windowing::AppWindow::GetFromWindowId(windowId);
appWindow.TitleBar().ExtendsContentIntoTitleBar(true);
auto pointerSource = winrt::Microsoft::UI::Input::InputNonClientPointerSource::GetForWindowId(windowId);
pointerSource.SetRegionRects(
    winrt::Microsoft::UI::Input::NonClientRegionKind::Maximize,
    {
        winrt::Windows::Graphics::RectInt32
        {
            .X = 0,
            .Y = 0,
            .Width = 100,
            .Height = 100
        }
    }
);

pointerSource.RegionsChanged([](
    winrt::Microsoft::UI::Input::InputNonClientPointerSource const& source, 
    winrt::Microsoft::UI::Input::NonClientRegionsChangedEventArgs const& arg)
    {
        // filters the Maximize region change
        if (auto regions = arg.ChangedRegions(); 
            std::ranges::find(regions, winrt::Microsoft::UI::Input::NonClientRegionKind::Maximize) != regions.end())
        {
            auto changedRegions = source.GetRegionRects(winrt::Microsoft::UI::Input::NonClientRegionKind::Maximize);
            for (auto region : changedRegions)
            {
                OutputDebugString(std::format(L"X: {}, Y: {}, Width: {}, Height: {}\n", region.X, region.Y, region.Width, region.Height).data()); // see this message!
            }
        }
    });

Expected behavior

No response

Screenshots

No response

NuGet package version

Windows App SDK 1.6.3: 1.6.250108002

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

IDE

Visual Studio 2022

Additional context

Repro, build and click the button to see.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Feb 19, 2025
@RDMacLachlan RDMacLachlan transferred this issue from microsoft/WindowsAppSDK Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant