Solved

Processing accelerators in a dialog box in Win32 C++

Posted on 2001-06-02
4
504 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
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
Thanks a lot Rob, it works :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now