CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    21

    How do I implement the KeyPreview function VB has in VC++ 6.0

    I want to Emulate the KeyPreview facility that VB has. ie In a dialog box I want to process any keypresses in the dialog box before they go to the controls in the dialog box. I'm using VC++ 6.0

    Help....

    Centurion Software Australia

  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: How do I implement the KeyPreview function VB has in VC++ 6.0

    Override the dialogue box's PreTranslateMessage() method as follows:

    ---
    BOOL CMyDialogue::PreTranslateMessage(MSG *psMSG)
    {
    BOOL bDealtWith = FALSE ;

    if (psMSG->message == WM_CHAR)
    {
    // If you want to call the default route for a keypress as if it
    // had gone to the window as normal, use:
    OnChar( (UINT)psMSG->wParam,(UINT)LOWORD(psMSG->lParam),
    (UINT)HIWORD(psMSG->lParam));

    // Or, if you want to know when the key was dealt with (i.e.,
    // does not get passed on to rest of command chain if dealt with),
    // use:
    bDealtWith = MyKeyPreview( (UINT)psMSG->wParam);
    // This routine would return TRUE if it handled the key and should
    // NOT be passed on, or FALSE if it ignored the key and should let
    // the system handle it as normal.
    }

    return bDealtWith ;
    }


    ---

    You may also want to trap WM_SYSCHAR for <Alt>key combos, and also WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP to trap non-ASCII-generating keys.

    Does this help?


    --
    Jason Teagle
    [email protected]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured