-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Article:
https://www.codeproject.com/Tips/1057230/Windows-Resize-and-Move
Sources:
WindowsMover-src.zip
private readonly int windowMessage_ShellHook;
public WindowsHookForm()
{
windowMessage_ShellHook = WindowsApi.RegisterWindowMessage("SHELLHOOK");
WindowsApi.RegisterShellHookWindow(this.Handle);
}
public event Action<IntPtr> WindowCreatedEvent;
public event Action<IntPtr> WindowActivatedEvent;
public event Action<IntPtr> WindowDestroyedEvent;
protected override void WndProc(ref Message message)
{
if(message.Msg == windowMessage_ShellHook)
{
WindowsApi.ShellEvents shellEvent = (WindowsApi.ShellEvents)message.WParam.ToInt32();
IntPtr windowHandle = message.LParam;
switch(shellEvent)
{
case WindowsApi.ShellEvents.HSHELL_WINDOWCREATED:
if(WindowCreatedEvent != null)
WindowCreatedEvent(windowHandle);
break;
case WindowsApi.ShellEvents.HSHELL_WINDOWACTIVATED:
if(WindowActivatedEvent != null)
WindowActivatedEvent(windowHandle);
break;
case WindowsApi.ShellEvents.HSHELL_WINDOWDESTROYED:
if(WindowDestroyedEvent != null)
WindowDestroyedEvent(windowHandle);
break;
}
}
base.WndProc(ref message);
}
Additional source:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registershellhookwindow