描述:
MSDN:Q187988 PRB: ActiveX Control Is the Parent Window of Modeless Dialog
中的方法,但是不能响应长按键。
我知道OnKeyDown中的Param中有标志长按键次数的,但是在键盘钩子上不行!
到底行不行啊!键盘钩子的原理我不懂,能给解释解释吗?
最好给个方案,代码如下
// Handle to the Windows Message hook. It can be a global variable or a
// member variable in your CPropertySheet-derived class.
HHOOK hHook = NULL;
// Hook procedure for WH_GETMESSAGE hook type.
LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Switch the module state for the correct handle to be used.
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
if((lParam & 0x40000000)==0) // key down
{
BOOL bHandle = TRUE;
OnKeyDown(wParam, wParam, lParam, bHandle);
return 0;
}
// Passes the hook information to the next hook procedure in
// the current hook chain.
return ::CallNextHookEx(hHook, nCode, wParam, lParam);
}
// Declare and define the following two functions:
BOOL CModelessPropertySheet::OnInitDialog()
{
CPropertySheet::OnInitDialog();
// Install the WH_GETMESSAGE hook function.
hHook = ::SetWindowsHookEx(
WH_GETMESSAGE,
GetMessageProc,
AfxGetInstanceHandle(),
GetCurrentThreadId());
ASSERT (hHook);
return TRUE; // Return TRUE unless you set the focus to a control.
// EXCEPTION: OCX Property Pages should return FALSE.
}
void CModelessPropertySheet::OnClose()
{
// Uninstall the WH_GETMESSAGE hook function.
VERIFY (::UnhookWindowsHookEx (hHook));
CPropertySheet::OnClose();
}
--我喜欢WTL和ATL!--