VC下给CDialog添加加速键(Add accelerators)
为CDialog添加加速键:
//在头文件声明成员变量 HACCEL m_hAccelTable; //在构造函数中调用函数,加入加速键 CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //加速键 m_hAccelTable = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR)); //加速键的资源ID }
//添加PreTranslateMessage消息相应 BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class //加速键事件 if(m_hAccelTable != NULL) { if(TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) { return TRUE; } } return CDialog::PreTranslateMessage(pMsg); }
Trackback from your site.
(1)条评论
VC 筱强
| #
不错
回复