Skip to content

Instantly share code, notes, and snippets.

@nmfisher
Created November 1, 2017 12:10
Show Gist options
  • Save nmfisher/08a7574f759da308a99de7826adfc4d7 to your computer and use it in GitHub Desktop.
Save nmfisher/08a7574f759da308a99de7826adfc4d7 to your computer and use it in GitHub Desktop.
var hwndSource = HwndSource.FromHwnd(handle);
if (hwndSource != null)
{
hwndSource.AddHook(WindowProc);
}
WinAPI.ShowWindowAsync(new WindowInteropHelper(OverlayForm).Handle, 0);
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case 0x0003:
uint uFlags = WinAPI.SWP_NOACTIVATE | WinAPI.SWP_NOZORDER;
int parent = Application.ActiveWindow.Hwnd;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
WinAPI.GetWindowRect((IntPtr)parent, ref rect);
WinAPI.SetWindowPos((uint)hwnd.ToInt32(), parent, 0, 0, rect.Right, rect.Bottom, uFlags);
break;
}
return (IntPtr)0;
}
@nmfisher
Copy link
Author

nmfisher commented Nov 2, 2017

[DllImport("user32.dll")]
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hWnd, int id);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment