Translating the Keystrokes
来源:互联网 发布:网络教育有哪68所学校 编辑:程序博客网 时间:2024/04/28 18:47
We will now tamper with three lines of code that are common to all the Windows programs we've created so far in this book. The code is the standard message loop:
while (GetMessage (&msg, NULL, 0, 0)){ TranslateMessage (&msg) ; DispatchMessage (&msg) ;}
Here's how we change it to use the keyboard accelerator table:
while (GetMessage (&msg, NULL, 0, 0)){ if (!TranslateAccelerator (hwnd, hAccel, &msg)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; }}
The TranslateAccelerator function determines whether the message stored in the msg message structure is a keyboard message. If it is, the function searches for a match in the accelerator table whose handle is hAccel. If it finds a match, it calls the window procedure for the window whose handle is hwnd. If the keyboard accelerator ID corresponds to a menu item in the system menu, the message is WM_SYSCOMMAND. Otherwise, the message is WM_COMMAND.
When TranslateAccelerator returns, the return value is nonzero if the message has been translated (and already sent to the window procedure) and 0 if not. If TranslateAccelerator returns a nonzero value, you should not call TranslateMessage and DispatchMessage but rather should loop back to the GetMessage call.
The hwnd parameter in TranslateMessage looks a little out of place because it's not required in the other three functions in the message loop. Moreover, the message structure itself (the structure variable msg) has a member named hwnd, which is also a handle to a window.
Here's why the function is a little different: The fields of the msg structure are filled in by the GetMessage call. When the second parameter of GetMessage is NULL, the function retrieves messages for all windows belonging to the application. When GetMessage returns, the hwnd member of the msg structure is the window handle of the window that will get the message. However, when TranslateAccelerator translates a keyboard message into a WM_COMMAND or WM_SYSCOMMAND message, it replaces the msg.hwnd window handle with the hwnd window handle specified as the first parameter to the function. That is how Windows sends all keyboard accelerator messages to the same window procedure even if another window in the application currently has the input focus. TranslateAccelerator does not translate keyboard messages when a modal dialog box or message box has the input focus, because messages for these windows do not come through the program's message loop.
- Translating the Keystrokes
- [Translating Project I] The Annotated C++ Reference Manual
- Assigning keystrokes
- Dynamic Equivalence in Translating
- translating a document
- Translating Numbers to Strings
- Software test & translating
- Using PreTranslateMessage to handle dialog keystrokes
- TransE算法(Translating Embedding)
- TransE算法(Translating Embedding)
- Translating lotus API Data Types to LotusScript
- Translating Virgil's Epic Poem of Empire
- plan translating "applied software project managerment"
- 4.translating&rotating in different spaces
- packet tracer Translating "***"...domain server (255.255.255.255)
- Harvesting Cross Site Scripting (XSS) Victims - Clicks, Keystrokes and Cookies
- 论文阅读笔记一(Recognizing Keystrokes Using WiFi Devices)
- Scaling, Shearing, Translating, and Rotating a Drawn Image:
- Effective C#之Item 40:Match Your Collection to Your Needs
- 虚拟机中无法用ghost中安装xp
- vs2008打了SP1以后,智能提示变成英文的解决办法
- 起停Informix、tuxedo
- Loading the Accelerator Table
- Translating the Keystrokes
- Slab代码分析之calculate_slab_order
- 用select使Accept()具有超时能力
- cisco 路由器的组成和配置
- createTextRange和createRange
- 忏悔录读后感一
- 如何修复msc文件关联
- plc
- 理解C语言声明的优先级规则