private void cbtHook_Callback(int nCode, IntPtr wParam, IntPtr lParam, ref bool handled) { switch ((HCBT)nCode) { case HCBT.SetFocus: // wParam // Определяет дескриптор окна, получающего фокус клавиатуры. // lParam // Определяет дескриптор окна, теряющего фокус клавиатуры. //e.HWndGaining = (IntPtr)wParam; //e.HWndLosing = lParam; if (SetFocusCallback != null) { SetFocusCallback.Invoke(wParam, lParam, ref handled); } break; case HCBT.Activate: // wParam // Определяет дескриптор окна, которое будет активировано // lParam // Specifies a long pointer to a CBTACTIVATESTRUCT structure containing the handle // to the active window and specifies whether the activation is changing because of a mouse click. if (ActivateCallback != null) { CBTActivateStruct cbtActivateStruct = (CBTActivateStruct)Marshal.PtrToStructure(lParam, typeof(CBTActivateStruct)); ActivateCallback.Invoke(wParam, cbtActivateStruct.fMouse, ref handled); } break; case HCBT.SysCommand: // wParam // Определяет значение системной команды (SC_) // lParam // low-order = X // high-order = Y | This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic. switch ((SysCommands)wParam) { case SysCommands.SC_TASKLIST: //e.Location = new System.Drawing.Point((int)lParam & 0xFFFF, (int)lParam >> 16); if (TaskListCallback != null) { TaskListCallback.Invoke((int)lParam, ref handled); } break; } break; } }
public static IntPtr CBTHookProcFn(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(CallNextHookEx(hHook, nCode, wParam, lParam)); } else if (nCode == HCBT_ACTIVATE) { //Marshall the data from the callback. CBTActivateStruct cbtActivateStruct = (CBTActivateStruct)Marshal.PtrToStructure(lParam, typeof(CBTActivateStruct)); m_Debug.DebugPrint(String.Format("hWnd = {0}", cbtActivateStruct.hWndActive)); } else if (nCode == 9) //HCBT_SETFOCUS) { m_Debug.DebugPrint(String.Format("hWndFocus = {0}, hWndLose = {1}", wParam.ToInt32(), lParam.ToInt32())); } else { return(CallNextHookEx(hHook, nCode, wParam, lParam)); } return(CallNextHookEx(hHook, nCode, wParam, lParam)); }