Announcement

Collapse
No announcement yet.

Toolbar Button Callback Function?

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

  • Toolbar Button Callback Function?

    I know how to handle a button click on a toolbar button in the dialog callback but how do you define a toolbar (buttons) to have it's/their own callback(s).
    I want to create an include file that will create a toolbar, manipulate it etc. So far I've got everthing neatly tucked away in a separate include except the WM_COMMAND stuff. It's still in the WM_COMMAND section of my DIALOG call back.

    Bob Mechler

  • #2
    except the WM_COMMAND stuff. It's still in the WM_COMMAND section of my DIALOG call back
    ?????

    That's what toolbar buttons do, they send WM_COMMAND to the owner window.

    If you are talking about DDT syntax with its support for the ability to specify a distinct callback procedure for each control, I 'suppose' you could Create the toolbar ("CONTROL ADD "msctls_toolbar32") and do a series of CONTROL ADD BUTTON specifying the toolbar as the parent window and naming the procedure in that line.

    Except I don't think that will get WM_COMMAND to our main window procedure. Or maybe it will, that might be part of the default window procedure for the $TOOLBAR_CLASS.

    You might find it a little easier to just CALL Something (CBHNDL, CBMSG, CBWPARAM, CBLPARAM) when you get WM_COMMAND when CBCTL can be identified as a "toolbar item." That will get the code in one separate place, it's just that you can't catch a DIRECT flight, you have to change planes.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Here is what I have encapsulated so far. I guess I could use the following under %WM_COMMAND in my main dialog callback to keep it cleaner.

      #IF %def(%ID_ToolBar)
      #INCLUDE "TBBTClicks.inc"
      #ENDIF
      Code:
      %ToolButtons  = 13
      %ID_ToolBar   = 10000
      %ID_TBAdd     = 101
      %ID_TBChange  = 102
      %ID_TBDelete  = 103
      %ID_TBInquire = 104
      %ID_TBList    = 105
      %ID_TBExit    = 106
      %ID_TBSAVE    = 107
      CALLBACK FUNCTION cbTBMaint
        MSGBOX("Call back doesn't work")
      END FUNCTION 
      FUNCTION CreateTBMaint (BYVAL hParent AS DWORD) AS DWORD
        ' Toolbar & Print Preview equates
        LOCAL Tbb()      AS TBBUTTON
        LOCAL Tabm       AS TBADDBITMAP
        LOCAL ToolHeight AS LONG
        DIM Tbb(0:%ToolButtons - 1) AS LOCAL TBBUTTON
        ' Toolbar
        ' add Toolbar control
        CONTROL ADD "TOOLBARWINDOW32", hParent, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_CHILD OR %WS_BORDER OR %WS_VISIBLE OR %CCS_TOP OR %TBSTYLE_TOOLTIPS OR %TB_AUTOSIZE CALL cbTBMaint
      
        ' Init Tbb array.
        FOR x& = 0 TO %ToolButtons - 1
            ' Set the initial states for each button
            Tbb(x&).iBitmap = 0
            Tbb(x&).idCommand = 0
            Tbb(x&).fsState = %TBSTATE_ENABLED
            Tbb(x&).fsStyle = %TBSTYLE_AUTOSIZE
            Tbb(x&).dwData = 0
            Tbb(x&).iString = 0
            SELECT CASE x&
                CASE 0,2,4,6,8,10
                    ' Gap creation buttons.
                    Tbb(x&).iBitmap = 15
                    Tbb(x&).fsState = 0'%TBSTATE_ENABLED
                    Tbb(x&).fsStyle = %TBSTYLE_AUTOSIZE
                    'Tbb(x&).fsStyle = %TBSTYLE_SEP 'original
                    Tbb(x&).iString = 6
                CASE 1&
                    Tbb(x&).iBitmap = %STD_FILENEW
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBAdd
                    Tbb(x&).iString = 0
                CASE 3&
                    Tbb(x&).iBitmap = %STD_FILEOPEN
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBChange
                    Tbb(x&).iString = 1
                CASE 5&
                    Tbb(x&).iBitmap = %STD_DELETE
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBDelete
                    Tbb(x&).iString = 2
                    Tbb(x&).fsState = %TBSTATE_ENABLED 'or 0 if disabled
                CASE 7&
                    Tbb(x&).iBitmap = %STD_FIND
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBInquire
                    Tbb(x&).iString = 3
                CASE 9&
                    Tbb(x&).iBitmap = %STD_PRINTPRE
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBList
                    Tbb(x&).iString = 4
                CASE 11&
                    Tbb(x&).iBitmap = %STD_REDOW
                    Tbb(x&).fsState = %TBSTATE_ENABLED
                    Tbb(x&).idCommand = %ID_TBExit
                    Tbb(x&).iString = 5
                CASE 12&
                    Tbb(x&).iBitmap = %STD_FILESAVE
                    Tbb(x&).fsState = %TBSTATE_HIDDEN
                    Tbb(x&).idCommand = %ID_TBSAVE
                    Tbb(x&).iString = 7
        
           END SELECT
        NEXT x&
        CONTROL SEND hParent, %ID_TOOLBAR, %WM_SETFONT,hFontText,0
        
        ' Set the imge list for the TB
        Tabm.hInst = %HINST_COMMCTRL    ' Use GetModuleHandle(BYVAL %NULL) if using a bitmap in a linked resource file
        Tabm.nID = %IDB_STD_SMALL_COLOR ' Use the ID of the bitmap image, ie, %ID_TOOLBAR
        CONTROL SEND hParent, %ID_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
        
        ' Set the buttons
        CONTROL SEND hParent, %ID_TOOLBAR, %TB_BUTTONSTRUCTSIZE, SIZEOF(Tbb(0)), 0
        CONTROL SEND hParent, %ID_TOOLBAR, %TB_ADDBUTTONS, %ToolButtons, VARPTR(Tbb(0))
        
        ' Add text descriptions if hi-res screen
        IF GetSystemMetrics(%SM_CXFULLSCREEN) =>1024 THEN
            a$ =" Add record " & $NUL &  "Find/Change " & $NUL & "Find/Delete" & $NUL &  "Find/Review " & $NUL & "List Records" & $NUL &   " Main Menu  " & $NUL & "    " & $NUL & " Save/Reset" & $NUL & $NUL
            CONTROL SEND hParent, %ID_TOOLBAR, %TB_ADDSTRING, 0, STRPTR(a$)
        END IF
        
        ' Force TB to initially resize before we display the dialog
        CONTROL SEND hParent, %ID_TOOLBAR, %WM_SIZE, 0, 0
        
        ' Add Hover effect...
        hWndTB& = GetDlgItem(hParent, %ID_TOOLBAR)
        TBstyle& = SendMessage (hWndTB&, %TB_GETSTYLE, 0&, 0&)
        IF ISFALSE(TBstyle& AND %TBSTYLE_FLAT) THEN
             CALL SendMessage( hWndTB&, %TB_SETSTYLE, 0, (TBstyle& OR %TBSTYLE_FLAT) )
        END IF
         ' Toolbar control
      END FUNCTION 
      FUNCTION ResetTBMaint (BYVAL hParent AS DWORD) AS DWORD
        CONTROL HANDLE hParent,%ID_TOOLBAR TO tbhandl&
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBADD,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBChange,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBDelete,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBInquire,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBList,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBExit,MAKLNG(%TBSTATE_ENABLED,0)
        SendMessage tbhandl&, %TB_SETSTATE, %ID_TBSave,MAKLNG(%TBSTATE_HIDDEN,0)
      END FUNCTION
      This toolbar I plan to call from every maintenance program that has the same style of operation. Write once, use many so to speak.

      Bob Mechler
      Last edited by BOB MECHLER; 30 Nov 2007, 02:13 PM. Reason: Fix error

      Comment

      Working...
      X