 |
|
 |
Thanks a lot for the information..
|
|
|
|
 |
|
 |
Exactly what I was looking for! With little MFC knowledge I could finally add keystrokes to a legacy MFC application, thank you!
|
|
|
|
 |
|
 |
Finally found what I was looking for, after 3 days of search. Superb site. Best forum for developers!
THANKS NISHANT!!!
THANKS CODEPROJECT!!!!
CHEERS!!!
Raj
|
|
|
|
 |
|
|
 |
|
 |
Pretty good article. It works well with accelerators. Earlier I was trying to handle CTRL+ clicks in PreTranslateMessage, the main issue I faced was that if the control is with edit box or some other control, CTRL+ click would not work. For it to start working again, I had to click on the main window(to set focus). But with accelerator, it works really well. No issues faced.
One small problem I faced in the beginning was with m_pMainWnd->m_hWnd, which was not defined in the article, but it is actually pointer to CDialog class whose instance is called in InitInstance. One might come across few more problems related to declaring pointer to Cdialog class. One can declare the pointer globally and then assign &dlg to it.(CDialogMain dlg, in my case). All of this will be done in class derived from CWinApp.
Cheers,
|
|
|
|
 |
|
|
 |
|
 |
I have implemented the given code. It is working fine for main dialog. But for child dialog accelerator keys are not working.
|
|
|
|
 |
|
 |
Its been forever since you posted this. Did you ever find a solution for this?
|
|
|
|
 |
|
 |
I have a dialog that needs to capture the Enter key mulitple times. I have impmlemented the PreTranslateMessage as such:
if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
SetSomeFlag();
return TRUE;
}
However, the message does not get handled correctly after the first one(by calling SetSomeFlag()) unless I have a break point set there.
|
|
|
|
 |
|
 |
I have defined this in my dialog class also declared a ON_WM_KEYDOWN()message map, any ideas?
|
|
|
|
 |
|
 |
hi all
i want to call click event of button with "Ctrl + Up" keyboard shortcut.
i have used ::PreTranslateMessage(MSG *pMsg) but tell me what could be
value of pMsg->message and pMsg->wParam to handle the same.
thanx
maulesh
|
|
|
|
 |
|
 |
how can i use my accelator in my dll?
Can you please the code for doing this?
and if i use shortcut keys it will work in the main application (My dll functionality as short cut keys)?
please give some code snippet, which is useful for my question.....
Rammy
|
|
|
|
 |
|
 |
i've tried using the code. but i can only use the keyboard input after i've minimized and maximized the program i worked out. any suggestion?? ??
anyway,NICE ARTICLE there. keep up the good work!
regards,
fikree
|
|
|
|
 |
|
 |
Hello Nish I want to simulate the mouse behavior holding down a button with a key in a diglog application, and I tried it with your method. But it doesn't work. When i push down the key,the buton was down then up immeidately even if i am still holding down the key ,the button is just like being clicked not holded down as the mouse can do. I want some tips. regards BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->wParam==VK_RIGHT){ if(pMsg->message==WM_KEYDOWN && ((pMsg->lParam>>30 & 1)==0)) m_myButton.SendMessage(WM_LBUTTONDOWN); if(pMsg->message==WM_KEYUP) m_myButton.SendMessage(WM_LBUTTONUP); } return CDialog::PreTranslateMessage(pMsg); } chenzd
|
|
|
|
 |
|
 |
I've run into a bit of a problem with this. I've implemented this solution and it works fine except that the accelerators are active not only for the dialog, but for all child dialogs as well.
For example, I set Insert, Delete, and Ctrl+A as accelerators to insert an item, delete an item, and select all items in a list control. This is fine, but when the Insert Item or Delete Prompt dialogs come up, those keys are still active and when pressed, perform their action.
It should not call TranslateAccelerator if a child dialog has the focus. I am working around this by having my main dialog have a member boolean which I set to false before running any child dialogs and back to true afterwards. I then change the ProcessMessageFilter function like so:
if (m_hAccel) {
to
if (m_hAccel&&((CFooBar*)m_pMainWnd)->m_Focus) {
I don't like this because it requires casting to the dialog type and accessing a variable (using an accessor function is even worse), and more importantly, it requires setting/clearing the flag before and after each child dialog.
Does anyone have a better solution?
Thanks.
--
Synetech
|
|
|
|
 |
|
 |
Hi,
I discussed this with Joe Newcomer who has this in one of his articles and we solved it. Just change this line in ProcessMessageFilter:
if(m_haccel)
to this:
if (m_hAccel && m_pMainWnd->IsWindowEnabled())
Works like a charm.
--
Synetech
|
|
|
|
 |
|
 |
Hi,
This works very well. I've been wondering why accelerators don't seem to work in my apps and now I know why (although I'm pretty sure I've read the reason before.) I've added those three tiny pieces of code and now my apps are alive with productivity.
Thanks a lot.
--
Synetech
|
|
|
|
 |
|
 |
In case,while I'm running another program(minimize the program that support Hots key)It will can't use hots key of the program that I minimize it.
If I want to make it always support although I use another program.
How I do for this case?
|
|
|
|
 |
|
|
 |
|
 |
Why error???
I used POCKET PC 2003 // Win32(WCE emulator) Debug // POCKET PC 2003 emulator
Please, help me !!! thanks
BOOL CEX1App::ProcessMessageFilter(int code, LPMSG lpMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
return(TRUE);
}
return CWinApp::ProcessMessageFilter(code, lpMsg); // =>error C2039: 'ProcessMessageFilter' : is not a member of 'CWinApp'}
Thanks
|
|
|
|
 |
|
|
 |
|
 |
Hi:
First thanks to the brief short article that gives a clear explaination.
I have an application that has main window and child windows. A dialog box under one child window needs to have accelerators.
How can I utilise the method suggested in this article?
Thank you for any suggestion/advice.
kezhu
|
|
|
|
 |
|
 |
Hello,
this is great, but how to call any function after press, for example, ctrl + D????
// in my Application Class:
BOOL CDialogApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
{
OnClear(); // this funktion should be called after the user have press ctrl + D, this is a Dialogclass member!
return(TRUE); // the program run to here, but they dont call the OnClear(); Funktion???!! Why???
}
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
regards
break;
-- modified at 8:01 Wednesday 11th January, 2006
|
|
|
|
 |
|
 |
Hi,
i make them like this, but im not sure that is the best solution!!!
BOOL CDialogApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel) // m_haccel hat den "Alt + D" Code!
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
{
CDialogDlg *cDialog = (CDialogDlg*)AfxGetApp()->GetMainWnd(); // Referenz to the Dialogclass who have this OnClear() Funktion
cDialog->OnClear();
return(TRUE);
}
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
Now when the user press "Alt + D" run this OnClear() Funktion and clear all items(controls) on my dialog, or any other Funktion!
break;
|
|
|
|
 |
|
 |
Tanks For ever VC++.net programering.
|
|
|
|
 |