Sign in to follow this  
Followers 0
Holger

Sample: Multi Tab/Child GUI and Tabs with icons

13 posts in this topic

Hi ;)

was just for me to testing out something...

Here is the small script in which I use child windows for placing multiple tab controls on one main GUI.

! Beta version is needed (only for the icons in tabs) !

#include <GUIConstants.au3>

Global Const $TCM_SETIMAGELIST = 0x1303
Global Const $TCM_SETITEM = 0x1306

; Disable visual styles for controls
;DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

Global $hImageList = 0


$main_GUI           = GUICreate("Tab Sample", 400, 300, -1, -1);, BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPSIBLINGS))
$ok_button          = GUICtrlCreateButton("OK", 110, 270, 70, 20)
$cancel_button      = GUICtrlCreateButton("Cancel", 220, 270, 70, 20)
GUISetState()

; Creates the first child window that is implemented into the main GUI
$child1             = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child
$child1_tab         = GUICtrlCreateTab(0, 0, 370, 215)
$child1_tabitem1    = GUICtrlCreateTabItem("Child1Tab1")
$child1_tabitem2    = GUICtrlCreateTabItem("Child1Tab2")
$child1_tabitem3    = GUICtrlCreateTabItem("Child1Tab3")
GUICtrlCreateTabItem("")

GUISetState()

; Creates the second child window that is implemented into the main GUI
$child2             = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child

$child3             = GUICreate("", 210, 220, 158, 0, BitOr($WS_CHILD,$WS_TABSTOP), -1, $child2)
;GUISetBkColor(0x257788)
$listview           = GUICtrlCreateListView("Col1|Col2", 0, 2, 210, 211, BitOr($LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$WS_TABSTOP), $WS_EX_CLIENTEDGE)
GUICtrlCreateListViewItem("ItemLong1|ItemLong2", $listview)
GUICtrlCreateListViewItem("ItemLong3|ItemLong4", $listview)
GUICtrlCreateListViewItem("ItemLong5|ItemLong6", $listview)
GUISetState()

GUISwitch($child2)
$child2_tab         = GUICtrlCreateTab(0, 0, 156, 215)
$child2_tabitem1    = GUICtrlCreateTabItem("Child2Tab1")
$child2_tabitem2    = GUICtrlCreateTabItem("Child2Tab2")
GUICtrlCreateTabItem("")

; Switch back the main GUI and create the tabs
GUISwitch($main_GUI)
$main_tab           = GUICtrlCreateTab(10, 10, 380, 250)
$main_tabitem1      = GUICtrlCreateTabItem("MainTab1")
$main_tabitem2      = GUICtrlCreateTabItem("MainTab2")
GUICtrlCreateTabItem("")
GUICtrlSetState($main_tabitem1,$GUI_SHOW)

Bind_ImageList($main_tab)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $cancel_button
            ExitLoop
            
        Case $msg[0] = $main_tab
            $tabidx = GUICtrlRead($main_tab)
            Select 
                Case $tabidx = 0
                    GUISetState(@SW_HIDE, $child2)
                    GUISetState(@SW_SHOW, $child1)
            
                Case $tabidx = 1
                    GUISetState(@SW_HIDE, $child1)
                    GUISetState(@SW_SHOW, $child2)
            EndSelect
    EndSelect
WEnd

DllCall("comctl32.dll", "int", "ImageList_Destroy", "hwnd", $hImageList)
Exit



Func ImageList_Create()
    $hImageList = DllCall("comctl32.dll", "hwnd", "ImageList_Create", "int", 16, "int", 16, "int", 0x0021, "int", 0, "int", 1)
    $hImageList = $hImageList[0]
    Return $hImageList
EndFunc


Func Bind_ImageList($nCtrl)
    $hImageList = ImageList_Create()
    GUICtrlSendMsg($nCtrl, $TCM_SETIMAGELIST, 0, $hImageList)
    
    $szIconFile = "shell32.dll"

    $tcitem = DllStructCreate("uint;dword;dword;ptr;int;int;int")
    DllStructSetData($tcitem, 1, 0x0002)
    DllStructSetData($tcitem, 6, 0)
    AddImageToTab($nCtrl, 0, $tcitem, $szIconFile, 12)
    
    DllStructSetData($tcitem, 6, 1)
    AddImageToTab($nCtrl, 1, $tcitem, $szIconFile,21)
    
    DllStructDelete($tcitem)
EndFunc


Func AddImageToTab($nCtrl, $nTabIndex, $nItem, $szIconFile, $nIconID)
    $hIcon = DllStructCreate("int")
    $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szIconFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
    $result = $result[0]
    If $result > 0 Then
        DllCall("comctl32.dll", "int", "ImageList_AddIcon", "hwnd", $hImageList, "hwnd", DllStructGetData($hIcon,1))
        DllCall("user32.dll", "int", "SendMessage", "hwnd", ControlGetHandle($main_GUI, "", $nCtrl), "int", $TCM_SETITEM, "int", $nTabIndex, "ptr", DllStructGetPtr($nItem))
        DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon)
    EndIf
    
    DllStructDelete($hIcon)
EndFunc

Feel free to modify and use it :P

Regards

Holger

Share this post


Link to post
Share on other sites



Awesome Holger !!! Really useful ;)


FootbaG

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I tried it with the non-beta version and got multiple errors: Perhaps I'm missing an include or something.

C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3(94,65) : ERROR: DllStructCreate(): undefined function.
    $tcitem = DllStructCreate("uint;dword;dword;ptr;int;int;int")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3(95,40) : ERROR: DllStructSetData(): undefined function.
    DllStructSetData($tcitem, 1, 0x0002)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3(102,28) : ERROR: DllStructDelete(): undefined function.
    DllStructDelete($tcitem)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3(108,139) : ERROR: DllStructGetPtr(): undefined function.
    $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szIconFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3(111,115) : ERROR: DllStructGetData(): undefined function.
        DllCall("comctl32.dll", "int", "ImageList_AddIcon", "hwnd", $hImageList, "hwnd", DllStructGetData($hIcon,1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~^
C:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\new.au3 - 5 error(s), 0 warning(s)

Just thought you might want to know.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

I tried it with the non-beta version and got multiple errors: Perhaps I'm missing an include or something

.....

Just thought you might want to know.

<{POST_SNAPBACK}>

Just that SMALL detail: You need the beta.

DLLStruct.. functions included in the beta only.

Share this post


Link to post
Share on other sites

Nice work. This should be added the the AutoIt Example Folder/Help.

This will definitely come in handy..

Cheers.. ;)

Share this post


Link to post
Share on other sites

Gives me a dll function error...what did I do bad? :/

Also I think I have the BETA... Here's my version :$ 3.1.1.0

IS that ok?

Share this post


Link to post
Share on other sites

@Holger

Very Nice ;) !!!

@Gaboury

Beta is 3.1.1.+++, if you're using SciTE to edit, you Alt+F5 to run your script...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Really Nice Job... Holger

Thanks for sharing

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I don't understand :/ Do I have the BETA or not?! :/ Please help me, I want to try this! ;)

Share this post


Link to post
Share on other sites

No, you don't.

There's a link in my signature. The current beta version is 3.1.1.75.

Share this post


Link to post
Share on other sites

Thanks Saunders ;) Valuater explained everything to me in PM... Now it works :P

Thanks a lot to you 2! :mad2:

Share this post


Link to post
Share on other sites

Updated to Beta 3.2.9.14

#include <GUIConstants.au3>

;Global Const $TCM_SETIMAGELIST = 0x1303
;Global Const $TCM_SETITEM = 0x1306

; Disable visual styles for controls
;DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

Global $hImageList = 0


$main_GUI            = GUICreate("Tab Sample", 400, 300, -1, -1);, BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPSIBLINGS))
$ok_button            = GUICtrlCreateButton("OK", 110, 270, 70, 20)
$cancel_button        = GUICtrlCreateButton("Cancel", 220, 270, 70, 20)
GUISetState()

; Creates the first child window that is implemented into the main GUI
$child1                = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child
$child1_tab            = GUICtrlCreateTab(0, 0, 370, 215)
$child1_tabitem1    = GUICtrlCreateTabItem("Child1Tab1")
$child1_tabitem2    = GUICtrlCreateTabItem("Child1Tab2")
$child1_tabitem3    = GUICtrlCreateTabItem("Child1Tab3")
GUICtrlCreateTabItem("")

GUISetState()

; Creates the second child window that is implemented into the main GUI
$child2                = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child

$child3                = GUICreate("", 210, 220, 158, 0, BitOr($WS_CHILD,$WS_TABSTOP), -1, $child2)
;GUISetBkColor(0x257788)
$listview            = GUICtrlCreateListView("Col1|Col2", 0, 2, 210, 211, BitOr($LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$WS_TABSTOP), $WS_EX_CLIENTEDGE)
GUICtrlCreateListViewItem("ItemLong1|ItemLong2", $listview)
GUICtrlCreateListViewItem("ItemLong3|ItemLong4", $listview)
GUICtrlCreateListViewItem("ItemLong5|ItemLong6", $listview)
GUISetState()

GUISwitch($child2)
$child2_tab            = GUICtrlCreateTab(0, 0, 156, 215)
$child2_tabitem1    = GUICtrlCreateTabItem("Child2Tab1")
$child2_tabitem2    = GUICtrlCreateTabItem("Child2Tab2")
GUICtrlCreateTabItem("")

; Switch back the main GUI and create the tabs
GUISwitch($main_GUI)
$main_tab            = GUICtrlCreateTab(10, 10, 380, 250)
$main_tabitem1        = GUICtrlCreateTabItem("MainTab1")
$main_tabitem2        = GUICtrlCreateTabItem("MainTab2")
GUICtrlCreateTabItem("")
GUICtrlSetState($main_tabitem1,$GUI_SHOW)

Bind_ImageList($main_tab)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $cancel_button
            ExitLoop
            
        Case $msg[0] = $main_tab
            $tabidx = GUICtrlRead($main_tab)
            Select
                Case $tabidx = 0
                    GUISetState(@SW_HIDE, $child2)
                    GUISetState(@SW_SHOW, $child1)
            
                Case $tabidx = 1
                    GUISetState(@SW_HIDE, $child1)
                    GUISetState(@SW_SHOW, $child2)
            EndSelect
    EndSelect
WEnd

DllCall("comctl32.dll", "int", "ImageList_Destroy", "hwnd", $hImageList)
Exit



Func ImageList_Create()
    $hImageList = DllCall("comctl32.dll", "hwnd", "ImageList_Create", "int", 16, "int", 16, "int", 0x0021, "int", 0, "int", 1)
    $hImageList = $hImageList[0]
    Return $hImageList
EndFunc


Func Bind_ImageList($nCtrl)
    $hImageList = ImageList_Create()
    GUICtrlSendMsg($nCtrl, $TCM_SETIMAGELIST, 0, $hImageList)
    
    $szIconFile = "shell32.dll"

    $tcitem = DllStructCreate("uint;dword;dword;ptr;int;int;int")
    DllStructSetData($tcitem, 1, 0x0002)
    DllStructSetData($tcitem, 6, 0)
    AddImageToTab($nCtrl, 0, $tcitem, $szIconFile, 12)
    
    DllStructSetData($tcitem, 6, 1)
    AddImageToTab($nCtrl, 1, $tcitem, $szIconFile,21)
    
    $tcitem = 0
EndFunc


Func AddImageToTab($nCtrl, $nTabIndex, $nItem, $szIconFile, $nIconID)
    $hIcon = DllStructCreate("int")
    $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szIconFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
    $result = $result[0]
    If $result > 0 Then
        DllCall("comctl32.dll", "int", "ImageList_AddIcon", "hwnd", $hImageList, "hwnd", DllStructGetData($hIcon,1))
        DllCall("user32.dll", "int", "SendMessage", "hwnd", ControlGetHandle($main_GUI, "", $nCtrl), "int", $TCM_SETITEM, "int", $nTabIndex, "ptr", DllStructGetPtr($nItem))
        DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon)
    EndIf
    
   $hIcon = 0
EndFunc

8)


NEWHeader1.png

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
Sign in to follow this  
Followers 0