I am currently working on a program that uses a functionality that should alert me when an other process's window is maximizing/maximized. With the maximize event I mean pressing the symbols next to the close button on the top right corner.
To accomplish this I use the SetWinEventHook function. The problem is that I can't find the correct event code to catch this event. I tried the EVENT_SYSTEM_MOVESIZESTART, EVENT_SYSTEM_MOVESIZEEND, EVENT_SYSTEM_MINIMIZESTART and EVENT_SYSTEM_MINIMIZEEND
constants but they all don't seem to trigger on the maximize event. I however can trace other events so my implementation of SetWinEventHook is working.
Does anyone maby has an idea on how to capture the maximize event from an other process?
Thanks in advance.
With friendly greetings, Bob
Code example:
// To catch the event
SetWinEventHook(EVENT_MIN, EVENT_MAX, IntPtr.Zero, new WinEventDelegate(WinEventProc), GetProcess(), 0, 0);
// The handler
private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
// TODO: Filter maximize event here
if (eventType == ?)
{
// Do something
}
}
In SetWinEventHook()
’s callback, handle the EVENT_OBJECT_LOCATIONCHANGE
event and check if the window is in maximized state by calling the GetWindowPlacement()
function and comparing the showCmd
property of its second argument with the SW_SHOWMAXIMIZED
constant.
C++ example:
void CALLBACK exampleHook(HWINEVENTHOOK hook, DWORD event, HWND hWnd,
LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if (EVENT_OBJECT_LOCATIONCHANGE == event) {
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp);
if (SW_SHOWMAXIMIZED == wp.showCmd) {
// Window is maximized.
}
}
}
Fwiw, I used this approach in my ExplorerHiDpiFix utility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With