I created a new dialog based project and added OnKeyDown() message handler, but no matter what I pressed, it never got called?
Printable View
I created a new dialog based project and added OnKeyDown() message handler, but no matter what I pressed, it never got called?
override PreTranslateMessage and do:
regardsCode:BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x43 && GetKeyState( VK_CONTROL ) < 0 ) {
_asm int 3
}
return CDialog::PreTranslateMessage(pMsg);
}
when I used your code and press ctrl-c, the code inside got executed when the "ctrl" key was hold, and nothing happened after "c" pressed.
try again i have made a change.
Thanks that works. so 0x43 is the virtual key code for ctrl-c? how about ctrl-v? where did you find the table?
Virtual-Key Codes from MSDN.
Enjoy.
This approach works for CDialog, I assume it works the same way in CView. However, when I out the CView into ActiveX Control, it never got called. Do you know why?
it never get called cause this ActiveX probably not handling Ctrl+C key press. only the the window that Handle it can get it while it in focus of course.Quote:
Originally Posted by tangjun
if you want to detect Ctrl+C in all the system no matter what window is active (at the moment ) you can consider using ::SetWindowsHookEx (..) with WH_KEYBOARD parameter to check it out.
Cheers
However, the OnKeyDown() does get called in activeX control. Can you detect ctrl-c with OnKeyDown()?
I don't want to set it system wide because there are other window than the activex control in the system which is using the contrl-c.
Why don't you just setup an Accelerator to handle Ctrl+C?
how? sample code please?
if you want a system wide then OnKeyDown() is not the correct way. i wrote in my post before if you want a system wide keybaord hook you need to use ::SetWindowsHookEx(..) with WH_KEYBOARD.Quote:
Originally Posted by tangjun
Cheers
no, I don't want system wide, my system will have more than one activex control, each one should handle the control-c by itself. so if ctrl-c pressed, the highlighted one should get called.