Accelerators in a Dialog application
-
I've added an accelerator, then Ctrl+W then selected my main Dlg class. However, when I run my program and press the keys, the accelerator doesn't work... thanks for help -Mike
Have you called
LoadAccelerators()
in the dialog's constructor? You'll also need to override thePreTranslateMessage()
method and callTranslateAccelerator()
accordingly.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Have you called
LoadAccelerators()
in the dialog's constructor? You'll also need to override thePreTranslateMessage()
method and callTranslateAccelerator()
accordingly.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
Hmm, can you give me an example please? I'm kinda new... CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CD2HackKitDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } thanks
-
Hmm, can you give me an example please? I'm kinda new... CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CD2HackKitDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } thanks
CTestDlg::CTestDlg(CWnd* pParent) : CDialog(CTestDlg::IDD, pParent)
{
m_hAccelTable = LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
}BOOL CTestDlg::PreTranslateMessage( LPMSG pMsg )
{
if (NULL != m_hAccelTable)
{
if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
return (TRUE);
}return CDialog::PreTranslateMessage(pMsg);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
CTestDlg::CTestDlg(CWnd* pParent) : CDialog(CTestDlg::IDD, pParent)
{
m_hAccelTable = LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
}BOOL CTestDlg::PreTranslateMessage( LPMSG pMsg )
{
if (NULL != m_hAccelTable)
{
if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
return (TRUE);
}return CDialog::PreTranslateMessage(pMsg);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen