void CCppWindowsHookDlg::OnBnClickedSetshellhook() { // TODO: Add your control notification handler code here CString strButtonText; GetDlgItem(IDC_SETSHELLHOOK)->GetWindowText(strButtonText); if (strButtonText == "Set Shell Hook") { // Install Hook if (!SetShellHook(TRUE, 0, m_hWnd)) { AfxMessageBox(L"Fail to Install Hook!"); return; } GetDlgItem(IDC_SETSHELLHOOK)->SetWindowText(L"Unset Shell Hook"); GetDlgItem(IDC_SETHOOKINPUT)->EnableWindow(FALSE); GetDlgItem(IDC_SETHOOKTHREAD)->EnableWindow(FALSE); GetDlgItem(IDC_SETHOOK)->EnableWindow(FALSE); } else { if (!SetShellHook(FALSE)) { AfxMessageBox(L"Fail to Install Hook!"); return; } GetDlgItem(IDC_SETHOOKINPUT)->SetWindowText(L"Set Shell Hook"); GetDlgItem(IDC_SETHOOKINPUT)->EnableWindow(TRUE); GetDlgItem(IDC_SETHOOKTHREAD)->EnableWindow(TRUE); GetDlgItem(IDC_SETHOOK)->EnableWindow(TRUE); } }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { BOOL ret; hInst = hInstance; // Store instance handle in our global variable int width = GetSystemMetrics(SM_CXFULLSCREEN); int height = GetSystemMetrics(SM_CYFULLSCREEN) - 23; hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); SetWindowPos(hWnd, HWND_TOP, 0, 0, 800, 800, SWP_NOREDRAW | SWP_SHOWWINDOW); //SetWindowPos(hWnd, HWND_TOPMOST,0,0,height,width, SWP_NOREDRAW | SWP_SHOWWINDOW); if (!hWnd) { return FALSE; } if (!SetShellHook(hWnd)) { MessageBox(hWnd, TEXT("F"), NULL, MB_OK); return 3; } MySystemProc(hWnd); // Enumerate Windows and Desktops ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(uMsg == WM_SHELLHOOKMESSAGE) { int i; for(i = 0; shell_list[i].pMsg; i++) { if(shell_list[i].uMsg == wParam) { AddEditText(shell_list[i].pMsg, (HWND)lParam); return 0; } } return 0; } switch(uMsg) { case WM_SIZE: { RECT rect; GetClientRect(hwnd, &rect); MoveWindow(hwndEdit, 0, 0, rect.right - rect.left, rect.bottom - rect.top, TRUE); return 0; } case WM_CREATE: { RECT rect; hwndMain = hwnd; GetClientRect(hwnd, &rect); hwndEdit = CreateWindowEx(0, WC_EDIT, NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hwnd, (HMENU)IDC_EDIT, ((CREATESTRUCT*)lParam)->hInstance, NULL); if(!SetShellHook(hwnd)) { MessageBox(hwnd, "SetShellHook, failed.", NULL, MB_OK); } return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CLOSE: UnSetShellHook(hwnd); DestroyWindow(hwnd); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }