哪位高人能解决用代码来实现ALT+X的快捷键的功能?

yingfeng80 2003-08-22 01:27:57
如何用写程序代码来实现ALT+X的快捷键的功能?????
...全文
100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Napoleo 2003-08-25
  • 打赏
  • 举报
回复
用SendMessage()
bcpl 2003-08-25
  • 打赏
  • 举报
回复
加上加速键资源,响应wm_command
zhouyong0371 2003-08-25
  • 打赏
  • 举报
回复
是呀,捕获键盘消息吧
yanzai8848 2003-08-25
  • 打赏
  • 举报
回复
你还是看MSDN的源文章吧,以下两篇都可以看看,其实实现起来不难。
HOWTO: Using Accelerator Keys Within a Modal Dialog Box
HOWTO: Using Accelerator Keys with Modal Dialog Box Main Window
yanzai8848 2003-08-25
  • 打赏
  • 举报
回复
MSDN:
HOWTO: Using Accelerator Keys with Modal Dialog Box Main Window

步骤如下(可能工程不一样):
Load the TRACER project into Visual C++.


For all versions of 16-bit Visual C++, and Visual C++ 32-bit Editions through version 2.2, start App Studio.

For Visual C++ 4.0 and later, select the Resource View in the Project Workspace window.


Edit the dialog box resource and specify the "thin" border style. This step is required for a dialog box that contains a menu.


Create a new menu resource that contains a top level entry "&File" and a menu item "&Exit\tCTRL+E"(CTRL+X is usually associated with cutting text, so CTRL+E was used instead).


Associate the menu with the dialog box by entering the menu ID in the dialog resource properties edit control.


Select the "&Exit\tCTRL+E" menu item and click the ClassWizard button on the toolbar.


In the Add Class dialog box, choose Select Class. Then choose CPromptDlg and click OK. Visual C++ 4.0 recognizes that the menu resource is not associated with any object and prompts you to associate it with the CPromptDlg class.


In the ClassWizard dialog box, select the menu ID associated with the Exit menu, ID_FILE_EXIT, and the COMMAND message. Then choose Add Function.


The Add Member Function dialog box proposes a name for the function which you can edit if desired. Click OK.


Click Edit Code. Insert the following line into the function:

PostMessage(WM_COMMAND, IDOK, 0L);
This gives the same effect as clicking OK when the user chooses Exit from the File menu. Clicking OK closes TRACER.


Create a new accelerator resource and associate the CTRL+E key combination with ID_FILE_EXIT.


Save the resources and close App Studio.


Edit the TRACER.CPP file to declare the following variables after the #include statements:

HWND ghDlg; // Handle to main dialog box
HACCEL ghAccelTable; // Handle to accelerator table



In ClassWizard, choose the CPromptDlg and the WM_INITDIALOG message and add a function. With Visual C++ 4.0, choose the CPromptDlg class, the CPromptDlg Object ID, the WM_INITDIALOG message, and Add Function. Note that there are now two OnInitDialog() functions, one for Macintosh, surrounded by #ifdef _MAC/#endif directives, and the one just added.


Edit the function added above to include the following line of code:

ghDlg = m_hWnd;
In Visual C++ 4.0, be sure to edit the newly added function, not the existing, Macintosh-specific one:

ghDlg = m_hWnd;



Edit CTraceApp::InitInstance() in the Tracer.cpp file to add the following line immediately after the call to SetDialogBkColor() or, as in Visual C++ 4.0, after the declaration of dlg, the CPromptDlg object:

ghAccelTable = LoadAccelerators(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_ACCELERATOR1));



Edit the CTracerApp class definition to add the following line to the public section:

virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);



Add the following function after the InitInstance() function:

BOOL CTracerApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if (code < 0)
CWinApp::ProcessMessageFilter(code, lpMsg);

if (ghDlg && ghAccelTable)
{
if (::TranslateAccelerator(ghDlg, ghAccelTable, lpMsg))
return(TRUE);
}

return CWinApp::ProcessMessageFilter(code, lpMsg);
}



Compile and run TRACER. It should have a menu. When you choose Exit from the File menu or press CTRL+E, the application closes, as expected.
yingfeng80 2003-08-25
  • 打赏
  • 举报
回复
我的意思是在以对话框模式的窗体中怎样用代码编写使用ALT+一个字母作为快捷键的程序,我用GetKeyState来捕获ALT键,可是不行,非要加CTRL键,我不知道用什么消息捕获ALT键
goooool 2003-08-23
  • 打赏
  • 举报
回复
在程序中添加消息WM_CHAR处理就可以。
在你判断当前输入的字符是ATL+X时用exit(0);就可以了
XiangDong 2003-08-22
  • 打赏
  • 举报
回复
ALT+X是什么功能?

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧