No announcement yet.

WM_CHAR revisited

  • Filter
  • Time
  • Show
Clear All
new posts

  • WM_CHAR revisited

    Hiya all.

    I need to trap the ENTER key from any control on a dialog, I have
    just searched for WM_CHAR in the forums and found a few ideas
    but I am confused. It appears the most common reply is to
    sub class a control.
    The follwoing is from the win32 help file..

    The WM_CHAR message is posted to the window with the keyboard
    focus when a WM_KEYDOWN message is translated by the
    TranslateMessage function. WM_CHAR contains the character code
    of the key that was pressed.

    This leads me to believe that that I should be able to
    trap the WM_CHAR message in the dialogs callback with something

    Select Case CBMSG
    Case %WM_CHAR
    SendMessage hDlg, %WM_CHAR,%VK_TAB,0
    Function = 0 'stop the enter key going further
    End IF
    End Select

    It was this easy in VB3, am I doing something wrong in PB. ?
    I shouldnt have to subclass just to trap a key.

    Please Help.


  • #2
    Neil --
    PB uses Windows's dialog engine.
    By default, the system handles all keyboard input to the control and interprets certain types of keyboard input as dialog box navigation keys (enter, tab and so on).
    It's enough comfortable for most situations.

    If you want to override default behavior, you can:
    a) To use Dialog Show Modeless and to write own message loop (w/o IsDialogMessage) - very easy and comfortable
    b) To process WM_GETDLGCODE message, which is sent to the window procedure associated with a control.
    c) To subclass controls.

    E-MAIL: [email protected]


    • #3

      Thanx for your reply (been away for a while).
      Have got it working by trapping it in messge pump, will have
      a look at subclassing though
      Speaking of which, I was just playing with your ddt dialog
      scrolling code; kewl! Just gotta work out how to make it scroll
      as a child window (or dialog).



      [This message has been edited by Neil Hosgood (edited July 13, 2001).]