We help IT Professionals succeed at work.

WM_KEYDOWN Message in a Dialog

gurukg102498
gurukg102498 asked
on
Medium Priority
434 Views
Last Modified: 2013-11-20
Hi,

I have a SDI application which has a dialog inside it.I will display the dialog when a menu item is clicked. Inside the dialog I have a list control and a refresh button , which will display the records fetched from a database.

After the dialog is displayed whenever I press F5 Key, the dialog needs to get refreshed rather the lsit control should show me the updated records from the database.

Actually I have implemented that in the Refresh button.Also I am able to capture the F5 Key when it is pressed in a dialog by mapping Application's PreMessageFilter. But the thing is after pressing the F5 Key I could not able to get the dialog's list control / Refresh Button's function / methoda say OnRefresh().

Do anyone tell me how to get the handle of Refresh button or how to call Refresh Method of this Dialog.

Thanks
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Hi gurukg,

simply handle WM_KEYDOWN message for VK_F5 in dialog class
by overriding CWnd::PreTranlateMessage() ... then you can there
simply call the function you OnRefresh(), i.e.:

BOOLCMyDlg::PreTranslateMessage(MSG* pMsg)
{
 if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5 )
 {
  OnRefresh();
  return TRUE;
 }
 return CDialog::PreTranslateMessage( pMsg );
}

hope that helps,

ZOPPO
yes, easier to use PreTranslateMessage(), u can substitue it with PreMessageFilter

may i know where you put the PreMessageFilter()? And is your dialog a modal dialog? If it is modal, u must put it in your dialog class, otherwise u can put it in your other class (view, doc, app), and i can show u the code to get the dialog handle from those view, doc, app, and u can call OnRefresh from there.

Author

Commented:
Zoppo,

Thanks a lot for your suggestion. It worked fine.I am ready to award you the points.How will I award you?

Orange_jiuce,

Are you talking about getting the dialog handle from App?

guru
CERTIFIED EXPERT
Commented:
Well, in the caption of my comment you should see a button like 'accept comment as answer' ... press this button and fill the following form ...

BTW, if you want I can also post an answer instead of a comment...
yes and no, i think i can't get your question properly
seems that yours is in the dialog class only

Explore More ContentExplore courses, solutions, and other research materials related to this topic.