bourny

Assistance with Tabs

5 posts in this topic

I am using some tabs and controls to allow me to float boxes onto a background  image to act as buttons.  It all works great except it seems I can go forward in the buttons in an order but if I go back to the previous button to the one I clicked on it does not work.

 

The code I am using used to use images as the background controls but this was causing problems on windows 10 so I dropped the imaged in preference for simply using the labels but not I have inherited this strange bug. I have no doubt it is the use of the index values and pic[$number] but cannot figure out how to fix it. 

I am trying to locate also the person to credit this code with that I am using for the tabbed gui but cannot find the original article I obtained the code from.

#include <GUICONSTANTS.au3>
Global $LocalClientWKDir = "c:\tmp"


;Tab Global Vars
Global $Item = -1
Global $Over = -1
Global $Pic[5]
Global $Tab, $Tab1, $Tab2, $Tab3, $Tab4, $Tab5

MakeGui()
LaunchGUI()


Func MakeGui()

   $hGUI = GUICreate('MYGui', 1252, 750)
   BuildTabs()
   GUISetState()

EndFunc


Func LaunchGUI()

   While 1

      $Msg = GUIGetMsg()
      If $Item = -1 Then
         $Msg = $Pic[0]
         $Item = 1
      EndIf

      Switch $Msg

         Case $GUI_EVENT_CLOSE
            Exit

         Case $Pic[0] To $Pic[UBound($Pic) - 1]

             If $Msg <> $Pic[$Item] Then
                 GUICtrlSetImage($Pic[$Item], "c:\WindowsMail.bmp")
                ; GUICtrlSetcolor($Pic[$Item] + 1,  0x708090)
                 $Item = _Index($Msg)
                 GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item, 0)
                 $Over = -1
             EndIf

         Case $GUI_EVENT_CLOSE

             Exit


         Case $Tab


            $ReadID =  GUICtrlRead($Tab, 1)
            Select

              Case $ReadID = $Tab2
                  ConsoleWrite("I am here tab2 " & @crlf)

              Case $ReadID = $Tab3
                  ConsoleWrite("I am here tab3 " & @crlf)

               Case $ReadID = $Tab4
                  ConsoleWrite("I am here tab4 " & @crlf)

            EndSelect

      EndSwitch

   WEnd

EndFunc


Func BuildTabs()

    ;$Pic[0] = GUICtrlCreatePic("c:\WindowsMail.bmp", 100, 40, 1, 1)
    ;GUICtrlSetState(-1, $GUI_Disable)
    $Pic[0] = GUICtrlCreateLabel("", 80, 18, 42, 42, $SS_BLACKFRAME);

    ;$Pic[1] = GUICtrlCreatePic("c:\WindowsMail.bmp", 120, 90, 1, 1)
    ;GUICtrlSetState(-1, $GUI_Disable)
    $Pic[1] = GUICtrlCreateLabel("", 115, 85, 42, 42, $SS_BLACKFRAME)

    ;$Pic[2] = GUICtrlCreatePic("c:\WindowsMail.bmp", 160, 150, 1, 1)
    ;GUICtrlSetState(-1, $GUI_Disable)
    $Pic[2] = GUICtrlCreateLabel("", 150, 145, 42, 42, $SS_BLACKFRAME)

    ;$Pic[3] = GUICtrlCreatePic("c:\WindowsMail.bmp", 120, 280, 1, 1)
    ;GUICtrlSetState(-1, $GUI_Disable)
    $Pic[3] = GUICtrlCreateLabel("", 112, 210, 42, 42, $SS_BLACKFRAME)

    ;$Pic[4] = GUICtrlCreatePic("c:\WindowsMail.bmp", 120, 320, 1, 1)
    ;GUICtrlSetState(-1, $GUI_Disable)
    $Pic[4] = GUICtrlCreateLabel("", 111, 498, 42, 42, $SS_BLACKFRAME)

   $Tab = GUICtrlCreateTab(172 + 4, 10 + 4, 523 - 8, 149 - 8)

   $Tab1 = GUICtrlCreateTabItem('TAB1')
      GUICtrlCreateLabel("TAB 1", 250, 50, 300, 50)
      GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      GUICtrlSetcolor(-1, 0x708090)
      GUICtrlSetFont(-1, 30, 400, 0, 'Calisto MT')

   $Tab2 = GUICtrlCreateTabItem('TAB2')
      GUICtrlCreateLabel("TAB 2", 250, 50, 300, 50)
      GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      GUICtrlSetcolor(-1, 0x708090)
      GUICtrlSetFont(-1, 30, 400, 0, 'Calisto MT')

   $Tab3 = GUICtrlCreateTabItem('TAB3')
      GUICtrlCreateLabel("TAB 3", 250, 50, 300, 50)
      GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      GUICtrlSetcolor(-1, 0x708090)
      GUICtrlSetFont(-1, 30, 400, 0, 'Calisto MT')

   $Tab4 = GUICtrlCreateTabItem('TAB4')
      GUICtrlCreateLabel("TAB 4", 250, 50, 300, 50)
      GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      GUICtrlSetcolor(-1, 0x708090)
      GUICtrlSetFont(-1, 30, 400, 0, 'Calisto MT')

   $Tab5 = GUICtrlCreateTabItem('TAB5')
      GUICtrlCreateLabel("TAB 5", 250, 50, 300, 50)
      GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      GUICtrlSetcolor(-1, 0x708090)
      GUICtrlSetFont(-1, 30, 400, 0, 'Calisto MT')

EndFunc


Func _Index($CtrlID) ;Belongs to Tab GUI
    For $i = 0 To UBound($Pic) - 1
        If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
            Return $i
        EndIf
    Next
    Return -1
EndFunc   ;==>_Index

 

Share this post


Link to post
Share on other sites



I think you're trying to do this. change my example with pictures instead buttons.

#include <GUIConstantsEx.au3>
#include <GUICONSTANTS.au3>

Example()

Func Example()
    GUICreate("My GUI Tab", 400, 200)


    Local $idTab = GUICtrlCreateTab(10, 10, 380, 100)


    Local $iNTabs = 5
    Local $aIdTabs[$iNTabs]
    Local $aIdBtns[$iNTabs]

    ;Create Tabs
    For $i = 0 To $iNTabs - 1
        $aIdTabs[$i] = GUICtrlCreateTabItem("Tab - " & $i + 1)
        GUICtrlCreateLabel("Tab - " & $i + 1, 50, 50, 100)
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetColor(-1, 0x708090)
        GUICtrlSetFont(-1, 15, 400, 0, 'Calisto MT')
    Next
    GUICtrlCreateTabItem(""); end tabitem definition

    ;Create Buttons
    Local $iWidth = 70
    For $i = 0 To $iNTabs - 1
        $aIdBtns[$i] = GUICtrlCreateButton("Tab - " & $i + 1, ($i * $iWidth) + 10, 120, $iWidth, 30)
    Next

    GUISetState(@SW_SHOW)

    Local $idMsg
    Local $iTabIndex = 0
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()
        Switch $idMsg

            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aIdBtns[0] To $aIdBtns[UBound($aIdBtns) - 1]
                $iTabIndex = $idMsg - $aIdBtns[0]
                ConsoleWrite("Focus Tab Index: " & $iTabIndex + 1 & @CRLF)
                GUICtrlSendMsg($idTab, $TCM_SETCURFOCUS, $iTabIndex, 0)

            Case $idTab
                $iTabIndex = GUICtrlRead($idTab)
                ConsoleWrite("I'm in Tab: " & $iTabIndex + 1 & @CRLF)

        EndSwitch
    WEnd


EndFunc   ;==>Example

Saludos

Share this post


Link to post
Share on other sites

That looks great.  I will try and overlay this onto my script which I have clearly butchered for something I found using pictures.

 

Thanks for your excellent reply and time spent on this.

Share this post


Link to post
Share on other sites

Applied to my Gui and its working great.  Many Thanks.  I will decommission the old $pic logic.

 

Cheers

 

 

Share this post


Link to post
Share on other sites

You're welcome.

 

Saludos

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now