CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: PreTranslateMessage()

  1. #1
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    PreTranslateMessage()

    Hi there! Can anyone here tell me what is PreTranslateMessage() and what does it do?

    Also, what is the MSG* pMsg parameter in PreTranslateMessage()? Thanks!(how do U use it?)

    "Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria

    "I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria

  2. #2
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    Re: PreTranslateMessage()

    Hi,

    If u look in MSDN: "The TranslateMessage function translates virtual-key messages into character messages."
    Now, I've used many times to capture messages form controls of dialog boxes (edits, buttons, etc.).
    The MSG *pMsg is a pointer to a MSG structure who contains:typedef struct tagMSG { // msg
    HWND hwnd;
    UINT message;
    WPARAM wParam;
    LPARAM lParam;
    DWORD time;
    POINT pt;
    } MSG;

    So, how u use it: let's say that u want to capture the enter key from a edit box in youd dialog based app. Then in your overriden PreTranslateMessage u must capture the WM_KEYDOWN message (pMsg->message == WM_KEYDOWN) and check your hwnd edit box (pMsg->hWnd == m_edit.m_hWnd) and for what key was pressed (pMsg->wParam == VK_RETURN) and return FALSE if all of this conditions are TRUE.

    Tell me if that help or if u need more info.

    Regards,
    Emi.
    Regards,

    Emanuel Vaduva

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: PreTranslateMessage()

    Many times people use PreTranslateMessage when they do not know a more appropriate solution. For example, to capture the enter key from a edit box, give the edit box a multliline style and derive a class from CEdit. Then you can override OnKeyDown, OnkeyUp and/or OnChar.

    See: http://home.socal.rr.com/samhobbs/VC...teMessage.html



    ****************************************************************************************************
    Ratings are unimportant but feedback is. Let the helper and the worldwide community know what works, perhaps with ratings.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  4. #4
    Join Date
    Nov 1999
    Location
    Dresden / Germoney
    Posts
    1,402

    Re: PreTranslateMessage()

    hi,

    a) Why & How do you want to use it? That's the first question that comes not only to Sam Hobb's mind ;-)

    b) What it is:
    To process windows messages, each (UI) thread has a so called message loop, or message pump. this consists basically of:

    1. Get message from Thread's Msg Queue
    2. TranslateMessage: creates WM_CHAR messages from 'raw keyboard' messages (WM_KEYDOWN/UP)
    3. Dispatch message to the window that is responsoble for handling


    MFC allows you to get hold of each message beetween 1 and 2. This is sometimes necessary to intercept messages that can#t be handled otherwise.

    c) The members of the MSG struct are documented in MSDN. The relate to the parameters of a WindowProc.

    Peter



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)