Solved

MDI Message Loop

Posted on 1997-03-10
4
292 Views
Last Modified: 2013-12-03
How should the message loop be written in a Windows 95 MDI application so that the application can recieve WM_COMMAND messages using the Keyboard accelerator. ?
I am using BorlandC++ ver 4.02 and write my program in plain C language.
0
Comment
Question by:makhlouf
  • 2
4 Comments
 
LVL 1

Expert Comment

by:winmeister
ID: 1334197
// Enter main message loop

while (GetMessage(&msg, NULL, 0, 0))

    if (!TranslateMDISysAccel(hwndMDIClient, &msg))
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }


0
 

Author Comment

by:makhlouf
ID: 1334198
When I submitted my question, I already had the loop suggested by
Charles Petzold in his book "Programming Windows 95"
It looks like this

while (GetMessage (&msg, NULL, 0, 0))    {
    if (!TranslateMDISysAccel (hwndClient, &msg) &&
        !TranslateAccelerator (hwndFrame, hAccel, &msg))  {
        TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
    }
}
Unfortunatly, it does not work.
yours is a sub version of Petzold and does not work also.
I compiled my program with your version of the loop and found that the program does not receive WM_COMMAND messages when I enter a command with the KeyBoard Accelerator
0
 

Author Comment

by:makhlouf
ID: 1334199

0
 
LVL 2

Accepted Solution

by:
r parkinson earned 50 total points
ID: 1334200
If you are using the following message loop :

if(!TranslateMDISysAccel(hwndMDIClient,&msg)&&
  !TanslateAccelerator(hwndFrame,hAccel,&msg))
{
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}

and it does not work then check the following :

1) have you loaded the accelorator table correctly?

e.g.

hAccel=LoadSccelerators(hInstance,MAKEINTRESOURCE(ID_ACCEL));

if this fails then the message loop wont work.  There are two likly reasons for failure, either the ID is wrong or the table is not in the module pointed to by the hInstance parameter.

2)  Are you checking for the WM_COMMAND message in the main window proc or the child window proc?

the message should be sent to the main window proc, i.e. the proc that was defined for the hwndFrame handle.

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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