Is it possible to create a low level hook of the CBTProc Function (so that I can detect when an external window is minimized, etc)? If it's possible, how would I go about doing it?
Thanks in advanced!
-Eric
Printable View
Is it possible to create a low level hook of the CBTProc Function (so that I can detect when an external window is minimized, etc)? If it's possible, how would I go about doing it?
Thanks in advanced!
-Eric
Windows hooks aren't the easiest thing to accomplish.
You will need to import some win32 functions, and do a google search on how to implement them for your desired methods.
SetWindowsHookEx
UnhookWindowsHookEx
CallNextHookEx
Code:[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
Int32 wParam, IntPtr lParam);
The problem I'm running into is that it seems that hooking using the WH_CBT event with SetWindowsHookEx() will only apply to the current process, and does not seem to apply to external applications even when set up like a global hook. Is there any other way besides using the CBT hook that would allow me to be able to detect when any window is minimized?
This is an old post I made for VB 6 but I think it still holds true for C# RegisterShellHook