Announcement

Collapse
No announcement yet.

Pressing button or key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pressing button or key

    In Visual BASIC, I can use this code:

    Command1.Value = True

    to have the program "press" the button for me. I can't find similar code in PB/DLL to press a button or a key for me. Can you give me example code to press buttons and keys? Jeffrey.

  • #2
    Deleted!

    [This message has been edited by Adam Ritchie (edited April 08, 2000).]

    Comment


    • #3
      Jeffrey,

      Why not download some of Dave Navaro's *.inc files from the ftp site? For example in Button32.inc you can find the following:-

      '==============================================================================
      '
      ' Button encapsulation for PB/DLL 5.0
      ' Copyright (c) 1997,98 by PowerBASIC, Inc.
      '
      ' Notes:
      '
      ' * Assumes that WIN32API.INC will also be included into your code.
      ' * Success = 0 if an operation is successful, otherwise a non-zero value
      ' is returned.
      ' * Many items marked as "Win95 only" will also work in WinNT 4.0 or later.
      '
      '==============================================================================

      '------------------------------------------------------------------------------
      ' TITLE: BmClick
      ' DESC: Simulate the user clicking a button. This causes the button to
      ' receive a %WM_LBUTTONDOWN and a %WM_LBUTTONUP message, and the
      ' button's parent window to receive a %BN_CLICKED notification message.
      ' SYNTAX: BmClick hButton
      '
      SUB BmClick(BYVAL hButton AS LONG)
      SendMessage hButton, %BM_CLICK, 0, 0
      END SUB

      These files are all great study material. You can then see how
      the code may need changes to use ddt - Control send etc.

      Regards,

      David

      ------------------

      Comment


      • #4
        Adam, Thanks for helping me. In Visual BASIC, I can write code like this:

        If char01$="1" and Command1.Enabled=True then Command1.Value=True

        In PB/DLL, I would write code like this:

        If char01$="1" then control send hdlg,100,%bm_click,0,0

        but there is no function in PB/DLL that checks to see if a control is enabled before using control send. Jeffrey.

        ------------------

        Comment


        • #5
          Jeffrey --
          When you talk about PB, it's necessary to understand that it's possible to do ALL, because you can operate with "row" API.
          Another question - comfortable or not, have you enough knowledge or not.
          For example, you can test WS_DISABLED bit in window's style.
          (there are also another ways)

          Code:
          #Compile Exe
          #Register None
          #Dim All
          #Include "win32Api.inc"
          CallBack Function Cb
             Select Case CbMsg
                Case %WM_COMMAND
                   If CbCtl = 101 Then
                      If IsTrue(GetWindowLong(GetDlgItem(CbHndl, 102), %GWL_STYLE) And %WS_DISABLED) Then _
                          Control Enable CbHndl, 102 Else Control Disable CbHndl, 102
                   End If
             End Select
          End Function
          Function PbMain
            Local hdlg As Long
            Dialog New 0,"Test",,, 200, 70, %ws_sysmenu To hdlg
            Control Add Button,  hdlg,101, "Disable/Enable Second Button", 10, 10, 180, 15
            Control Add Button,  hdlg,102, "Second Button", 10, 30, 180, 15
            Dialog Show Modal hdlg Call Cb
          End Function
          ------------------

          Comment


          • #6
            Hello,

            I'll just pass on the same favor I was given when I first showed up here... Do some reading

            Check out the FAQ forum for some suggested books.

            Colin Schmidt

            ------------------
            Colin Schmidt & James Duffy, Praxis Enterprises, Canada

            Comment


            • #7
              Semen, Thanks for the code. Visual BASIC is different from PB/DLL because in Visual BASIC, you draw controls on forms and write code for controls. In PB/DLL, you have to write code to draw controls and write code for them almost the same way that you use C++ compiler to write code. I have "Programming Windows Fifth Edition" book written by Charles Petzold and "Visual BASIC Programmer's Guide to the WIN32 API" book written by Dan Appleman. There is another book on WIN32 API recommended by Lance but I forgot its title and I think that Amazon book store doesn't have it. Jeffrey.

              ------------------

              Comment


              • #8
                Jeffrey --
                I am also was (and is) VB programmer too and don't know C.
                I'm almost sure that at least 50% of PB customers use VB also.
                So I exactly imagine your API's knowledge at this moment.

                To write really big PB's apps is enough difficult.
                But VB is fat and slowly. So, for "middle" apps PB is excellent tool.
                I also have "Visual BASIC Programmer's Guide to the WIN32 API".
                (now I understand that this is "empty" book).
                As rule, Lance recommends Petzold's "Programming Windows" (for beginners) and Rector/Newcomer "Win32 Programming" (more detail description).
                I have both (note, ordered in Amazon). Petzold's book is almost new. But I can't to say the same about Rector/Newcomer.
                Unfortunatelly, even such fat books sometimes is not enough

                ------------------

                Comment


                • #9
                  Semen, I tried your code and it worked. There is %WS_DISABLED but there is no %WS_ENABLED. I thought I would write the callback function like this:

                  callback function hdlg02cb
                  select case cbmsg
                  case %wm_char
                  if cbwparam=49 then control send hdlg02,100,%bm_click,0,0
                  if cbwparam=50 then control send hdlg02,101,%bm_click,0,0
                  if cbwparam=51 then control send hdlg02,102,%bm_click,0,0
                  case %wm_destroy
                  call postquitmessage(0)
                  end select
                  end function

                  But when I tried to press the "1" key, my computer beeped but nothing happened. Also, I have two callback functions for push buttons labeled "Exit". When I press one of the buttons, the program is supposed to exit but I can't put postquitmessage there because it is in the callback function hdlg02cb. Jeffrey.

                  ------------------

                  Comment


                  • #10
                    You can use IsWindowEnabled to test the enabled state of a window, but I must question why you'd want to do this - it would be easier using a STATIC or GLOBAL variable in your code, which has the Handle or ID of the currently enabled button.

                    Another way if you want one button pressed at a time is to use Radio Buttons (Option buttons in VB) as that is much easier.

                    ------------------
                    Kev G Peel
                    KGP Software
                    Bridgwater, UK.
                    mailto:[email protected][email protected]</A>

                    Comment


                    • #11
                      Semen, I tried this code but it didn't work:

                      Code:
                      callback function hdlg02cb
                        select case cbmsg
                          case %wm_keydown
                            if cbwparam=%vk_f1 then textbox05("Key F1 Pressed")
                          case %wm_destroy
                            call deleteobject(hfont)
                            call postquitmessage(0)
                        end select
                      end function
                      If the code works and I press the F1 key, I should get "Key F1 Pressed" message. Nothing happens when I press the F1 key. Jeffrey.


                      ------------------

                      Comment


                      • #12
                        Deleted!


                        [This message has been edited by Adam Ritchie (edited April 08, 2000).]

                        Comment


                        • #13
                          Jeffrey, there should be no need to use PostQuitMessage() with DDT... use the DIALOG END CBHNDL statement instead, which causes your code to continue on from the DIALOG SHOW MODAL statement. From that point you can drop out of PBMAIN or whatever action is necessary. Using PostQuitMessage() will cause a conventional message-loop to fall-through, but your dialog is not destroyed until app termnination occurs. While PostQuitMessage() may 'work', it's not the most ideal way to terminate a dialog-based application.

                          Also please note that %WM_CHAR is not a message that is sent to a DDT dialog callback. To capture %WM_CHAR you need to use Semen's 'experimental' message-loop code with a MODELESS dialog, as you and Semen have discussed in another thread here.

                          To summarize: When a keystroke is processed by a message loop, the TranslateMessage() converts %WM_KEYDOWN/%WM_KEYUP messages into %WM_CHAR and then DispatchMessage() send that message to the control with focus if there is one - if there is no control with focus, then Windows "swallows" the message and beeps at you to tell you the keypress was "lost or invalid".

                          This means that a %WM_CHAR messages are only going to be received by controls' window procedures (ie, Windows itself), which in turn *may* process such messages and dispatch a consequential message to [your] button callback (ie, %BN_CLICKED, etc). In other words, raw keyboard messages go everywhere except to your callback. To grab these messages (without snatching them in the message loop), you have to subclass each and every control on your dialog, and as noted above, only if one of these controls has focus.

                          If we compare this behavior with what VB presents, you'll get some idea of what hoops VB has to go through, and hence why it creates slow/bloated applications, with little regard to whether you want to use such features a "key preview". Conversely, PB has no such manditory overhead, which means you have to get "down and dirty" with the API. These techniques are necessary because of the way Windows actually works at the API level - VB hides most of this from you because it uses a collection of custom controls (superclassed standard controls) so that VB can manipulate messages into it object properties and methods.

                          Finally, for the type of application you are writing (where you want to be able to use the keyboard interface in a non-standard way), you may just be better off writing the application as a 'standard window' based app (use CreateWindow(), etc), rather than by using a dialog. You can certainly get the job done either way with PB - it's just a matter of how you want to write the code.

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

                          Comment


                          • #14
                            Jeffrey
                            In my sample
                            1) IsTrue(GetWindowLong(GetDlgItem(CbHndl, 102), %GWL_STYLE) And %WS_DISABLED) - means DISABLED
                            and is equal
                            IsFalse(IsWindowEnabled(GetWindowLong(GetDlgItem(CbHndl, 102))))

                            IsFalse(GetWindowLong(GetDlgItem(CbHndl, 102), %GWL_STYLE) And %WS_DISABLED) - means ENABLED
                            and is equal
                            IsWindowEnabled(GetWindowLong(GetDlgItem(CbHndl, 102)))

                            There is a lot of "duplicate" functions in API.
                            IsWindowEnabled - sure - tests the same bit in GWL_STYLE.

                            2) I remember your big code.
                            Try to describe your task by words, perhaps, we'll offer better interface.
                            I write programs, which calculates railway's tariff for cargoes.
                            Network has about 9000 stations.
                            Customers type "Departure", "Destination" and - only if they what to change "default" way - one or some "via" stations.
                            For example, "default way" from west part of Russia to Turkmenia is through Kazakhstan (by land), but customers could be interesting to use Azerbaidjan-Turkmenian ferry.

                            It seems to me that you need something the same.
                            Much comfortable to make Departure/Destination/Via fields as Listbox, not Textbox.




                            ------------------

                            Comment


                            • #15
                              Adam, I gave up on the project because I can't get PB/DLL programs with DDT controls to process keystrokes. Lance told me that I have to use WIN32API to create dialogs and controls that process keystrokes. I am thinking of using PB/DLL to enhance Visual BASIC programs. Jeffrey.


                              ------------------

                              Comment


                              • #16
                                Lance, I gave up on the project. I am thinking of using PB/DLL to enhance Visual BASIC programs. I tried to log into this web site at about 7:30 AM Eastern Time but I got a message saying that the site was not found. Jeffrey.

                                ------------------

                                Comment


                                • #17
                                  Semen, I gave up on the project. I wrote a version of my program that uses WIN32API calls to create dialogs and controls. I am thinking of using PB/DLL to enhance Visual BASIC programs. Jeffrey.

                                  ------------------

                                  Comment


                                  • #18
                                    Deleted!

                                    [This message has been edited by Adam Ritchie (edited April 08, 2000).]

                                    Comment


                                    • #19
                                      Adam, My E-Mail address is 70033,[email protected] I wish that I can scan the whole "Programming Windows Fifth Edition" book into my brain. I checked out "WIN32 Programming" book on the publisher's web site and I am not sure about buying it. Jeffrey.

                                      ------------------

                                      Comment


                                      • #20
                                        Deleted!

                                        [This message has been edited by Adam Ritchie (edited April 08, 2000).]

                                        Comment

                                        Working...
                                        X