Problem when maximizing windows in C ++

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

alt text

Everything seems fine, except for the fact that the window was not correctly installed, that is, the window looks a little lower, and the title bar does not look β€œcrushed” as it should. Compared to what it should look like when you click the maximize button, the problem is obvious:

alt text

Does anyone know why this is happening, and what can I do to fix it?

+4
source share
2 answers

Specifying the maximum window size can bypass some of the internal settings that the program makes when it is maximized using the system menu command. To emulate a maximize button, send the SC_MAXIMIZE command:

 SendMessage(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0); 
+10
source

Antoher way of using SetWindowPos (); For example, you got an HWND handleWnd;

 RECT rcWnd; GetWindowRect(handleWnd,&rcWnd); SetWindowPos(handleWnd,WHND_TOP,rcWnd.left,rcWnd.top,(rcWnd.right-rcWnd.left),(rcWnd.bottom-rcWnd.top),SWP_SHOWWINDOW); 

So, you got your previous position, place the window on top of Z and show

0
source

Source: https://habr.com/ru/post/1335496/


All Articles