抓图程序开发实践
2010-05-12 20:35:23 来源:WEB开发网3. 钩子函数如下:
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
BOOL bProcessed=FALSE;
if(HC_ACTION==nCode)
{
if((lParam&0xc0000000)==0xc0000000){// 有键松开
switch(wParam)
{
case VK_MENU:
MaskBits&=~ALTBIT;
break;
case VK_CONTROL:
MaskBits&=~CTRLBIT;
break;
case VK_SHIFT:
MaskBits&=~SHIFTBIT;
break;
default: //judge the key and send message
break;
}
for(int index=0;index<MAX_KEY;index++){
if(hCallWnd[index]==NULL)
continue;
if(IsWindow(hCallWnd[index])&&(HotKey[index]==wParam)&&(HotKeyMask[index]==MaskBits)){
SendMessage(hCallWnd[index],WM_HOTKEY,wParam,WM_KEYUP);
bProcessed=TRUE;
}
}
}
else if((lParam&0xc000ffff)==1){ //有键按下
switch(wParam)
{
case VK_MENU:
MaskBits|=ALTBIT;
break;
case VK_CONTROL:
MaskBits|=CTRLBIT;
break;
case VK_SHIFT:
MaskBits|=SHIFTBIT;
break;
default: //judge the key and send message
break;
}
for(int index=0;index<MAX_KEY;index++){
if(hCallWnd[index]==NULL)
continue;
if(IsWindow(hCallWnd[index])&&(HotKey[index]==wParam)&&(HotKeyMask[index]==MaskBits)){
SendMessage(hCallWnd[index],WM_HOTKEY,wParam,WM_KEYDOWN);
bProcessed=TRUE;
}
}
}
if(!bProcessed){ //一般按键事件,为监视键盘的程序留出余地
for(int index=0;index<MAX_KEY;index++){
if(hCallWnd[index]==NULL)
continue;
if(IsWindow(hCallWnd[index])&&(HotKey[index]==0)&&(HotKeyMask[index]==0))
SendMessage(hCallWnd[index],WM_HOTKEY,WM_HOTKEY,lParam); //lParam的意义可看MSDN中WM_KEYDOWN部分
}
}
}
return CallNextHookEx( hHook, nCode, wParam, lParam );
}
这样,热键管理的DLL就做好了,我们就可以在程序里调用AddHotkey了
更多精彩
赞助商链接