Announcement

Collapse
No announcement yet.

Simulate button click

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

  • Simulate button click

    This is a Windows documentation problem, and although I ordeed
    the book Lance and Dave recommended, it has not yet arrived.
    (They shipped the wrong book and took a week to acknowledge
    my e-mails - still no book).

    I'm trying to use a separate button to cause a Combobox to
    show its list. I've tried a lot of things, the latest being.
    Is this easy to do and if so what message should button 200
    send to cause button 201 to drop its list?

    $COMPILE EXE
    $INCLUDE "WIN32API.INC"
    CALLBACK FUNCTION MainLoop()
    SELECT CASE CBMSG
    CASE %WM_COMMAND
    SELECT CASE LOWRD(CBWPARAM)
    CASE %IDOK
    SELECT CASE HIWRD(CBWPARAM)
    CASE %BN_CLICKED
    DestroyWindow CBHNDL:PostQuitMessage 0
    END SELECT
    CASE 200
    DIALOG SEND CBHNDL, %WM_COMMAND, %CB_SHOWDROPDOWN*2^16+201&, -1&
    CASE 201
    END SELECT
    END SELECT
    END FUNCTION

    FUNCTION PBMAIN() AS LONG
    LOCAL hDlg AS LONG
    DIM DropDown(1:10) AS STRING
    LOCAL i AS LONG:FOR i=1 TO 10ropDown(i)="Item "+STR$(i):NEXT i
    DIALOG NEW 0,"Testing",,,320,240,%WS_CAPTION OR %WS_SYSMENU,0 TO hDlg
    CONTROL ADD BUTTON,hDlg,200,"Push for DropDown",120,5+2*16,80,14,%BS_LEFT
    CONTROL ADD COMBOBOX,hDlg,201,DropDown(),200,5+2*16+1,40,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
    COMBOBOX SELECT hDlg,201,2
    DIALOG SHOW MODAL hDlg, CALL MainLoop
    END FUNCTION

  • #2
    Joe --
    try this
    Code:
    $Compile Exe
    $Include "WIN32API.INC"
    
    CallBack Function But_CB()
       Control Send CbHndl, 201, %CB_SHOWDROPDOWN, %True, 0
    End Function
    
    Function PbMain() As Long
    Local hDlg As Long
    Dim DropDown(1:10) As String
    Local i As Long:For i=1 To 10:DropDown(i)="Item "+Format$(i, "##"):Next i
    Dialog New 0,"Testing",,,320,240,%WS_CAPTION Or %WS_SYSMENU,0 To hDlg
    Control Add Button,hDlg,200,"Push for DropDown",120,5+2*16,80,14,%BS_LEFT Call But_CB
    Control Add ComboBox, hDlg,201,DropDown(), 200, 5+2*16+1, 40, 11*10
    ComboBox Select hDlg,201, 2
    Dialog Show Modal hDlg
    End Function
    [This message has been edited by Semen Matusovski (edited January 26, 2000).]

    Comment


    • #3
      Semen, almost perfect. It works when using the mouse to click on a
      button. However when using ALT+Key to select a box, only the dropdown
      occurs. The focus is still on the previous Combobox, so when the cursor
      keys are used to select the item, the previous box scrolls, not the one
      that was forced to drop down. Curious that ALT+Key works differently
      than just clicking the button.
      -------------------------------------------------------------------------
      $COMPILE EXE
      $INCLUDE "WIN32API.INC"
      GLOBAL hDlg AS LONG
      GLOBAL Speeds() AS STRING

      CALLBACK FUNCTION DD()
      CONTROL SEND CBHNDL,CBCTL+1,%CB_SHOWDROPDOWN,%True,0
      COMBOBOX SELECT CBHNDL,CBCTL+1,1
      END FUNCTION

      FUNCTION PBMAIN() AS LONG
      DIM Speeds(5:49) AS STRING
      LOCAL i AS LONG
      FOR i=5 TO 49:speeds(i)=" "+RIGHT$(STR$(100+i),2):NEXT
      DIALOG NEW 0,"Test ALT Key Selection",,,320,240,%WS_CAPTION OR %WS_SYSMENU,0 TO hDlg
      CONTROL ADD BUTTON,hDlg,200,"&1 Button",100,5+1*16,80-31,14,%BS_LEFT CALL DD()
      CONTROL ADD COMBOBOX,hDlg,201,Speeds(),100+80-30,5+1*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
      CONTROL ADD BUTTON,hDlg,202,"&2 Button",100,5+2*16,80-31,14,%BS_LEFT CALL DD()
      CONTROL ADD COMBOBOX,hDlg,203,Speeds(),100+80-30,5+2*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
      CONTROL ADD BUTTON,hDlg,204,"&3 Button",100,5+3*16,80-31,14,%BS_LEFT CALL DD()
      CONTROL ADD COMBOBOX,hDlg,205,Speeds(),100+80-30,5+3*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
      COMBOBOX SELECT hDlg,201,1
      COMBOBOX SELECT hDlg,203,5
      COMBOBOX SELECT hDlg,205,11
      DIALOG SHOW MODAL hDlg
      END FUNCTION

      Comment


      • #4
        From Dave's sample files in the code forum:-

        '------------------------------------------------------------------------------
        ' 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

        I recommend you copy all the example files.

        Comment


        • #5
          Thanks David. I'm not sure the Dave's function applies to my COMBOBOX
          problem. Still I did copy it and a few of the others. Played with it
          a little, but it did not seem apply.

          Semen's code almost worked and I played with it a little more and found
          that CONTROL SET FOCUS fixes the keyboard input (ALT+Key)issue. The
          code is now working, but I remain concerned and would like to learn more
          about the sequence of windows messages and parameters. What I'm doing
          now is like feeling around on the outside of an elepahnt without knowing
          which end I'm at. I need to learn a little more about the theory of
          elephants, to avoid unexpected events.
          -----------------------------------------------------------------------
          The apparently working code is
          -----------------------------------------------------------------------
          $COMPILE EXE
          $INCLUDE "WIN32API.INC"
          GLOBAL hDlg AS LONG
          GLOBAL Speeds() AS STRING

          CALLBACK FUNCTION DD()
          CONTROL SEND CBHNDL,CBCTL+1,%CB_SHOWDROPDOWN,%True,0
          CONTROL SET FOCUS CBHNDL,CBCTL+1
          END FUNCTION

          FUNCTION PBMAIN() AS LONG
          DIM Speeds(5:49) AS STRING
          LOCAL i AS LONG
          FOR i=5 TO 49:speeds(i)=" "+RIGHT$(STR$(100+i),2):NEXT
          DIALOG NEW 0,"Test ALT Key Selection",,,320,240,%WS_CAPTION OR %WS_SYSMENU,0 TO hDlg
          CONTROL ADD BUTTON,hDlg,200,"&1 Button",100,5+1*16,80-31,14,%BS_LEFT CALL DD()
          CONTROL ADD COMBOBOX,hDlg,201,Speeds(),100+80-30,5+1*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
          CONTROL ADD BUTTON,hDlg,202,"&2 Button",100,5+2*16,80-31,14,%BS_LEFT CALL DD()
          CONTROL ADD COMBOBOX,hDlg,203,Speeds(),100+80-30,5+2*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
          CONTROL ADD BUTTON,hDlg,204,"&3 Button",100,5+3*16,80-31,14,%BS_LEFT CALL DD()
          CONTROL ADD COMBOBOX,hDlg,205,Speeds(),100+80-30,5+3*16+1,30,11*10,%CBS_DROPDOWNLIST+%WS_TABSTOP
          COMBOBOX SELECT hDlg,201,1
          COMBOBOX SELECT hDlg,203,5
          COMBOBOX SELECT hDlg,205,11
          DIALOG SHOW MODAL hDlg
          END FUNCTION

          Comment

          Working...
          X