No announcement yet.

Need a 'keypreview' for DDT..

  • Filter
  • Time
  • Show
Clear All
new posts

  • Need a 'keypreview' for DDT..

    Currently, i'm hooking all of my controls on a DDT dialog.
    I just want to interact with page up and down (and other keys).

    Is there a better way to determine these keypresses, even while to focus is on different controls.
    Maybe i need a (global)hook for this instance?



  • #2
    Your window procedure should react to WM_KEYDOWN messages. I'm not sure if subclassing is necessary for that.

    [email protected]


    • #3
      DDT seems to swallow WM_KEYDOWN somehow. I tested some code a while ago and
      found that creating a timer event and trapping the keys I wanted to check
      with GetKeyState() in the dialog's Callback procedure and %WM_TIMER could
      do it. I'm sure there are better ways, but that's one way of doing it..


      • #4
        For catching the Enter key, you need to search the PB archives. Particularly look for Lance's kind and informative posts. One of his posts points us to . There you can search on "subclass" and "superclass". Here's some pages that can help explain the details of what subclass and superclass means:

        Sub-Classing Description
        Sub-Classing Example

        SetWindowLong() -> SetWindowLongPtr()
        GetWindowLong() ->GetWindowLongPtr()


        Generally, most of the PB examples use subClassing. The code in the archives should help you (us) solve many of the related problems.

        The bottom line is that you can not use an unmodified "Control Add" textbox to catch the Enter key. You have to sneakily redirect (subclass) its processing routine (WndProc) to yours. Then you can analyze all the keys.

        I posted the above links to help any one wanting the official Microsoft line on this. It's all C/C++ oriented. But the best examples are in the archives. Plus, reading all the code gives us practice. There is at least one example of superclassing also. This is where you define a new class using the old one as a template. But most people in the archives used sub-classing. It appears more convenient for "quickie" filters where there are not a lot of controls involved. Otherwise you SuperClassing.

        I could not find the topic "sub class" in Petzold. But I'm sure it's there. I just couldn't find it quickly in his 1000's of pages.



        • #5
          Oh, I forgot to add that the official Microsoft line says that

          SetWindowLong() is being replaced by SetWindowLongPtr() in 64 bit Windows

          GetWindowLong() is being replaced by GetWindowLongPtr() in 64 bit Windows

          That's why they're listed in the post. I'll be using the non-Ptr version for awhile, as that's what Lance used in his examples.



          • #6
            Guys --
            what do you think about this method ?

            ' Based on ideas of Patrice Terrier & Lance Edmonds
            #Compile Exe
            #Register None
            DefLng A-Z
            #Include "Win32Api.Inc"
            Global Stop&
            CallBack Function hDlg_CB
               Select Case CbMsg
                  Case %WM_DESTROY: Stop = 1
               End Select
            End Function
            Function PbMain()
               Local Msg  As tagMsg
               Dialog New 0 ,"SubClass ?", 0, 0, 200, 100, %DS_CENTER Or %WS_SYSMENU To hDlg
               Control Add Label,  hDlg, 101, "Label", 10, 5, 170, 12
               Control Add TextBox,  hDlg, 201, "Edit control-1", 10, 25, 170, 12
               Control Add TextBox,  hDlg, 202, "Edit control-2", 10, 45, 170, 12
               Control Add ComboBox, hDlg, 301,, 10, 65, 170, 100, %CBS_DROPDOWNLIST Or %WS_TABSTOP
               ComboBox Add hDlg, 301, "Combo box": ComboBox Select hDlg, 301, 1
               Dialog Show Modeless hDlg Call hDlg_CB
               While GetMessage(Msg, %NULL, 0, 0)
                  Select Case Msg.message
                     Case %WM_KEYDOWN: SetWindowText hDlg, "WM_KEYDOWN / " + Time$
                     Case %WM_KEYUP  : SetWindowText hDlg, "WM_KEYUP / " + Time$
                     Case %WM_CHAR   : SetWindowText hDlg, "WM_KEYCHAR / " + Time$
                  End Select
                  If IsDialogMessage(hDlg, Msg) = %FALSE Then  ' Don't touch Tab
                     TranslateMessage Msg
                     DispatchMessage Msg
                  End If
                  If Stop <> 0 Then Exit Do
               MsgBox "Ok"
            End Function


            • #7
              Hmmmm... I'll ask R&D about this, but (although I'm not privvy to how the DDT engine works internally) I would suspect that the DDT engine may "misbehave" as you are effectively intercepting the messages in the thread's message queue, and removing them from the DIALOG DOEVENTS loop... whether it may introduce subtle bugs into your application is the big question.

              I'll post any info R&D can tell me.

              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              mailto:[email protected]


              • #8
                I hope so, for now i can deal with subclassing the controls on this particular dialog.
                But it isn't something what should be used for other stuff.
                It involves more code/bugs etc..



                • #9
                  This example looks nice and simple. Did anyone determine whether or not it was reliable?

                  The links on this thread all go to "page not found", does anyone have current links?

                  Eftheon, Inc.
                  Tony Snyder


                  • #10
                    I did not re-read to investigate why we did so difficult..

                    Enter and cancel:
                        Case %WM_COMMAND
                            Select Case CbCtl
                            Case %IDOK
                                Select Case CbCtlMsg
                                Case %BN_CLICKED
                                    ' User hits Enter
                                End Select
                            Case %IDCANCEL
                                Select Case CbCtlMsg
                                Case %BN_CLICKED
                                    ' User hits escape
                                End Select
                            End Select