多TAB 实现
玩多TAB 有一段事件了 最近在官网上找到了几个好用的例子发给大家 #include <GUIConstants.au3>#include <WindowsConstants.au3>
#include <ListviewConstants.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 = $GUI_EVENT_CLOSE Or $msg = $cancel_button
ExitLoop
Case $msg = $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
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
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
代码有点乱 但是 意思是达到了
第二个看来比较直观
Func _GUICtrlCreateTabChild($hMainHwnd, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $nStyle = 0x80000000, $nStyleEX = 0x00000040)
Local $aControls
$aControls = GUICreate('', $iWidth, $iHeight, $iLeft, $iTop, $nStyle, $nStyleEX, $hMainHwnd)
$aControls = GUICtrlCreateTab(0, 0, $iWidth, $iHeight, BitOr($TCS_HOTTRACK, $TCS_TOOLTIPS, $TCS_MULTILINE))
Return $aControls ; Returns an Array = ChildHwnd = Tab Control ID
EndFunc
一段GUI代码结束 一定要用
GUISetState(@SW_SHOW, $cInformationTab) 显示
比如
$Form1_1 = GUICreate("123", 837, 601)
$cInformationTab = _GUICtrlCreateTabChild($Form1_1, 258, 28, 577, 530, BitOR($WS_CHILD, $WS_TABSTOP, $TCS_MULTILINE), $WS_EX_ACCEPTFILES)
GUICtrlCreateTabItem("普通")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW, $cInformationTab)
GUISetState(@SW_SHOW, $Form1_1)
代码没测试 只是 意思下 嘿嘿 大家懂都可以了 自己看把 顺便骂下鸟东 什么时候出教程 哈哈 效果那是相关的爽,就是用起来太过烦琐.....以前也找到过这个,不过太麻烦了,没用上.... 确实很繁琐!不过还是可以考虑用的!呵呵~不用多窗口显示了!支持! 呵呵,用你的例子做了一个出来!方便多了!
不用多窗口!
[ 本帖最后由 破帽遮颜 于 2008-7-27 15:11 编辑 ] 看到头晕晕的。 继续努力....努力能快点用上这个.HOHO 能不能单独设置 Child1Tab 那一行的宽度和高度?偏小了不好看。 看看能不能用....:face (29): :face (29): 测试下。辛苦了。 那怎么能叫有点繁琐呢?
哪是相当繁琐!
我还是用自带的gui设计工具做吧 呵呵 楼上好牛X的一个AD
:face (35): 原帖由 bob 于 2009-2-20 15:59 发表 http://www.autoitx.com/images/common/back.gif
楼上好牛X的一个AD
:face (35):
本来看到想屏蔽的,当做奇文共赏好了。这个还是枪得能骗到不少S13的。 支持一把了,谢谢你了. 支持一把了,谢谢你了. 如果寒暄只是打个招呼就了事的话,那与猴子的呼叫声有什么不同呢? 事实上,正确的寒暄必须在短短一句话中明显地表露出你对他的关怀。
页:
[1]
2