Announcement

Collapse
No announcement yet.

Coloring tabs with the new tab feature in PB 9

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

  • Coloring tabs with the new tab feature in PB 9

    I've been playing with the tab example in PB 9 and it uses a subroutine with SDK functions to paint a gradient on each tab. I tried to remove that and use CONTROL SET COLOR instead, not for any good reason but just to learn the ins and outs of it. But I can't seem to get it to work.

    Is that something that just isn't going to work? Or am I missing something?

    Barry

  • #2
    Sounds like a question which will get a much better and faster response were it directly sent to [email protected]
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Or at least you post some compilable code.
      I didn't say something new here :-).
      --Theo Gottwald
      ------------------------------------------------
      76706 Dettenheim * Germany * [email protected]
      ------------------------------------------------
      Joses Forum * Theo's Link Site * IT-Berater.org

      Comment


      • #4
        I'd like to have posted some code but by the time it occurred to me to post a message about this I'd already deleted that and started playing with using the SDK to do it as in the provided example.

        I may give it another try tomorrow and post some code.

        Barry

        Comment


        • #5
          never NEVER NEVER delete code you are working on!!!!

          You may need a concept you are working on that crops up again later

          You never know....sometimes it all boils down to "Well this worked, but this didn't....How come????" and compare the 2 and realize the differences
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment


          • #6
            >never NEVER NEVER delete code you are working on!!!!

            ???

            What if it's crap?

            When I create crap, I delete it immediately so I'm not tempted to use any of it. Forces me to start over with a clean page, which will surely result in something better than crap.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              never NEVER NEVER delete code you are working on!!!!
              This already sounds like one of those personal choices.

              But Michael,
              If you delete the crap, giving you a clean page, isn't that what you started with when you created the crap?
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                Originally posted by Cliff Nichols View Post
                never NEVER NEVER delete code you are working on!!!!
                I'm a well retired programmer and all I do is play around with it now so if I lose all my code it's no big deal.

                I like to learn with little experiments and the confidence that it'll be thrown away when I'm done helps me feel a little freer to experiment and I find that I'm a little more imaginative. I've always done that when I could and I find it works well for me.

                Anyway, the point of what I was doing was just to try to understand how tabbed interfaces work. The painting was a trivial part of it. I was curious so I tried CONTROL ADD COLOR and it didn't work so after a few different attempts I put it back like it was and went on with my learning.

                That little experiment did point out to me that the tab's ID could be used as the parent for controls. I have almost no GUI experience so that was a surprise to me. I'm sure I'd have eventually seen that anyway but this helped me to understand it when I did.

                Barry

                Comment


                • #9
                  Barry, I was trying something similar, just today. I was trying to find some way to color the raised part of the tab pages since it is difficult for the user to know which tab page has been selected. The tab control example in the Samples folder uses a reference to xp themes in the resource file to highlight the selected page. I was trying to find another way of doing this, but haven't had any success yet.

                  Comment


                  • #10
                    I never throw away old junk code... It gets filed away and possibly used again later.

                    Think of it this way... even if it's "crap" that's fertilizer for something better later, it feeds ideas :idea:
                    <b>George W. Bleck</b>
                    <img src='http://www.blecktech.com/myemail.gif'>

                    Comment


                    • #11
                      I saw the reference to XP styles but I didn't really understand that. I've never really paid much attention to the different GUI styles and I'm using Vista so I wasn't sure that applied to me anyway.

                      I tried commenting it out and I couldn't see any difference so I left it commented.

                      I'm finding that I like to write very simple and straightforward interfaces. Since I'm only writing very simple programs anyway that works fine for me. Most just have a simple window with the few controls I've learned to deal with. The fun part has been to try to find ways to turn that into something amusing to write and to use. The writing has been fun but the audience I have in mind for this, the others at this retirement home, don't seem interested in the programs, at least not yet. I'm having furn writing them so that's minor.

                      Barry

                      Comment


                      • #12
                        Here is some code to highlight the raised tab portion. I have stripped out all of the extraneous font and color stuff from PowerBasic's tab control example in the Samples folder, and added a routine originally written by, I think, Borje Hagsten. Note that the resource reference has been omitted, #INCLUDE "commCtrl.inc" is needed, %TCS_OWNERDRAWFIXED style added to CONTROL ADD TAB, and Borje's ColorTab() routine is added at the end.

                        Code:
                        #COMPILE EXE
                        #DIM ALL
                        #INCLUDE "win32api.inc"
                        #INCLUDE "commCtrl.inc"
                        
                        ' Control equates
                        %ID_TAB            = 1000
                        %ID_TAB1_TBFIRST   = 1001
                        %ID_TAB1_LBFIRST   = 1002
                        %ID_TAB1_LBLAST    = 1003
                        %ID_TAB1_TBLAST    = 1004
                        %ID_TAB1_BNSUBMIT  = 1005
                        %ID_TAB2_CBCHOICES = 1006
                        %ID_TAB3_LBCHOICES = 1007
                        %ID_TAB3_TEXTBOX   = 1008
                        
                        GLOBAL hDlg AS LONG
                        
                        FUNCTION PBMAIN () AS LONG
                          LOCAL hTab1     AS LONG
                          LOCAL hTab2     AS LONG
                          LOCAL hTab3     AS LONG
                          DIALOG NEW 0, "Tab Control Example", , , 300, 140, %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
                        
                          ' Add a Tab control to the main dialog box
                          CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 298, 138, %TCS_OWNERDRAWFIXED
                        
                          ' Build the Tab 1 dialog and it's controls
                          TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1", CALL TabProc TO hTab1
                          CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 2, 6, 100, 12
                          CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 60, 6, 100, 12
                          CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 20, 100, 12
                          CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 60, 20, 100, 12
                          CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 235, 100, 50, 14
                        
                          ' Build the Tab 2 dialog and it's controls
                          TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2", CALL TabProc TO hTab2
                          CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 2, 6, 100, 40, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
                          COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
                          COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
                          COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
                          COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 4"
                          COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 5"
                          COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
                        
                          ' Build the Tab 3 dialog and it's controls
                          TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3", CALL TabProc TO hTab3
                          CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 2, 6, 100, 60
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 5"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 6"
                          LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 7"
                          CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 120, 6, 100, 12, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
                        
                          ' Display the main dialog box
                          DIALOG SHOW MODAL hDlg CALL tabCtrlProc
                        END FUNCTION
                         
                        ' Callback function used by all Tab dialogs
                        CALLBACK FUNCTION TabCtrlProc()
                           SELECT CASE AS LONG CB.MSG
                              CASE %WM_DRAWITEM 'draw tab item text in different color on select
                                 IF CB.WPARAM = %ID_Tab THEN colorTab CBHNDL, CBWPARAM, CBLPARAM
                           END SELECT 
                        END FUNCTION 
                         
                        ' Callback function used by all Tab dialogs
                        CALLBACK FUNCTION TabProc
                          LOCAL i    AS LONG
                          LOCAL s    AS STRING
                        
                          SELECT CASE AS LONG CB.MSG
                            CASE %WM_COMMAND
                              SELECT CASE AS LONG CB.CTL
                        
                                CASE %ID_TAB1_BNSUBMIT
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                    MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
                                  END IF
                        
                                CASE %ID_TAB2_CBCHOICES
                                  IF CB.CTLMSG = %CBN_SELCHANGE THEN
                                    COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                                    COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                                    ? "You selected "+s
                                  END IF
                        
                                CASE %ID_TAB3_LBCHOICES
                                  IF CB.CTLMSG = %LBN_SELCHANGE THEN
                                    LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                                    LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                                    CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
                                  END IF
                              END SELECT
                          END SELECT
                        END FUNCTION
                        
                        SUB colorTab(hDlg AS LONG, wParm AS LONG, lParm AS LONG)
                           LOCAL lDISPtr AS DRAWITEMSTRUCT PTR, zCap AS ASCIIZ * 50
                           LOCAL ti AS TC_ITEM, TextDrawFlag AS LONG
                           LOCAL nColor, hBrush AS LONG
                        
                           lDisPtr = lparm
                           nColor = RGB(220, 220&, 240&)
                           hBrush = CreateSolidBrush(nColor)
                           SelectObject @lDisptr.hDc, hBrush
                           
                           @lDisptr.rcItem.nTop = @lDisptr.rcItem.nTop + 4
                           IF @lDisPtr.ItemState = %ODS_SELECTED THEN
                              SetTextColor @lDisPtr.hDc, %BLUE
                              SetBkColor @lDisPtr.hDc, nColor
                              FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
                           ELSE
                              SetTextColor @lDisPtr.hDc, %BLACK
                              SetBkColor @lDisPtr.hDc, GetSysColor(%COLOR_3DFACE)
                              FillRect @lDisptr.hDc, @lDisptr.rcItem, GetSysColorBrush(%COLOR_3DFACE)
                           END IF
                        
                           ti.mask = %TCIF_TEXT
                           ti.pszText = VARPTR(zCap)
                           ti.cchTextMax = SIZEOF(zCap)
                           CALL TabCtrl_GetItem(GetDlgItem(hDlg, wParm), @lDisptr.itemID, ti)
                           DrawText @lDisptr.hDc, zCap, LEN(zCap), @lDisptr.rcItem, %DT_SINGLELINE OR %DT_CENTER
                           DeleteObject hBrush
                        END SUB

                        Comment

                        Working...
                        X