MFC HOOK
HHOOK hook = NULL; HHOOK hook1 = NULL; LRESULT CALLBACK MouseProc//屏蔽键盘上的鼠标操作 ( int nCode, // hook code WPARAM wParam, // message identifier LPARAM lParam // mouse coordinates ) { return 1; } HWND hwnd = NULL; LRESULT CALLBACK KeyboardProc ( int code, // hook code WPARAM wParam, // virtual-key code LPARAM lParam // keystroke-message information ) { // if (VK_F4 == wParam || 1 ==( lParam >> 29 & 1))//屏蔽键盘上的ALT + F4 // { // return 1; // } // else // { // return CallNextHookEx(hook,code,wParam,lParam); // } ////////////////////////////////////////////////////////////////////////// /*if (VK_F2 == wParam) //按F2键退出程序 { ::SendMessage(hwnd,WM_CLOSE,NULL,NULL); UnhookWindowsHookEx(hook); UnhookWindowsHookEx(hook1); }*/ ////////////////////////////////////////////////////////////////////////// return 1; } BOOL CHOOKDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in <a href="http://www.larkenrose.com/store.html">Buy Viagra</a> the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here hwnd = m_hWnd; hook1 = SetWindowsHookEx(WH_MOUSE,MouseProc,NULL,GetCurrentThreadId()); hook = SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL,GetCurrentThreadId()); return TRUE; // return TRUE unless you set the focus to a control }