Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem when maximizing window in C++

My program needs to arbitrarily maximize any window on the current desktop. I achieve this by calling ShowWindow(hWnd, SW_MAXIMIZE), where hWnd is the HWND of the window I want to maximize. When that line of code executes, the window in question (here, Notepad) looks like this:

alt text

Everything seems fine, except for the fact that the window has not been positioned correctly, i.e. the window seems to be a few pixels to low, and the title bar does not look "squashed" like it should. Compared to how it should look when the maximize button is clicked, the problem is clearly visible:

alt text

Does anyone know why this behaviour occurs, and what I can do to fix it?

like image 690
AniDev Avatar asked Jan 14 '11 02:01

AniDev


1 Answers

Telling the window to maximize itself might bypass some internal adjustments that the program makes when it maximizes via a system menu command. To emulate clicking on the maximize button, send it a SC_MAXIMIZE command:

SendMessage(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
like image 94
Mark Ransom Avatar answered Sep 29 '22 23:09

Mark Ransom