I'm trying to programmatically maximize my top-level window in my Win32 C++ program. I'm using code similar to the following in the code that handles the WM_CREATE
message:
WINDOWPLACEMENT windowPlacement = {};
windowPlacement.length = sizeof(WINDOWPLACEMENT);
windowPlacement.rcNormalPosition = newWindowRect;
windowPlacement.showCmd = SW_NORMAL;
if (maximized == TRUE)
{
windowPlacement.showCmd = SW_SHOWMAXIMIZED;
}
SetWindowPlacement(hwnd, &windowPlacement);
When this code executes, if maximized
is TRUE
, the window is set to the size of a maximized window, but the maximize/restore button is still a maximize button, not a restore button.
I've tried using the ShowWindow()
function with the same results.
It turns out the WM_CREATE
message handler was the wrong place to do this. After moving the code out of the window procedure and into the wWinMain()
function after the call to CreateWindow()
but before the call to ShowWindow()
, it works as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.