RegisterHotKey 详解

The RegisterHotKey function defines a system-wide hot key.
BOOL RegisterHotKey(  HWND hWnd,//接受热键通知的窗口句柄 
                    int id,// 热键标示 
                     UINT fsModifiers, // 组合键标示  
                    UINT vk // 虚拟键码); 
Parameters
hWnd
Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
如果为空,放到调用线程消息队列中,用消息循环处理
id
Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.
同一个线程中不能有相同的标示,(0x0000-0xBFFF)
共享库的范围(0xC000-0xFFFF), 要用 GlobalAddAtom返回标示,避免冲突。
fsModifiers
Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values. 组合键码
ValueMeaning
MOD_ALTEither alt key must be held down.
MOD_CONTROLEither ctrl key must be held down.
MOD_SHIFTEither shift key must be held down.
MOD_WINEither WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo.

vk
Specifies the virtual-key code of the hot key.
Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.
如果某键被按下,系统比较所有注册热键,一旦发现匹配,发送热键消息到注册热键的线程,并放到队首,供下次
循环取走使用
This function cannot associate a hot key with a window created by another thread.
不能跨越线程使用

RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.
        如果组合键被注册了,就会失败

If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters. 如果这个线程的这个窗体已经注册了某热键,热键标示会代替那个热键

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值