Solved

Processing accelerators in a dialog box in Win32 C++

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
MS Access (Newest One): Pulling Data out of a MS SQL DB 1 47
What is MicroStrategy.NET? 2 68
What .NET URL re-routing tool did I use? 2 56
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

809 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