实现一个程序两套快捷键

 1 //.h文件
 2 public:
 3     CEdit edit;
 4     CEdit edit2;
 5     HACCEL   m_hAccel;
 6     HACCEL   m_hAccel2;
 7 
 8 
 9 //.cpp文件
10 BOOL CMFCApplication47Dlg::OnInitDialog()
11 {
12         .........................................
13     edit.Create(WS_BORDER, CRect(100, 100, 200, 200), this, 10012);
14     edit.ShowWindow(SW_SHOW);
15     edit2.Create(WS_BORDER, CRect(200,200,300,300), this, 100151);
16     edit2.ShowWindow(SW_SHOW);
17     // TODO: Add extra initialization here
18     m_hAccel = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
19     m_hAccel2 = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR2));
20         ...........................................
21 }
22 
23 BOOL CMFCApplication47Dlg::PreTranslateMessage(MSG* pMsg)
24 {
25     if (GetDlgItem(10012) == GetFocus())
26     {
27         if (m_hAccel)
28         {
29             if (::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))
30             {
31                 return(TRUE);
32             }
33         }
34     }
35     else
36     {
37         if (m_hAccel2)
38         {
39             if (::TranslateAccelerator(m_hWnd, m_hAccel2, pMsg))
40             {
41                 return(TRUE);
42             }
43         }
44     }
45     return CDialogEx::PreTranslateMessage(pMsg);
46 }
47   

 

posted @ 2019-07-09 15:55  Suarezz  阅读(221)  评论(0编辑  收藏  举报