Announcement

Collapse
No announcement yet.

Sending %BM_CLICK (again)

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

  • John Tate
    replied
    I have been using code like the sample below for several years. Control Send and Control Post to the button works for me. I use it to click a button when double clicking on a selection in a listbox, for example.
    It must be part of the Case %WM_Command.

    John Tate

    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1 =  101
    %IDC_BUTTON1 = 1001
    %IDC_BUTTON2 = 1002
    %IDCANCEL    =    2
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
           CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_BUTTON1
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                           ' CONTROL SEND CBHNDL, %IDC_BUTTON2, %BM_CLICK,0,0
                            CONTROL POST CBHNDL, %IDC_BUTTON2, %BM_CLICK,0,0
                        END IF
    
                    CASE %IDC_BUTTON2
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            MSGBOX "BUTTON 2 PUSHED"
                        END IF
    
                    CASE %IDCANCEL
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            DIALOG END CBHNDL, 0
                        END IF
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW hParent, "TEST OF PROGRAMATICALLY PUSHING BUTTON", 70, 70, _
            287, 206, TO hDlg
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 45, 75, 50, 15
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Button2", 150, 75, 50, 15
        CONTROL ADD BUTTON, hDlg, %IDCANCEL, "EXIT", 115, 155, 50, 15
    #PBFORMS END DIALOG
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------

    Leave a comment:


  • Scott Turchin
    replied
    That workis, thanks!, although I never would have figured that out! (The Mak part!)


    Tx!

    Leave a comment:


  • Kev Peel
    replied
    Only works for buttons. For menus and other controls, use:

    Code:
    DIALOG SEND CbHndl, %WM_COMMAND, MAK(DWORD, %IDM_SAVE, %BN_CLICKED), 0

    Leave a comment:


  • Scott Turchin
    started a topic Sending %BM_CLICK (again)

    Sending %BM_CLICK (again)

    I thought I had this working, maybe I can't do it?

    Problem is- it's never received by the %IDM_SAVE, %IDM_SAVEAS....


    Code:
              Case %IDM_CLOSE
                  If IsTrue Need2SaveFlag Then
                      sTmp = "Save Changes before exiting Y/N?"
                      lResult = MessageBox(ByVal CbHndl, ByVal StrPtr(sTmp), ByVal StrPtr(g_szMine), ByVal %MB_ICONWARNING Or %MB_YESNO)
                      If lResult = %IDYES Then
                          Control Send CbHndl,%IDM_SAVE,%BM_CLICK,0,0
                          Function = %TRUE
                      End If
                  End If
    
              Case %IDM_OPEN
                  If IsTrue Need2SaveFlag Then
                      sTmp = "Save Changes before exiting Y/N?"
                      lResult = MessageBox(ByVal CbHndl, ByVal StrPtr(sTmp), ByVal StrPtr(g_szMine), ByVal %MB_ICONWARNING Or %MB_YESNO)
                      If lResult = %IDYES Then
                          Control Send CbHndl,%IDM_SAVE,%BM_CLICK,0,0
                      End If
                  End If
    
    
              Case %IDM_SAVE, %IDM_SAVEAS
                  If LoWrd(CbWParam)= %IDM_SAVE And CbCtlMsg = %BN_CLICKED Then MsgBox "Save programatically pressed"
Working...
X