RegisterHotKey注册热键,然后响应WM_HOTKEY消息
MSDN中的一个示例代码,步骤就是RegisterHotKey注册热键,然后响应WM_HOTKEY消息
@1:这个是系统热键
- #include "stdafx.h"
- int _cdecl _tmain (
- int argc,
- TCHAR *argv[])
- {
- if (RegisterHotKey(
- NULL,
- 1,
- MOD_ALT | MOD_NOREPEAT,
- 0x42)) //0x42 is 'b'
- {
- _tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"));
- }
- MSG msg = {0};
- while (GetMessage(&msg, NULL, 0, 0) != 0)
- {
- if (msg.message == WM_HOTKEY)
- {
- _tprintf(_T("WM_HOTKEY received\n"));
- }
- }
- return 0;
- }
@2:软件非全局的快捷键,Keyboard Accelerators(键盘加速器)
- FontAccel ACCELERATORS
- {
- VK_F5, IDM_REGULAR, VIRTKEY
- "B", IDM_BOLD, CONTROL, VIRTKEY
- "I", IDM_ITALIC, CONTROL, VIRTKEY
- "U", IDM_ULINE, CONTROL, VIRTKEY
- }
- HWND hwndMain; // handle to main window
- HANDLE hinstAcc; // handle to application instance
- int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg; // application messages
- BOOL bRet; // for return value of GetMessage
- HACCEL haccel; // handle to accelerator table
- // Perform the initialization procedure.
- // Create a main window for this application instance.
- hwndMain = CreateWindowEx(0L, "MainWindowClass",
- "Sample Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
- hinst, NULL );
- // If a window cannot be created, return "failure."
- if (!hwndMain)
- return FALSE;
- // Make the window visible and update its client area.
- ShowWindow(hwndMain, nCmdShow);
- UpdateWindow(hwndMain);
- // Load the accelerator table.
- // haccel = LoadAccelerators(hinstAcc, MAKEINTRESOURCE(IDC_*)) ;IDC_*为.RC资源中的加速器ID
- haccel = LoadAccelerators(hinstAcc, "FontAccel");
- if (haccel == NULL)
- HandleAccelErr(ERR_LOADING); // application defined
- // Get and dispatch messages until a WM_QUIT message is
- // received.
- while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
- {
- if (bRet == -1)
- {
- // handle the error and possibly exit
- }
- else
- {
- // Check for accelerator keystrokes.
- if (!TranslateAccelerator(
- hwndMain, // handle to receiving window
- haccel, // handle to active accelerator table
- &msg)) // message data
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- }
- return msg.wParam;
- }
- LRESULT APIENTRY MainWndProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- BYTE fbFontAttrib; // array of font-attribute flags
- static HMENU hmenu; // handle to main menu
- switch (uMsg)
- {
- case WM_CREATE:
- // Add a check mark to the Regular menu item to
- // indicate that it is the default.
- hmenu = GetMenu(hwndMain);
- CheckMenuItem(hmenu, IDM_REGULAR, MF_BYCOMMAND |
- MF_CHECKED);
- return 0;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- // Process the accelerator and menu commands.
- case IDM_REGULAR:
- case IDM_BOLD:
- case IDM_ITALIC:
- case IDM_ULINE:
- // GetFontAttributes is an application-defined
- // function that sets the menu-item check marks
- // and returns the user-selected font attributes.
- fbFontAttrib = GetFontAttributes(
- (BYTE) LOWORD(wParam), hmenu);
- // SetFontAttributes is an application-defined
- // function that creates a font with the
- // user-specified attributes the font with
- // the main window's device context.
- SetFontAttributes(fbFontAttrib);
- break;
- default:
- break;
- }
- break;
- // Process other messages.
- default:
- return DefWindowProc(hwndMain, uMsg, wParam, lParam);
- }
- return NULL;
- }
http://blog.csdn.net/x356982611/article/details/16341797
RegisterHotKey注册热键,然后响应WM_HOTKEY消息的更多相关文章
- 用RegisterHotKey注册系统热键
函数功能:该函数定义一个系统范围的热键. 函数原型:BOOL RegisterHotKey(HWND hWnd,int id,UINT fsModifiers,UINT vk): 参数: hWnd:接 ...
- WPF注册热键后处理热键消息(非winform方式)
由于最近在做wpf版的截图软件,在处理全局热键的时候,发现国内博客使用的都是winform窗体的键盘处理方式,此方式需要使用winform的动态库,如此不协调的代码让我开始在github中寻找相关代码 ...
- RegisterHotKey注册快捷键
RegisterHotKey的具体使用方使用方法如下: BOOL RegisterHotKey( HWND hWnd, //响应该热键的窗口句柄 Int id, ...
- WinForm和WPF中注册热键
由于.Net没有提供专门的类库处理热键,所以需要直接调用windows API来解决. HotKey为.NET调用Windows API的封装代码,主要是RegisterHotKey和Unregist ...
- MFC注册热键
注册热键. 当用户点击注册的快捷键时,做出相应的响应. 定义 ALT+M键为测量按钮响应函数: 头文件中定义: #define ID_HOTKEY1 10001 在初始化函数中加入注册热键函数: if ...
- 离奇失踪的WM_HOTKEY消息--浅析WIN32消息队列
故事的开端有些平淡,眼红于XXX小程序,认为写完该程序就有了和心仪的妹子多相处的机会,必须搞,必须酷,按钮不能有,界面得隐藏,这就想到了全局快捷键. 注册调用RegisterHotKey(m_hWnd ...
- MFC 给对话框注册热键
在头文件中添加: //}}AFX_MSGafx_msg LRESULT OnHotKey(WPARAM wParam,LPARAM lParam);//(此行为加入的)BEGIN_MESSAGE_MA ...
- delphi注册热键方法(一)
uses windows,menus; ..... //声明 HotKey_Key: Word; HotKey_Shift: Word; procedure WMHotKey(var msg : Tm ...
- 【WinForm程序】注册热键快捷键切换
重写DefWndProc事件 #region Window 消息捕获 const int WM_COPYDATA = 0x004A; public struct COPYDATASTRUCT { pu ...
随机推荐
- eclipse中使用maven插件的时候,运行run as maven build/clean的时候报错
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a ...
- JAVA_2Lesson
package test; public class abc { public static void main(String[] arg) { int[][] xx=new int[3][]; xx ...
- android中获取 bitmap 像素的颜色 之吸管取色功能
本功能是参考android API colorPickerView修改,实现类似与PS中吸管取色功能.也就是可以对图片的任意位置取该位置的RGB.本demo中,完成了色盘取色功能.当点击色盘的某个位置 ...
- linux shell编程指南第十一章------------合并与分割2
c u t用来从标准输入或文本文件中剪切列或域.剪切文本可以将之粘贴到一个文本文件. 下一节将介绍粘贴用法. c u t一般格式为: cut [options] file1 file2 下面介绍其可用 ...
- Struts2运行机制(MVC)的分析:
C:(controller)控制器 M:(model)模型处理 V:(view)视图 Struts 2 的运行过程: 核心控制器是FilterDispatcher会过滤 ...
- Oracle、DB2、MySql、SQLServer JDBC驱动
四种数据库JDBC驱动,还列出了连接的Class驱动名和Url Pattern,DB2包括Type 2.Type 3和Type 4三种模式.注意驱动包名称的大小写. Oralce连接驱动包名和URL ...
- CSDN-Code平台使用过程中的5点经验教训
昨天又创建了一个项目,fucms,可是本地一直没有权限提交,搞了非常久,试了几十次,都不行,我是非常的灰心和郁闷. 刚刚,和CSDN-Code的官方客服咨询了非常久非常久,最终摸索出来了一些心得体会 ...
- 用spring-data-redis实现类似twitter的网站(转)
1. spring-data-redis简介 封装了一下redis的客户端,使得使用起来更方便. 优点是把客户端连接放到一个连接池里,从而提高性能.还有就是可以不同的客户端之间实现切换,而不用改一行代 ...
- [jQuery] check if an id exists - Google 网上论坛
[jQuery] check if an id exists - Google 网上论坛 From: http://docs.jquery.com/Frequently_Asked_Questions ...
- CF 552C 进制转换
http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...