Announcement

Collapse
No announcement yet.

Toolbar Confusion

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

  • Toolbar Confusion

    According to the PB9 documentation the toolbar parameter may be placed in one of the following four locations:
    %CCS_TOP
    The ToolBar is placed at the top of the dialog.

    %CCS_BOTTOM
    The ToolBar is placed at the bottom of the dialog.

    %CCS_LEFT
    The ToolBar is placed on the left side of the dialog.

    %CCS_RIGHT
    The ToolBar is placed on the right side of the dialog.


    Code:
    CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR [B]%CCS_TOP [/B]OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0
    I tried each of the position parameters with the following results:
    %CCS_TOP = Worked correctly.

    %CCS_BOTTOM = Toolbar disappeared.
    Expected: Toolbar to move to the bottom of the dialog.

    %CCS_LEFT = All icons save the home icon vanished.
    Expected: Toolbar icons to be presented vertically on the left side of the dialog.

    %CCS_RIGHT = The home icon moved to the upper right corner, all other icons vanished.
    Expected: Toolbar icons to be presented vertically on the right side of the dialog.

    I changed only the default %CCS_TOP parameter. Are there additional parameters that have to be changed in order to relocate the toolbar?

  • #2
    Extra styles for vertical toolbars

    %CCS_BOTTOM - Need to adjust the position of the Listview in %WS_SIZE (to avoid putting it on top of the Toolbar)

    %CCS_LEFT, %CCS_RIGHT - Need to include %CCS_VERT in the Toolbar style and add %TBSTATE_WRAP to each of the Buttons eg.
    Code:
      Toolbar Set State  hDlg, %ID_TOOLBAR, ByCmd %ID_BTN_HOME,  %tbstate_wrap Or %tbstate_enabled
      Toolbar Set State  hDlg, %ID_TOOLBAR, ByCmd %ID_BTN_PRINT, %tbstate_wrap Or %tbstate_enabled
      Toolbar Set State  hDlg, %ID_TOOLBAR, ByCmd %ID_BTN_PROP,  %tbstate_wrap Or %tbstate_enabled
    Note you will have to add this style whenever the state of a button is changed eg.
    Code:
    Toolbar Set State  hDlg, %ID_TOOLBAR, ByCmd %ID_BTN_HOME,  %tbstate_disabled Or %tbstate_wrap
    Rgds, Dave

    Comment


    • #3
      WM_SIZE processing on your dialog procedure....
      Also, the toolbar window procedure automatically adjusts the size of the toolbar whenever it receives a WM_SIZE or TB_AUTOSIZE message. An application should send either of these messages whenever the size of the parent window changes or after sending a message that requires adjusting the size of the toolbar—for example, a TB_SETBUTTONSIZE message. [Italics mine]
      eg
      Code:
          CASE %WM_SIZE
             CONTROL SEND CBHNDL, %ID_TOOLBAR, CBMSG, CBWPARAM, CBLPARAM
      ... "if" your dialog/window is resizeable.

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

      Comment


      • #4
        >>... "if" your dialog/window is resizeable.

        In the PBWin90 sample Toolbar.bas, which is not resizable, the listview is positioned and sized in %WM_SIZE (the message fires when the dialog/window is first drawn).
        Code:
            Case %wm_size
              ' Resize the toolbar and listview control
              Control Get Size Cb.Hndl, %ID_TOOLBAR To w, h
              Control Set Loc  Cb.Hndl, %ID_LISTVIEW, 0, h+1
              w = Lo(Word, Cb.LParam)                    '  width client area in pixels
              h = Hi(Word, Cb.LParam)                    '  height client area in pixels
              Dialog Pixels Cb.Hndl, w, h To Units w, h
              Control Set Size Cb.Hndl, %ID_LISTVIEW, w, h
        In this case, if the Toolbar is given %CCS_BOTTOM style, the location / size of the Listview causes it to hide the toolbar...
        Rgds, Dave

        Comment


        • #5
          The listview (and I think all other controls) you have to resize yourself... but windows will handle toolbars for you if you ask it to.

          Of course I am "assuming " the PB "CONTROL ADD TOOLBAR" statement creates a window of $TOOLBARCLASSNAME and does not pre-empt the Windows' default behavior.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            %CCS_LEFT and %CCS_RIGHT Still Don't Work Correctly

            Thanks for the replies gentlemen.

            When the LISTVIEW specific code is removed, the TOOLBAR is visible when moved to the bottom of the dialog.

            Unfortunately, %CCS_LEFT and %CCS_RIGHT exhibit the same symptom as previously reported. That is only the home icon is visible in the upper left or right corner of the dialog.


            Code:
            '====================================================================
            '
            '   Toolbar.bas example for PowerBASIC for Windows
            '   Copyright (c) 2008 PowerBASIC, Inc.
            '   All Rights Reserved.
            '
            '   Example of using a toolbar, imagelist, and listview
            '
            '====================================================================
            
            #COMPILER PBWIN 9
            #COMPILE EXE
            #DIM ALL
            
            #INCLUDE "commctrl.inc"
            
            ' Add the resource file that contains the icons
            ' and XP manifest
            #RESOURCE "toolbar.pbr"
            
            ' Control equates
            %ID_TOOLBAR   = 1000
            %ID_BTN_HOME  = 1001
            %ID_BTN_PRINT = 1002
            %ID_BTN_PROP  = 1003
            %ID_LISTVIEW  = 1100
            
            ' Application main entry point
            FUNCTION PBMAIN
              LOCAL hDlg AS LONG
              LOCAL hTBNorm AS LONG
              LOCAL hTBHot     AS LONG
              LOCAL hTBDis    AS LONG
              LOCAL hLVImg  AS LONG
            
              ' Create an imagelist for the normal toolbar buttons
              IMAGELIST NEW ICON 32, 32, 32, 4 TO hTBNorm
              IMAGELIST ADD ICON hTBNorm, "#100"            ' Normal Home button
              IMAGELIST ADD ICON hTBNorm, "#101"            ' Normal Print button
              IMAGELIST ADD ICON hTBNorm, "#102"            ' Normal Properties button
            
              ' Create an imagelist for the hot toolbar buttons
              IMAGELIST NEW ICON 32, 32, 32, 4 TO hTBHot
              IMAGELIST ADD ICON hTBHot, "#200"             ' Hot Home button
              IMAGELIST ADD ICON hTBHot, "#201"             ' Hot Print button
              IMAGELIST ADD ICON hTBHot, "#202"             ' Hot Properties button
            
              ' Create an imagelist for the disabled toolbar buttons
              IMAGELIST NEW ICON 32, 32, 32, 4 TO hTBDis
              IMAGELIST ADD ICON hTBDis, "#300"             ' Disabled Home button
              IMAGELIST ADD ICON hTBDis, "#301"             ' Disabled Print button
              IMAGELIST ADD ICON hTBDis, "#302"             ' Disabled Properties button
            
              ' Create an imagelist for the Listview control
            '  IMAGELIST NEW ICON 64, 64, 32, 4 TO hLVImg
            '  IMAGELIST ADD ICON hLVImg, "#400"             ' Monet icon
            '  IMAGELIST ADD ICON hLVImg, "#401"             ' Picaso icon
            '  IMAGELIST ADD ICON hLVImg, "#402"             ' The Cliff and the Porte d'Aval, Étretat
            '  IMAGELIST ADD ICON hLVImg, "#403"             ' Bridge over the Waterlily Pond
            '  IMAGELIST ADD ICON hLVImg, "#404"             ' Waterlilies, Green Reflection, Left Part
            '  IMAGELIST ADD ICON hLVImg, "#405"             ' Impression: soleil levant
            '  IMAGELIST ADD ICON hLVImg, "#406"             ' Houses of Parliament, London, with the sun breaking through the fog
            '  IMAGELIST ADD ICON hLVImg, "#407"             ' Les Demoiselles d'Avignon
            '  IMAGELIST ADD ICON hLVImg, "#408"             ' Weeping Woman
            '  IMAGELIST ADD ICON hLVImg, "#409"             ' The Old Guitar Player
            '  IMAGELIST ADD ICON hLVImg, "#410"             ' The Acrobats
            '  IMAGELIST ADD ICON hLVImg, "#411"             ' Skull and Pitcher
            '  IMAGELIST ADD ICON hLVImg, "#412"             ' The Dream
            
              ' Create the dialog box
              DIALOG NEW 0, "Toolbar, ImageList, and ListView Example", , , 400, 300, _
                %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
                %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
              DIALOG SET COLOR hDlg,  %BLACK, %WHITE
            
              ' Add a toolbar to the dialog box
              CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_TOP OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Works correctly.
              'CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_bottom OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Works correctly.
              'CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_left OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Shows only the Home icon in the upper left corner.
              'CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_right OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Shows only the Home icon in the upper right corner.
              'CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_vert or %ccs_left OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Shows only the Home icon in the upper left corner.
              'CONTROL ADD TOOLBAR,  hDlg, %ID_TOOLBAR, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %CCS_VERT OR %CCS_right OR %TBSTYLE_FLAT OR %CCS_NODIVIDER, 0 'Shows only the Home icon in the upper right corner.
            
              ' Set the toolbars normal button images
              TOOLBAR SET IMAGELIST hDlg, %ID_TOOLBAR, hTBNorm, 0
            
              ' Set the toolbars disabled button images
              TOOLBAR SET IMAGELIST hDlg, %ID_TOOLBAR, hTBDis,  1
            
              ' Set the toolbars hot button images
              TOOLBAR SET IMAGELIST hDlg, %ID_TOOLBAR, hTBHot,  2
            
              ' Add the buttons to the toolbar
              TOOLBAR ADD BUTTON    hDlg, %ID_TOOLBAR, 1, %ID_BTN_HOME,  %TBSTYLE_BUTTON, "Home"
              TOOLBAR ADD BUTTON    hDlg, %ID_TOOLBAR, 2, %ID_BTN_PRINT, %TBSTYLE_BUTTON, "Print"
              TOOLBAR ADD BUTTON    hDlg, %ID_TOOLBAR, 3, %ID_BTN_PROP,  %TBSTYLE_BUTTON, "Properties"
            
              ' Set the toolbar home button to disabled
              TOOLBAR SET STATE     hDlg, %ID_TOOLBAR, BYCMD %ID_BTN_HOME,  %TBSTATE_DISABLED
            
              ' Add a listview to the dialog box
            '  CONTROL ADD LISTVIEW,  hDlg, %ID_LISTVIEW, "", 0, 0, 0, 0, %WS_VISIBLE OR %WS_TABSTOP OR %LVS_ICON OR %LVS_SHOWSELALWAYS OR %LVS_SINGLESEL
            '
            '  ' Set the listview images
            '  LISTVIEW SET IMAGELIST hDlg, %ID_LISTVIEW, hLVImg, %LVSIL_NORMAL
            
              ' Display the dialog box
              DIALOG SHOW MODAL hDlg, CALL DlgProc
            
            END FUNCTION
            
            CALLBACK FUNCTION DlgProc
              STATIC Screen AS LONG
              LOCAL  pLVnmhdr AS NM_LISTVIEW PTR
              LOCAL  LVCount AS LONG
              LOCAL  w        AS LONG
              LOCAL  h        AS LONG
            
              SELECT CASE AS LONG CB.MSG
                CASE %WM_INITDIALOG
                  ' Set the listview to the Home page
                  Screen = 1
                  CreateScreen(CB.HNDL, Screen)
            
            '    CASE %WM_SIZE
            '      ' Resize the toolbar and listview control
            '      CONTROL GET SIZE CB.HNDL, %ID_TOOLBAR TO w, h
            '      CONTROL SET LOC  CB.HNDL, %ID_LISTVIEW, 0, h+1
            '      w = LO(WORD, CB.LPARAM)
            '      h = HI(WORD, CB.LPARAM)
            '      DIALOG PIXELS CB.HNDL, w, h TO UNITS w, h
            '      CONTROL SET SIZE CB.HNDL, %ID_LISTVIEW, w, h
            
                CASE %WM_COMMAND
                  SELECT CASE AS LONG CB.CTL
            
                    CASE %ID_BTN_HOME
                      ' User clicked the toolbar home button
            
                      ' Set the toolbar home button to disabled
                      TOOLBAR SET STATE CB.HNDL, %ID_TOOLBAR, BYCMD %ID_BTN_HOME,  %TBSTATE_DISABLED
            
                      ' Display the home page in the listview
                      Screen = 1
                      CreateScreen(CB.HNDL, Screen)
            
                    CASE %ID_BTN_PRINT
                      ? "Print Button Clicked"
            
                    CASE %ID_BTN_PROP
                      ? "Properites Button Clicked"
            
                  END SELECT
            
                  CASE %WM_NOTIFY
                    IF CB.NMID = %ID_LISTVIEW THEN
                      pLVnmhdr = CB.NMHDR
            
                      SELECT CASE AS LONG @pLVnmhdr.hdr.code
                        CASE %NM_CLICK
                          ' The user clicked on the listview control
            
                          ' If the click was not on a listview item then exit
                          IF @pLVnmhdr.iItem = -1 THEN EXIT FUNCTION
            
            
                          IF Screen = 1 THEN
                            ' Change the listview display
            
                            ' Get the listview item that was clicked
                            Screen = @pLVnmhdr.iItem + 2
            
                            ' Display the necessary listview screen
                            CreateScreen(CB.HNDL, Screen)
            
                            ' Enable the toolbar home button
                            TOOLBAR SET STATE CB.HNDL, %ID_TOOLBAR, BYCMD %ID_BTN_HOME, %TBSTATE_ENABLED
                          END IF
            
                      END SELECT
            
                    END IF
            
              END SELECT
            
            END FUNCTION
            
            ' Create the Listview screens
            SUB CreateScreen(hDlg AS LONG, Screen AS LONG)
            '  LISTVIEW RESET hDlg, %ID_LISTVIEW
            '
            '  SELECT CASE AS LONG Screen
            '    CASE 1
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 1, "Claude Monet"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 2, 2, "Pablo Picasso"
            '
            '    CASE 2
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 3, "The Cliff and the Porte d'Aval, Étretat"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 4, "Bridge over the Waterlily Pond"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 5, "Waterlilies, Green Reflection, Left Part"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 6, "Impression: soleil levant"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 7, "Houses of Parliament, London, with the sun breaking through the fog"
            '
            '    CASE 3
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1,  8, "Les Demoiselles d'Avignon"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1,  9, "Weeping Woman"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 10, "The Old Guitar Player"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 11, "The Acrobats"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 12, "Skull and Pitcher"
            '      LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, 1, 13, "The Dream"
            '
            '  END SELECT
            END SUB

            Comment


            • #7
              Walter,

              See post #2.

              For a vertical toolbar you need to add %TBSTATE_WRAP to each of the Buttons. (As well as add %CCS_VERT to the Toolbar style).
              Insert the TOOLBAR SET STATE lines shown just after the TOOLBAR ADD BUTTON statements.

              (Don't forget to include this style wherever you see TOOLBAR SET STATE in the original code)
              Last edited by Dave Biggs; 24 Nov 2008, 05:58 PM.
              Rgds, Dave

              Comment


              • #8
                Thanks Dave! That solved it.

                Comment

                Working...
                X