Created
November 1, 2017 12:10
-
-
Save nmfisher/08a7574f759da308a99de7826adfc4d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
WinAPI.HookProc HookProcedure = new WinAPI.HookProc(ThisAddIn.HookProc);
WinAPI.SetWindowsHookEx(0x0003, HookProcedure, (IntPtr)0, AppDomain.GetCurrentThreadId());
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
public static IntPtr ParentProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
public static int HookProc(int nCode, IntPtr wParam, IntPtr lParam) {
System.Diagnostics.Debug.WriteLine(nCode);
return 0;
}
[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
var lpwndpl = new WINDOWPLACEMENT();
lpwndpl.rcNormalPosition = new System.Drawing.Rectangle(rect.Left, rect.Top, rect.Width, rect.Height);
lpwndpl.length = System.Runtime.InteropServices.Marshal.SizeOf(lpwndpl);
WinAPI.SetWindowPlacement((uint)handle.ToInt32(), ref lpwndpl);