CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Posts
    6

    Help - Low Level CBTProc Hook

    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

  2. #2
    Join Date
    Aug 2005
    Location
    Seattle, Wa
    Posts
    179

    Re: Help - Low Level CBTProc Hook

    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);

  3. #3
    Join Date
    Jul 2007
    Posts
    6

    Re: Help - Low Level CBTProc Hook

    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?

  4. #4
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646

    Re: Help - Low Level CBTProc Hook

    This is an old post I made for VB 6 but I think it still holds true for C# RegisterShellHook

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured