Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Processing accelerators in a dialog box in Win32 C++

Posted on 2001-06-02
4
Medium Priority
?
554 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:cshlin
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6150119
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
0
 
LVL 1

Author Comment

by:cshlin
ID: 6150154
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 :)
0
 
LVL 5

Accepted Solution

by:
robpitt earned 400 total points
ID: 6150244
Something like...



hAccel=LoadAccelerator(...)
hWnd=CreateDialog(...)
ShowWindow(hWnd,SW_SHOWDEFAULT)

while (GetMessage(&msg,NULL,0,0)>0)
{
    if (!TranslateAccelerator(msg.hwnd,hAccel,&msg) &&
        !IsDialogMessage(hWnd,&msg) )
    {
        TranslateMessage(&msg)
        DispatchMessage(&msg)
    }
}

Note : if using the above your DialogProc should call PostQuitMessage() to finish and not EndDialog() as in modal dialog boxes.



Rob




0
 
LVL 1

Author Comment

by:cshlin
ID: 6151786
Thanks a lot Rob, it works :)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question