Solved

Processing accelerators in a dialog box in Win32 C++

Posted on 2001-06-02
4
509 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

15 Experts available now in Live!

Get 1:1 Help Now