Win32 SDK中设置Hotkey
2013-11-15 16:25
363 查看
MSDN中的一个示例代码,步骤就是RegisterHotKey注册热键,然后响应WM_HOTKEY消息
@1:这个是系统热键
@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
}
@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; }
相关文章推荐
- Win32 SDK控件详细设置
- 关于Android SDK Manager无法获取更新列表的正确设置
- Android开发之项目初建时设置minSdkVersion,maxSdkVersion,targetSdkVersion,compile作用
- android sdk manager设置国内镜像快速下载sdk
- xilinxSDK关于调试中终端的设置
- flex 开发air 2.0 sdk 设置
- VC++ WIN32 sdk实现按钮自绘详解.
- win32 sdk绘制矩形选择框
- 提取VS的Win32SDk用C/C++编译器
- 一个Win32SDK的通用的打开、保存文件的对话框的调用
- win32 api CreateWindow创建窗口控件及设置字体
- MFC和Win32 SDK的区别
- 彻底明白如何设置minSdkVersion和targetSdkVersion
- 初学者必看:VC++、Win32 SDK、MFC的区别
- Win32 SDK 实现UDP聊天室程序(一)
- 快捷键设置控件: THotKey [1]
- 设置BaseSDK和DeploymentTarget
- OUYA——设置Android SDK Manager(开发环境配置3)
- Android Studio 设置/更改 SDK 路径
- VC6默认目录设置SDK