Click here to Skip to main content
15,886,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pretranslatemessageoverride Pin
prateekkathuria26-Aug-04 12:14
prateekkathuria26-Aug-04 12:14 
GeneralRe: pretranslatemessageoverride Pin
prateekkathuria26-Aug-04 11:04
prateekkathuria26-Aug-04 11:04 
GeneralRe: pretranslatemessageoverride Pin
Joaquín M López Muñoz26-Aug-04 10:39
Joaquín M López Muñoz26-Aug-04 10:39 
GeneralRe: pretranslatemessageoverride Pin
prateekkathuria26-Aug-04 10:46
prateekkathuria26-Aug-04 10:46 
GeneralRe: pretranslatemessageoverride Pin
Joaquín M López Muñoz26-Aug-04 10:52
Joaquín M López Muñoz26-Aug-04 10:52 
GeneralRe: pretranslatemessageoverride Pin
GKarRacer26-Aug-04 12:27
GKarRacer26-Aug-04 12:27 
GeneralRe: pretranslatemessageoverride Pin
prateekkathuria27-Aug-04 8:23
prateekkathuria27-Aug-04 8:23 
GeneralRe: pretranslatemessageoverride Pin
GKarRacer27-Aug-04 10:31
GKarRacer27-Aug-04 10:31 
Overriding OnCommand is the correct place to do this.

Why isn't PreTranslateMessage being called?
I had to think about this for a bit and reach back into the message loop days. PreTranslateMessage is not called for every type of message sent to a window. It is primarily a pre-cursor beforing calling the API function TranslateMessage.

TranslatesMessage's primary function is to convert key strokes into WM_CHAR messages or into command accelerators.

MFC's message loop, in a nutshell, looks like this:

while( GetMessage(pMsg) )
{
    if( ! AfxPreTranslateMessage(pMsg) )
    {
        ::TranslateMessage(pMsg);
        ::DispatchMessage(pMsg);
    }
}


The key thing to note here as the GetMessage does not return for every message received by the application. It only returns for WM_QUIT, posted messages (I think), and keyboard handling. WM_COMMAND messages are sent directly to the window procedure from within GetMessage. The reason for this is that there is no translation necessary.

Think of it this way. The purpose of PreTranslateMessage/TranslateMessage is not to perform some action when a message is received. That's what the appropriate message handlers are for (like OnCommand). It's job is to convert message IDs from one to another as needed. For example if you press "Ctrl+N" it converts the WM_KEYUP to WM_COMMAND (ID_FILE_NEW).
GeneralRe: pretranslatemessageoverride Pin
prateekkathuria27-Aug-04 10:43
prateekkathuria27-Aug-04 10:43 
GeneralRe: pretranslatemessageoverride Pin
GKarRacer27-Aug-04 10:56
GKarRacer27-Aug-04 10:56 
GeneralCommand - line processing Pin
Andre Massada26-Aug-04 10:06
Andre Massada26-Aug-04 10:06 
GeneralRe: Command - line processing Pin
Bob Stanneveld26-Aug-04 10:13
Bob Stanneveld26-Aug-04 10:13 
GeneralRe: Command - line processing Pin
David Crow26-Aug-04 10:22
David Crow26-Aug-04 10:22 
GeneralRe: Command - line processing Pin
Andre Massada26-Aug-04 10:29
Andre Massada26-Aug-04 10:29 
GeneralRe: Command - line processing Pin
David Crow27-Aug-04 2:31
David Crow27-Aug-04 2:31 
GeneralDLL programming Pin
Madmaximus26-Aug-04 6:54
Madmaximus26-Aug-04 6:54 
QuestionDetecting memory leaks!? Pin
umarcool26-Aug-04 6:06
umarcool26-Aug-04 6:06 
AnswerRe: Detecting memory leaks!? Pin
jmkhael26-Aug-04 6:21
jmkhael26-Aug-04 6:21 
AnswerRe: Detecting memory leaks!? Pin
Rick York26-Aug-04 6:36
mveRick York26-Aug-04 6:36 
GeneralTime function Pin
Supaflyfrank26-Aug-04 5:53
Supaflyfrank26-Aug-04 5:53 
GeneralRe: Time function Pin
jmkhael26-Aug-04 6:18
jmkhael26-Aug-04 6:18 
GeneralRe: Time function Pin
David Crow26-Aug-04 8:52
David Crow26-Aug-04 8:52 
GeneralRe: Time function Pin
Bob Stanneveld26-Aug-04 10:24
Bob Stanneveld26-Aug-04 10:24 
GeneralRe: Time function Pin
David Crow26-Aug-04 10:26
David Crow26-Aug-04 10:26 
GeneralRe: Time function Pin
Supaflyfrank26-Aug-04 13:00
Supaflyfrank26-Aug-04 13:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.