SetWindowsHookEx(WH_KEYBOARD,KeyBoardProc,NULL,GetCurrentThreadId());
第一个为消息类型,听说有13种
第二个为返回消息
第三个为HINSTANCE
第四个为(用DLL全局钩子的话该项可为0)线程ID
LRESULT CALLBACK KeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
消息处理
LRESULT CALLBACK KeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
CString str;
int keydown ;
for(keydown=0x41 ;keydown<=0x5A;keydown++)
{
if((DWORD)keydown == wParam)
{
if(FindWindow(NULL,"获取按键值") != NULL)
{
CHOOK_KEYBOARDDlg * ck ;
// ck =(CHOOK_KEYBOARDDlg *)FindWindow(NULL,"获取按键值") ;
// ck =(CHOOK_KEYBOARDDlg *)GetActiveWindow();
// ck =(CHOOK_KEYBOARDDlg *)GetParent(GetActiveWindow());
// ck->m_hWnd =FindWindowEx(NULL,NULL,NULL,_T("获取按键值"));
ck =(CHOOK_KEYBOARDDlg *)ck->FromHandle( ::FindWindowEx(NULL,NULL,NULL,_T("获取按键值")) );
ck->m_Epassword.Format("%c",(TCHAR)wParam);
ck->UpdateData(false);
}
}
}
return CallNextHookEx(oldkeyhook, nCode, wParam, lParam);
}
评论