#define HOOK_DLL extern "C" __declspec(dllexport)
CMyHookDllApp theApp;
CMyHookDllDlg *pHookDlg;
HHOOK g_hHook;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
HOOK_DLL BOOL WINAPI InstallHook(DWORD dwTID);
HOOK_DLL BOOL WINAPI UnInstallHook();
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL bKeyUp = lParam & (1<<31);
if (bKeyUp && wParam == VK_F12 && nCode == HC_ACTION)
{
if (pHookDlg == NULL)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd *pCWnd = CWnd::GetForegroundWindow();
pHookDlg = new CMyHookDllDlg();
pHookDlg->Create(IDD_DIALOG1, pCWnd);
pHookDlg->ShowWindow(SW_SHOW);
}
else
{
pHookDlg->ShowWindow(pHookDlg->IsWindowVisible() ? SW_HIDE : SW_SHOW);
}
}
return ::CallNextHookEx(g_hHook, nCode, wParam, lParam);
}
HOOK_DLL BOOL WINAPI InstallHook(DWORD dwTID)
{
if (g_hHook == NULL)
{
g_hHook = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, theApp.m_hInstance, dwTID);
if (g_hHook == NULL)
{
return FALSE;
}
MessageBox(NULL, "外挂已注入成功!按F12呼出外挂!", "提示", 0);
}
return TRUE;
}
HOOK_DLL BOOL WINAPI UnInstallHook()
{
//pHookDlg->DestroyWindow();
MessageBox(NULL, "外挂已移出成功!", "提示", 0);
return ::UnhookWindowsHookEx(g_hHook);
}
1