Announcement

Collapse
No announcement yet.

Toolbar & PBForms

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

  • Toolbar & PBForms

    I have been working through the Toolbar sample that came with PBForms 1.51
    and came unstuck with creating a toolbar from my own created icons.

    Creating the toolbar.bmp with TBbCreate from:
    http://www.powerbasic.com/support/pb...ad.php?t=23258
    It has the limitation of using 16 colors - my Icons use 24bit colors

    So I used Toolbar Paint to create the bitmap image list (toolbar.bmp)
    It unfortunately does not keep the transparency settings of the Icon(s) The transparent background gets replaced with white, which is not so cool looking on the toolbar.

    The bitmap given with the sample has a RGB(192,192,192) background, which ends up as transparent when the Image is displayed on the toolbar button.
    When I create my Icons with a RGB(192,192,192) background, the background is not displayed as transparent.

    I have tried the following code:-
    ImageList_AddMasked hImageList, hImage, RGB(192,192,192)
    ImageList_Add hImageList, hImage, RGB(192,192,192)

    I could not get it to work either, it must be because the imagelist is already built/loaded when the resource file is compiled.
    and/or I inserted the code in the wrong place
    and/or because the toolbar is created as a toolbar class (ToolbarWindow32) I am still in the dark when it comes to classes (or any OOP)

    Where/how can I specify the transparency (mask) for my Icons?

    I know it can be done without using a resource file, but I want to use the resource file.
    Andre Jacobs
    "The problem with Computers is that they do what you tell them, not what you want them to"

  • #2
    Ms

    Andre,

    Are you using PBWin 9.0? All the tools needed are there. PBForms 1.51 is not up to the level of PBWin 9.0 with regard to the newer DDT for many conrols and Image List management.

    E.G.
    'create an image list, you specify the color depth.

    IMAGELIST NEW BITMAP|ICON width&, height&, depth&, initial& TO hLst

    There are additional commands to add your bitmaps or icons from the program resource you have made.

    Please post the code that is giving you your problem.
    Rick Angell

    Comment


    • #3
      Thanks Richard

      Are you using PBWin 9.0? All the tools needed are there. PBForms 1.51 is not up to the level of PBWin 9.0 with regard to the newer DDT for many conrols and Image List management.
      Yes I am Using PB/Win 9.0
      I am just having difficulties as to where/how the code is used, as the pbForms sample seems to be doing it differently, all the updates/changes to the toolbar is done with a: "CONTROL SEND"

      E.G.
      'create an image list, you specify the color depth.
      IMAGELIST NEW BITMAP|ICON width&, height&, depth&, initial& TO hLst
      The Sample does not create the list


      There are additional commands to add your bitmaps or icons from the program resource you have made.

      Please post the code that is giving you your problem.
      Here is the code:
      Code:
      #PBFORMS CREATED V1.51
      '==============================================================================
      '
      '  ToolBar.bas example for PBForms and PowerBASIC for Windows
      '  Copyright (c) 2002-2005 PowerBASIC, Inc.
      '  All Rights Reserved.
      '
      '  Build a toolbar control
      '
      '==============================================================================
      
      #COMPILE EXE
      #DIM ALL
      
      '--------------------------------------------------------------------------------
      '   ** Includes **
      '--------------------------------------------------------------------------------
      #PBFORMS BEGIN INCLUDES
      #RESOURCE "ToolBar.pbr"
      #IF NOT %DEF(%WINAPI)
          #INCLUDE "WIN32API.INC"
      #ENDIF
      #PBFORMS END INCLUDES
      #INCLUDE "COMMCTRL.INC"
      #INCLUDE "PBForms.INC"
      '--------------------------------------------------------------------------------
      
      '--------------------------------------------------------------------------------
      '   ** Constants **
      '--------------------------------------------------------------------------------
      #PBFORMS BEGIN CONSTANTS
      %IDCANCEL     =   2
      %IDC_TOOLBAR  = 104
      %IDD_DIALOG1  = 102
      %IDR_IMGFILE1 = 103
      %IDR_IMGFILE2 = 104
      %IDR_MENU1    = 101
      #PBFORMS END CONSTANTS
      '--------------------------------------------------------------------------------
      %ToolButtons  = 9
      %ID_Btn1      = 1001
      %ID_Btn2      = 1002
      %ID_Btn3      = 1003
      %ID_Btn4      = 1004
      %ID_Btn5      = 1005
      %ID_Btn6      = 1006
      '--------------------------------------------------------------------------------
      '   ** Declarations **
      '--------------------------------------------------------------------------------
      DECLARE FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      #PBFORMS DECLARATIONS
      '--------------------------------------------------------------------------------
      DECLARE FUNCTION SetToolbarButtons(BYVAL hDlg AS DWORD) AS LONG
      '--------------------------------------------------------------------------------
      FUNCTION PBMAIN()
          PBFormsInitComCtls (%ICC_WIN95_CLASSES)
          ShowDIALOG1 %HWND_DESKTOP
      END FUNCTION
      '--------------------------------------------------------------------------------
      
      '--------------------------------------------------------------------------------
      '   ** Menus **
      '--------------------------------------------------------------------------------
      FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
      #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_DIALOG1
          LOCAL hMenu   AS DWORD
          LOCAL hPopUp1 AS DWORD
      
          MENU NEW BAR TO hMenu
          MENU NEW POPUP TO hPopUp1
          MENU ADD POPUP, hMenu, "&File", hPopUp1, %MF_ENABLED
              MENU ADD STRING, hPopUp1, "&Close", %IDCANCEL, %MF_ENABLED
      
          MENU ATTACH hMenu, hDlg
      #PBFORMS END MENU
          FUNCTION = hMenu
      END FUNCTION
      '--------------------------------------------------------------------------------
      
      '--------------------------------------------------------------------------------
      '   ** CallBacks **
      '--------------------------------------------------------------------------------
      CALLBACK FUNCTION ShowDIALOG1Proc()
      
          SELECT CASE CBMSG
              CASE %WM_INITDIALOG
                  ' Force TB to initially resize before we display the dialog
                  DIALOG POST CBHNDL, %WM_SIZE, 0, 0
      
              CASE %WM_SIZE
                  ' Resize the toolbar as the dialog is resized
                  CONTROL POST CBHNDL, %IDC_TOOLBAR, CBMSG, 0, 0
                  FUNCTION = 1
      
              CASE %WM_COMMAND
                  SELECT CASE CBCTL
                      CASE %IDC_TOOLBAR
                      CASE %ID_Btn1
                          MSGBOX "New=" + FORMAT$(%ID_Btn1), %MB_TASKMODAL
                      CASE %ID_Btn2
                          MSGBOX "Open=" + FORMAT$(%ID_Btn2), %MB_TASKMODAL
                      CASE %ID_Btn3
                          MSGBOX "Save=" + FORMAT$(%ID_Btn3), %MB_TASKMODAL
                      CASE %ID_Btn4
                          MSGBOX "Cut=" + FORMAT$(%ID_Btn4), %MB_TASKMODAL
                      CASE %ID_Btn5
                          MSGBOX "Copy=" + FORMAT$(%ID_Btn5), %MB_TASKMODAL
                      CASE %ID_Btn6
                          MSGBOX "Paste=" + FORMAT$(%ID_Btn6), %MB_TASKMODAL
                      CASE %IDCANCEL  ' exit on Esc
                          DIALOG END CBHNDL
      
                  END SELECT
          END SELECT
      
      END FUNCTION
      '--------------------------------------------------------------------------------
      
      '--------------------------------------------------------------------------------
      '   ** Dialogs **
      '--------------------------------------------------------------------------------
      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->%IDR_MENU1->
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW hParent, "Toolbar Example", 90, 66, 250, 142, %WS_POPUP OR %WS_BORDER OR _
              %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
              %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_CENTER OR %DS_3DLOOK OR _
              %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_CONTROLPARENT OR _
              %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          DIALOG  SET ICON hDlg, "#" + FORMAT$(%IDR_IMGFILE1)
          DIALOG  SET COLOR hDlg, -1, %WHITE
          CONTROL ADD "ToolbarWindow32", hDlg, %IDC_TOOLBAR, "Toolbar", 0, 0, 249, 25, _
              %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _
              %TB_AUTOSIZE, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
      
          AttachMENU1 hDlg
      #PBFORMS END DIALOG
      
          CALL SetToolbarButtons(hDlg)
          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
      
      #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
      #PBFORMS END CLEANUP
      
          FUNCTION = lRslt
      END FUNCTION
      '--------------------------------------------------------------------------------
      
      '--------------------------------------------------------------------------------
      FUNCTION SetToolbarButtons(BYVAL hDlg AS DWORD) AS LONG
          LOCAL x     AS LONG
          LOCAL a$
          LOCAL Tbb() AS TBBUTTON
          LOCAL Tabm  AS TBADDBITMAP
          DIM Tbb(0 TO %ToolButtons - 1) AS LOCAL TBBUTTON
      
          ' 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_BUTTON
              Tbb(x).dwData = 0
              Tbb(x).iString = 0
              SELECT CASE AS CONST x
                  CASE 0,4,8
                      ' Gap creation buttons.
                      Tbb(x).fsStyle = %TBSTYLE_SEP
                  CASE 1
                      Tbb(x).iBitmap = 0
                      Tbb(x).idCommand = %ID_Btn1
                      Tbb(x).iString = 0
                  CASE 2
                      Tbb(x).iBitmap = 1
                      Tbb(x).idCommand = %ID_Btn2
                      Tbb(x).iString = 1
                  CASE 3
                      Tbb(x).iBitmap = 2
                      Tbb(x).idCommand = %ID_Btn3
                      Tbb(x).iString = 2
                  CASE 5
                      Tbb(x).iBitmap = 4
                      Tbb(x).idCommand = %ID_Btn4
                      Tbb(x).iString = 3
                  CASE 6
                      Tbb(x).iBitmap = 5
                      Tbb(x).idCommand = %ID_Btn5
                      Tbb(x).iString = 4
                  CASE 7
                      Tbb(x).iBitmap = 6
                      Tbb(x).idCommand = %ID_Btn6
                      Tbb(x).iString = 5
              END SELECT
          NEXT x
      
          ' Set the individual image size for the TB
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(24,24)
      
          ' Set the imge list for the TB
          Tabm.hInst = GetModuleHandle(BYVAL %NULL)
          Tabm.nID = %IDR_IMGFILE2
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
      
          ' Set the buttons
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_BUTTONSTRUCTSIZE, SIZEOF(Tbb(0)), 0
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBUTTONS, %ToolButtons, VARPTR(Tbb(0))
      
          ' Note: Widest string sets all buttons width. "Paste" is here
          '       made a little wider to make all buttons wider.
          a$ = "New" & $NUL & "Open" & $NUL & "Save" & $NUL & _
               "Cut" & $NUL & "Copy" & $NUL & "  Paste  " & $NUL & $NUL
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDSTRING, 0, STRPTR(a$)
      
      END FUNCTION
      And the RC File, Toolbar.rc:
      Code:
      //#PBForms Created v1.51
      //--------------------------------------------------------------------------------
      // The first line in this file is a PBForms comment. It
      // should ALWAYS be the first line of the file. Other
      // PBForms comments are placed at the beginning and
      // ending of blocks of code that should be edited using
      // PBForms only. Do not edit or delete these comments or
      // PBForms will not be able to reread the file correctly.
      // See the PBForms documentation for more information.
      // Beginning blocks begin like this: //#PBForms Begin ...
      // Ending blocks begin like this:    //#PBForms End ...
      // Feel free to make changes anywhere else in the file.
      //--------------------------------------------------------------------------------
      
      #include "Resource.h"
      
      //--------------------------------------------------------------------------------
      //  ** Constants **
      //--------------------------------------------------------------------------------
      //#PBForms Begin Constants
      #define IDR_IMGFILE1  103
      #define IDR_IMGFILE2  104
      //#PBForms End Constants
      
      //--------------------------------------------------------------------------------
      //  ** RC Data **
      //--------------------------------------------------------------------------------
      //#PBForms Begin RCData
      IDR_IMGFILE1    ICON    DISCARDABLE "APPICON.ICO"
      IDR_IMGFILE2    BITMAP  DISCARDABLE "TOOLBAR.BMP"
      //#PBForms End RCData
      The two toolbars used is attached.

      Toolbar.bmp is the one supplied with the Sample
      When I want to use Tbb32.bmp, the line in the RC file:
      Code:
      IDR_IMGFILE2    BITMAP  DISCARDABLE "TOOLBAR.BMP"
      Gets changed to:
      Code:
      IDR_IMGFILE2    BITMAP  DISCARDABLE "Tbb32.bmp"
      The RC gets compiled and then in the Toolbar.bas the line(s):
      Code:
       ' Set the individual image size for the TB
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(24,24)
      Gets changed to:
      Code:
       ' Set the individual image size for the TB
          CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(32,32)
      as the icons in the bitmap is defined as 32x32

      As can be seen in the tbb32.bmp, I've tried various background colors, (the ones with the white backgrounds are those that are defined as transparent backgrounds on the Icons), with no resultant transparency


      My dilemma is this:
      It seems that with creating the toolbar as a class, the "toolbar add", "toolbar set" etc. does not seem applicable, I could be wrong, but then where is the imagelist to use with these commands?
      Attached Files
      Andre Jacobs
      "The problem with Computers is that they do what you tell them, not what you want them to"

      Comment


      • #4
        Andre,

        The PBForms examples are NOT current with PBWin 90

        Please see PBWIN90\Samples\DDT\Toolbar\Toolbar.bas. Then try and convert your code to use the new ImageList and Toolbar DDT commands.

        As far as what you are doing with the PBForms version, I'll try to look at it later when I get a chance. The stock example does compile and run however.
        Rick Angell

        Comment


        • #5
          Richard,

          I have looked at the sample that came with PB/win 9.
          It is not quite what I had in mind.

          The sample that came with PBForms however does.(Except for the transparency part)

          The difference is that in using resource file the Icons must only be available at compile time (compiling of the rc file) when doing it the the PB/WIN way, the Icons must still be available at run-time. I prefer less files to be included when distributing
          Andre Jacobs
          "The problem with Computers is that they do what you tell them, not what you want them to"

          Comment


          • #6
            The difference is that in using resource file the Icons must only be available at compile time (compiling of the rc file) when doing it the the PB/WIN way, the Icons must still be available at run-time.
            That's not accurate. If an ICON resource is included in your compiled executable, that icon is available to your program, and it does not matter if you are coding using 'DDT Style' or 'SDK-Style.'

            The two different coding styles may require different techniques to actually get at that resource at run time, but that resource IS available.

            The PBForms product may or may not support "direct and easy" inclusion of that resource, but all the tools you need are provided by the compiler.


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

            Comment


            • #7
              Michael is quite correct. If you have the icons in resource you can load them to an Imagelist using the new commands. Just see the help file. Resource files can be made independent of PBForms as well, but re-entry, change and save in PBForms will overwrite the resource with a new one. So if you have to, preserve a back-up rc file separately with any unique additions so you can retrieve after a PBForms save.

              Please note there are 2 Imagelist Add forms for icons, bimaps and masked bitmaps; one for a handle specification and the other for a string which can be a filename or a resource "name" (e.g. "#102","OpenIcon") Form the help file, in the Add commands you will see the highlighted phrasing.

              IMAGELIST ADD ICON hLst, Icn$ [TO data&]
              An icon is added to the ImageList specified by hLst. With this syntax, the icon is specified by a name string (Icn$), which is the name of an embedded resource or a disk file.
              Once I'd have the GUI designed (in PBForms), I'd edit to the newer DDT for the ease of the new DDT functions to manage the toolbar. Also please send your request to PB to have PB Forms updated to the new DDT usage for better interactivity!

              Gotta run ...
              Rick Angell

              Comment


              • #8
                That's not accurate. If an ICON resource is included in your compiled executable, that icon is available to your program, and it does not matter if you are coding using 'DDT Style' or 'SDK-Style.
                Michael is quite correct. If you have the icons in resource you can load them to an Imagelist using the new commands. Just see the help file.
                Thanks Michael and Richard,
                With my analyzing of the sample code(s) I went through, I only saw where the Icon/Bitmap was "loaded" (from disk) at runtime and therefore assumed (silly me) that this was the only way to do it, my mistake. So when I found the PBForm sample, I was "over-the-moon" and really thought that this was the way to go.
                The help file and I have this "understanding""- it will continue to spew reams and reams of useful information, and I will continue to absorb it only at a rate that I can cope with, it is a long and tedious process for me, but only when I become REALLY unstuck, do I post the question(s) here.

                Resource files can be made independent of PBForms as well, but re-entry, change and save in PBForms will overwrite the resource with a new one. So if you have to, preserve a back-up rc file separately with any unique additions so you can retrieve after a PBForms save.
                I have found that if the "customized" items are coded into the rc file outside the PBForms Blocks, then PBForms do not overwrite the added code when saved - under most conditions.
                I will however take your excellent advice (why did I not think of it?) and keep a backup of the rc (just incase)

                Also please send your request to PB to have PB Forms updated to the new DDT usage for better interactivity!
                Will do, once I know what I am doing (or not doing) so that my request would be clear and understandable. I would not wish to cloud a request of this nature with my muddled/ignorant description. The terminology used/needed is still a bit unclear.

                Once I'd have the GUI designed (in PBForms), I'd edit to the newer DDT for the ease of the new DDT functions to manage the toolbar.
                This is what I would like to do, and have asked for this in my own clumsy, mistake riddled way. I realized that there are only one of two ways to get what I need.
                1) There would/could be a statement for "masking" with doing it the "PBForms way" (I was hoping to find one here - as the sample does it correctly)
                or
                2) There must be a way to "correct" the PBForms "shortcoming" with either DDT and/or SDK

                As far as I can see, the "corrections" should be inserted somewhere inside the following code.
                I am just unsure as to where and exactly how, please assist.

                Code:
                    ' Set the individual image size for the TB
                    CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(24,24)
                
                    ' Set the imge list for the TB
                    Tabm.hInst = GetModuleHandle(BYVAL %NULL)
                    Tabm.nID = %IDR_IMGFILE2
                    CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
                
                    ' Set the buttons
                    CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_BUTTONSTRUCTSIZE, SIZEOF(Tbb(0)), 0
                    CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBUTTONS, %ToolButtons, VARPTR(Tbb(0))
                I have tried:
                ImageList Add Masked Tabm.hInst, "IDR_IMGFILE2", RGB(255,0,255)
                Just before:
                CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
                That does not seem to do anything. - I really do need a bit of "hand holding" here.

                Could the steps/sequence/process of the resource, ImageList and control be explained, as if to a child? I am totally confused here.
                Andre Jacobs
                "The problem with Computers is that they do what you tell them, not what you want them to"

                Comment


                • #9
                  Be sure to put your code OUTSIDE of the PBForms marked areas. On Resource files you may need to use a seperate one from the one PBFORMs makes as it can wipe out all of your code in there,

                  As far as the code outside of the PBForms marked areas, you won't see your code showing in PBForms, but just knowing it works correcly when compiled gets you going.

                  I don't know if there is an update comig, but it should be top priority to make PBForms fully compatible with PB 9. I don't think it is too cool to have your compilers ahead of your tools. There are 3rd party gui designers. I find I am using PBForms less and less because of this.
                  Barry

                  Comment


                  • #10
                    >>Also please send your request to PB to have PB Forms updated to the new DDT usage >>for better interactivity!

                    > Will do, once I know what I am doing (or not doing) so that my request would be clear >and understandable. I would not wish to cloud a request of this nature with my >muddled/ignorant description.


                    Well, you know NOW that your PBForms product is not 'in synch' with the 9x compiler features, but...

                    Were I a user of both products, I would certainly be asking the vendor why PBForms does not seem to support all the DDT controls supported by the compiler.

                    Sounds kinda like ordering a Cadillac and having it delivered with a Chevrolet interior.

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

                    Comment


                    • #11
                      Andre,

                      I'll suggest that learning and using the new DDT here will be beneficial for you to do and use. If and when PBForms gets up to speed for 9.0 and on then these statements should be expected from that product. Many Control Send messages have been wrapped, some enhanced, and added in PBWin 9 for imagelists, toolbars, tabs, scrollbars and some other controls which formerly needed generic CONTROL SEND or API messaging to work with them in a GUI.

                      So here is a cobbled together psuedo-code blurb made from altered snips from the PBWin Samples\DDT\Toolbar example. Main purpose is to illustrate how you could integrate he new, improved DDT with your PBForms produced template. Where a new DDT statement replaces PBForms or your own code, you might just comment the old one out until you are comfortable with the newer approach.

                      Code:
                      FUNCTION YourDialog(BYVAL hParent AS DWORD) AS LONG
                          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 BITMAP 32, 32, 32, 4 TO hTBNorm
                            IMAGELIST ADD MASKED hTBNorm, "#100", RGB(192,192,192)            ' Normal Home button
                            IMAGELIST ADD MASKED hTBNorm, "#101", RGB(192,192,192)            ' Normal Print button
                            IMAGELIST ADD MASKED hTBNorm, "#102", RGB(192,192,192)            ' Normal Properties button
                      
                            ' Create an imagelist for the hot toolbar buttons
                            IMAGELIST NEW BITMAP 32, 32, 32, 4 TO hTBHot
                            IMAGELIST ADD MASKED hTBHot, "#200", %WHITE             ' Hot Home button
                            IMAGELIST ADD MASKED hTBHot, "#201", %WHITE             ' Hot Print button
                            IMAGELIST ADD MASKED hTBHot, "#202", %WHITE             ' Hot Properties button
                      
                            ' Create an imagelist for the disabled toolbar buttons
                            IMAGELIST NEW BITMAP 32, 32, 32, 4 TO hTBDis
                            IMAGELIST ADD MASKED hTBDis, "#300", %RED             ' Disabled Home button
                            IMAGELIST ADD MASKED hTBDis, "#301", %RED             ' Disabled Print button
                            IMAGELIST ADD MASKED hTBDis, "#302", %RED             ' Disabled Properties button
                      
                      ' PBFORMS SECTION starts ...
                      #PBFORMS BEGIN DIALOG %ID_DLG_frmLogin->->
                            DIALOG NEW hParent, ..... TO hDlg       'or DIALOG NEW PIXELS, hParent, ..... TO hDlg
                            ' Add a toolbar to the dialog box, in your case REPLACE the PBFORMS line with one of this form
                            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
                      
                      
                      ' PBFORMS SECTION ends ...
                      #PBFORMS END DIALOG
                      
                            ' 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 separator hDlg, %ID_TOOLBAR,20 at 2
                            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
                      
                            DIALOG SHOW ....
                      #PBFORMS BEGIN CLEANUP %ID_DLG_YourDialog
                          'any font clean up will be here ... but I suggest looking at the FONT NEW,
                          'CONTROL|GRAPHIC|XPRINT SET FONT and FONT END statements in PBWin 9.0
                          'then in PBForms do not assign fonts, do it here outside of any PBForms tags, or
                          'in the CALLBACK. Note that in the callback you will need to use STATIC variables
                          'for the font handles you create.  Also in the callback use CONTROL SET FONT statements
                          'for affected controls in the CASE %WM_INITDIALOG case, before the dialog is displayed.
                          'perhaps in the future PBForms will be upgraded to use these new statements which could eliminate
                          'most of the need to have a PBForms include file for some more applications.
                          '
                          'In the callback you can use the FONT END statements in a %WM_DESTROY case to release them.
                      #PBFORMS END CLEANUP
                                                    
                            
                      END FUNCTION
                      
                      '........ then in the dialog callback handle the buttons:
                          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
                      
                                    ' do some code ...
                      
                                  CASE %ID_BTN_PRINT
                                    ? "Print Button Clicked"
                      
                                  CASE %ID_BTN_PROP
                                    ? "Properites Button Clicked"
                      
                                END SELECT
                      Originally posted by MCM
                      Sounds kinda like ordering a Cadillac and having it delivered with a Chevrolet interior.
                      Uh huh! Or having the Cadillac shocks degrade as versions were released, making for a stiff, bumpy ride.
                      Rick Angell

                      Comment


                      • #12
                        I am guessing "PbForms update" is on someone's "to do" list in Florida... and not on the bottom, either.

                        (I think PB/Unix OWNS that bottom slot).
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Thank you Guys,

                          I have sent a request to support.

                          It seems that I will have to do the Toolbar according to the new DDT, as the solution for my problem is not available yet.
                          Andre Jacobs
                          "The problem with Computers is that they do what you tell them, not what you want them to"

                          Comment


                          • #14
                            I have eventually managed to get the Toolbar to display the buttons with the correct transparency. Hopefully someone else can benefit from this.

                            In my search/research I've found the DDT way to be better, but I still needed to overcome the "obstacle" of the transparency with the "PBForms SDK" method.

                            The problem was that the bitmap was not/could not be created with the transparency mask set.

                            The code loaded the bitmap directly from the resource to the toolbar with:
                            Code:
                            ' Set the imge list for the TB
                                Tabm.hInst = GetModuleHandle(BYVAL %NULL)
                                Tabm.nID = %IDR_IMGFILE2
                                CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
                            All That is needed is to load the bitmap into an ImageList, set the transparency mask in the ImageList and load the Toolbar from the Imagelist.

                            Thus the above code is replaced with:
                            Code:
                                ' Set the imagelist used with default images
                                hImage = LoadImage(GetModuleHandle(ByVal %NULL), "TBNORM", %IMAGE_BITMAP, 0, 0, _
                                         %LR_LOADTRANSPARENT Or %LR_LOADMAP3DCOLORS Or %LR_DEFAULTSIZE)
                                hImageList = ImageList_Create(32, 32, %ILC_MASK Or %ILC_COLOR24, 1, 0)
                                ImageList_AddMasked hImageList, hImage, RGB(192,192,192)
                                ImageList_Add hImageList, hImage, RGB(192,192,192)
                                DeleteObject hImage
                                ' Set the image list for the TB - Now Safely set with Transparent colours/background
                                Control Send hDlg, %IDC_TOOLBAR, %TB_SETIMAGELIST, %ToolButtons, hImageList
                            The bitmap is now referenced in the RC as:
                            TBNORM BITMAP DISCARDABLE "Toolbar.bmp"

                            The bitmap was also altered to have the "background" set to RGB(192,192,192) and have images with size 32x32 and 24 bit colour

                            Is the correct way? - I don't know
                            Is this the best way - Probably not
                            BUT - it works....., and I have gained quite a bit by researching it to the n'th degree. My "research speed" could only improve from now on. It is not so easy to wade through leagues and leagues of information in all kinds of help files.
                            Knowing which help file is appropriate is half the battle, understanding the language/terminology is the other half.
                            Andre Jacobs
                            "The problem with Computers is that they do what you tell them, not what you want them to"

                            Comment


                            • #15
                              In my search/research I've found the DDT way to be better...
                              How did you come to that conclusion?

                              Is the correct way? - I don't know
                              No.

                              This code
                              Code:
                              ' Set the imge list for the TB
                                  Tabm.hInst = GetModuleHandle(BYVAL %NULL)
                                  Tabm.nID = %IDR_IMGFILE2
                                  CONTROL SEND hDlg, %IDC_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
                              and the CreateToolbarEx function are from an era gone by and really should not be used
                              when creating a modern toolbar. They both use the internal imagelist that is managed by
                              the toolbar which is near brain dead in regards to image color depth and transparency.

                              This block of code
                              Code:
                                  ' Set the imagelist used with default images
                                  hImage = LoadImage(GetModuleHandle(ByVal %NULL), "TBNORM", %IMAGE_BITMAP, 0, 0, _
                                           %LR_LOADTRANSPARENT Or %LR_LOADMAP3DCOLORS Or %LR_DEFAULTSIZE)
                                  hImageList = ImageList_Create(32, 32, %ILC_MASK Or %ILC_COLOR24, 1, 0)
                                  ImageList_AddMasked hImageList, hImage, RGB(192,192,192)
                                  ImageList_Add hImageList, hImage, RGB(192,192,192)
                                  DeleteObject hImage
                                  ' Set the image list for the TB - Now Safely set with Transparent colours/background
                                  Control Send hDlg, %IDC_TOOLBAR, %TB_SETIMAGELIST, %ToolButtons, hImageList
                              contains some serious errors.

                              Code:
                                  hImage = LoadImage(GetModuleHandle(ByVal %NULL), "TBNORM", %IMAGE_BITMAP, 0, 0, _
                                           %LR_LOADTRANSPARENT Or %LR_LOADMAP3DCOLORS Or %LR_DEFAULTSIZE)
                              This is correct but the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS flags are not needed. They
                              are from an era gone by. In fact, all you need is this
                              Code:
                                hImage = LoadBitmap(GetModuleHandle(ByVal %NULL), "TBNORM")
                              This code
                              Code:
                                  ImageList_Add hImageList, hImage, RGB(192,192,192)
                              fails, and you would would never know it did. It fails because the second parameter of the
                              ImageList_Add function expects the handle of a bitmap not a color value, therefore, the bitmap
                              it adds would not be transparent.
                              You actually ended up with two bitmaps in the imagelist. First, you are using a compound bitmap
                              which means the second bitmap is not needed. Second, the second bitmap would most likely look
                              horrible because it is not transparent and also for the following reason:
                              The ImageList_AddMasked function modifies the original image, therefore a copy of the image
                              must be made if it is to be reused.

                              This code is
                              Code:
                                  Control Send hDlg, %IDC_TOOLBAR, %TB_SETIMAGELIST, %ToolButtons, hImageList
                              is correct, but it will not work for nonzero values of %ToolButtons for versions of the Comctl32.dll that
                              are older than 5.80. On version 4.70 you will need TB_SETHOTIMAGELIST and TB_SETDISABLEDIMAGELIST for
                              nonzero values of %ToolButtons.

                              A modified version of your code will look like this
                              Code:
                                  ' Set the imagelist used with default images
                                  hImage = LoadBitmap(GetModuleHandle(ByVal %NULL), "TBNORM")
                                  hImageList = ImageList_Create(32, 32, %ILC_MASK Or %ILC_COLOR24, 1, 0)
                                  ImageList_AddMasked hImageList, hImage, RGB(192,192,192)
                                  DeleteObject hImage
                                  ' Set the image list for the TB - Now Safely set with Transparent colours/background
                                  Control Send hDlg, %IDC_TOOLBAR, %TB_SETIMAGELIST, %ToolButtons, hImageList
                              Also, keep the following tip in mind:
                              Avoid using the system colors as mask colors for imaglists. Even though a
                              system color may be equal to the background color of an image on a specific
                              computer, it may not be the same on a different color with a different OS or
                              different control panel settings.

                              For example, never do this
                              Code:
                                  ImageList_AddMasked hImageList, hImage, GetSysColor(%COLOR_BTNFACE)
                              Last edited by Dominic Mitchell; 5 Jan 2009, 05:15 AM.
                              Dominic Mitchell
                              Phoenix Visual Designer
                              http://www.phnxthunder.com

                              Comment


                              • #16
                                Thanks Dominic,

                                A lot of the code was a case of: " Monkey see, monkey do - monkey finds it works, monkey leave alone, while ahead"

                                Thanks for the modified version, it makes much more sense - now.

                                I thought the:
                                ImageList_AddMasked hImageList, hImage, RGB(192,192,192)
                                only "set" the mask, only indicating which color was the mask
                                and that:
                                ImageList_Add hImageList, hImage, RGB(192,192,192)
                                did the actual loading of the bitmap to the imagelist - silly me.
                                I should start coding with methods to get returns from each statement, so that it can be interrogated and corrected, if anything is incorrect, before I can jump to conclusions of: "It works, so it must be correct"

                                I now have a much clearer understanding of what happens and why.
                                My big hunt was trying to come to grips with why my toolbar did not work, now I know.
                                I have a saying: " If nothing goes wrong, then you learn nothing", boy did I learn here.

                                What I ended up with, was more of a "work-around" than the actual solution/method that I will eventually use to implement.
                                I am actually quite proud of my "accomplishment", it was rather difficult to "fish" it out of the plethora of information out there. It took me a long time to make sense of unfamiliar words/terms that are splattered all over the place.
                                As an old school Cobol programmer with little BASIC knowledge (PB does not look anything like the GWbasic I played with years ago) and zero, ziltch knowledge of programming for windows, and even less "events based" programming skills, this is quite a milestone. With LOTS of new knowledge "under the belt", even though my code is about as seaworthy as a submarine with a screen door hatch.

                                BTW, the internal imagelist (handled by the toolbar) coped with my bitmap with color depths of 24 with no problem (only the Transparency mask was at fault) - as far as I could tell. - Even a Photo, reduced to 48x48 with 24bit color, displayed fine.

                                As to my "conclusion" of DDT being better:
                                I think I mixed up a bit on the terminology.
                                That statement stems/grew from the all the above posts.
                                The way of the PBForms sample, - In my mind I saw this as the "SDK way".
                                Then the method that the Toolbar sample uses, became the "DDT way" in my mind, hence the conclusion of: "The DDT way to be better"

                                I should have stated it more clearly with: "The way to go is the newer method used in the PB/Win sample for toolbars, it is much better than the method used in the PBForms sample."

                                It is a bit of a "let down" as I bought PBForms together with PB/win 9.0, with the anticipation that PBForms would "ease" me into the world of windows programming. Now I find that PBForms and PB/win 9.0 are not "in-sync" .... bummer, Yet I still picked up a lot from PBForms in it's current state, so NP.
                                Andre Jacobs
                                "The problem with Computers is that they do what you tell them, not what you want them to"

                                Comment

                                Working...
                                X