Das Snap-Layout-Menü wird unter Windows 11 für die benutzerdefinierte Maximierungsschaltfläche nicht angezeigtC++

Programme in C++. Entwicklerforum
Guest
 Das Snap-Layout-Menü wird unter Windows 11 für die benutzerdefinierte Maximierungsschaltfläche nicht angezeigt

Post by Guest »

Mein Ziel ist es, eine benutzerdefinierte Maximierungsschaltfläche für meine App zu erstellen, und ich möchte auch das Snap-Layout-Menü auf der Schaltfläche unter Windows 11 auslösen. Dazu folge ich der Anleitung von hier, aber es funktioniert nicht.< /p>
Hier ist der Beispielcode. Zu Testzwecken nehme ich ein Rechteck {Punkt(0,0), Größe(200,200)} und wenn die Maus darüber ist, erhalte ich die WM_NCHITTEST-Nachricht I gib das zurück HTMAXBUTTON wie in der Anleitung beschrieben, aber das Snap-Layout-Menü wird nicht angezeigt.

Code: Select all

#include 

#ifndef UNICODE
#define UNICODE
#endif

#include 
#include 

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[]  = L"Sample Window Class";

WNDCLASS wc = { };

wc.lpfnWndProc   = WindowProc;
wc.hInstance     = hInstance;
wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);

// Create the window.

HWND hwnd = CreateWindowEx(
0,                              // Optional window styles.
CLASS_NAME,                     // Window class
L"Test Window",    // Window text
WS_OVERLAPPEDWINDOW,            // Window style

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

NULL,       // Parent window
NULL,       // Menu
hInstance,  // Instance handle
NULL        // Additional application data
);

if (hwnd == NULL)
{
return 0;
}

ShowWindow(hwnd, nCmdShow);

// Run the message loop.

MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);

// All painting occurs here, between BeginPaint and EndPaint.

FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

EndPaint(hwnd, &ps);
}
return 0;

case WM_NCHITTEST:
{
// Get the point in screen coordinates.
// GET_X_LPARAM and GET_Y_LPARAM are defined in windowsx.h
POINT point = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
// Map the point to client coordinates.
::MapWindowPoints(nullptr, hwnd, &point, 1);
RECT maximizeRect {0, 0, 200, 200};
// If the point is in your maximize button then return HTMAXBUTTON
if (::PtInRect(&maximizeRect, point))
{
printf("maxmize button rect %d\n", rand());
fflush(stdout);
return HTMAXBUTTON;
}

break;
}

}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post