Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Processing accelerators in a dialog box in Win32 C++

Posted on 2001-06-02
4
Medium Priority
?
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

722 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