Link to home
Start Free TrialLog in
Avatar of cshlin
cshlin

asked on

Processing accelerators in a dialog box in Win32 C++

I'm creating a program in Win32 C++ that's a dialog-box based app. How can I get the accelerators that work in the main window to work in the dialog box?
Avatar of robpitt
robpitt

Normally you would do a LoadAccelerator() and then add a TranslateAccelerator() call to your main message loop. The problem is that for modal dialog boxes you don't have access to that main message loop.

There are two fixes:

1) Don't use a modal dialog box. Instead use a modeless one and implement a message loop (GetMessage, TransalateAccelerate etc)

*or*

2) Continue using a modal dialog but also add a thread specific WH_MSGFILTER hook (see SetwindowsHookEx). Then in the hook filter you can call TranslateAccelerator and only if TranslateAccelerator doesn't handle the message do you call CallNextHookEx.


Rob
Avatar of cshlin

ASKER

Rob,
  Sounds like the kind of thing I've been finding from info searches, but can you elaborate more on how to do step 1 (a bit of sample code for message loop and where to put it)? I'm fairly new at this :)
ASKER CERTIFIED SOLUTION
Avatar of robpitt
robpitt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cshlin

ASKER

Thanks a lot Rob, it works :)