I was able to get Maximized and Size changed events, but not Maximize started.
Asked
Active
Viewed 289 times
-3
-
2https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanging – user2120666 Jun 02 '20 at 17:32
-
Actually I tried WM_WINDOWPOSCHANGING earlier but it was sent to all events like Z index changed, window moved, resized. So I just added a bit of logic to check if size is equals to working area size. – TƎИ. developer Jun 02 '20 at 18:30
1 Answers
0
I found solution for my problem. Here is hook method that you can add for your code and do all needed staff before Window Maximized event occurs.
private static void WmWindowPos(IntPtr hwnd, IntPtr lParam)
{
WINDOWPOS wpos = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS));
IntPtr monitorContainingApplication = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitorContainingApplication == IntPtr.Zero)
return;
var monitorInfo = new MONITORINFO();
GetMonitorInfo(monitorContainingApplication, monitorInfo);
var rcWorkArea = monitorInfo.rcWork;
if (wpos.x == rcWorkArea.left &&
wpos.y == rcWorkArea.top &&
wpos.cx == rcWorkArea.right &&
wpos.cy == rcWorkArea.bottom)
{
// Do required staff before windows maximized state has changed
}
}
Add this method to WindowProc like this
private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case 0x0046: // WM_WINDOWPOSCHANGING
WmWindowPos(hwnd, lParam);
break;
}
return (IntPtr)0;
}

TƎИ. developer
- 15
- 5
-
Hi, you can mark your own answer to end this thread. This can be beneficial to other community members reading this thread in the future. – Strive Sun Jun 11 '20 at 09:47