#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
Opt("GUIResizeMode", $GUI_DOCKBORDERS)
;当窗口调整大小时,运行此功能
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
Global $iGUIWidth = 800, $iGUIHeight = 500, $fResized = False
$MainGUI = GUICreate("Tab Row Example", $iGUIWidth, $iGUIHeight, Default, Default, _
BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
$TAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, $iGUIHeight - 50, _
BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))
;设置一些选项卡项目
Global $iTabNumber = 15
;创建数组持有虚拟标签项目标题
Global $aTitles[$iTabNumber + 1]
For $i = 1 To $iTabNumber
$aTitles[$i] = ""
For $j = 1 To Random(4, 10, 1)
$aTitles[$i] &= String($i) & " "
Next
Next
;确定初始顶端标签值
$iTabTop = Tab_Sizer($iTabNumber, $aTitles)
;创建数组,ListView 句柄
Global $aListView[$iTabNumber + 1] = [$iTabNumber]
;创建标签项目
For $i = 1 To $iTabNumber
GUICtrlCreateTabItem($aTitles[$i])
$aListView[$i] = GUICtrlCreateListView("文件清单", 10, $iTabTop, $iGUIWidth - 22, _
$iGUIHeight - $iTabTop - 50, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($aListView[$i], 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetBkColor($aListView[$i], 0xFF0000) ; 只是为了显示尺寸
GUICtrlSetResizing($aListView[$i], BitOR($GUI_DOCKBORDERS, $GUI_DOCKLEFT))
; 填写完整的项目
For $j = 1 To 25
GUICtrlCreateListViewItem("项目 " & $j & " - 清单 " & $i _
& " Blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah", $aListView[$i])
Next
Next
;关闭表定义
GUICtrlCreateTabItem("")
;创建虚拟按钮
$hButton = GUICtrlCreateButton("按钮", 10, $iGUIHeight - 40, 120, 30)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKWIDTH, $GUI_DOCKHEIGHT, $GUI_DOCKBOTTOM))
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hButton
; dummy
EndSwitch
;查找调整信息
If $fResized Then
;确定顶端标签值
$iTabTop = Tab_Sizer($iTabNumber, $aTitles)
; 复位所有标签,以适应新的标签尺寸
For $i = 1 To $aListView[0]
GUICtrlSetPos($aListView[$i], 10, $iTabTop, $iGUIWidth - 22, $iGUIHeight - $iTabTop - 50)
_GUICtrlListView_SetColumnWidth($aListView[$i], 0, $LVSCW_AUTOSIZE_USEHEADER)
Next
; 重置标签
$fResized = False
EndIf
WEnd
Func Tab_Sizer($iTabTotal, $aTabTitles)
; 创建 GUI
$TestGUI = GUICreate("", $iGUIWidth, 500)
; 创建标签
$TestTAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, 500, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))
; 建立标签项目
For $i = 1 To $iTabTotal
GUICtrlCreateTabItem($aTabTitles[$i])
Next
; 估算客户区标签
$aPos = _GUICtrlTab_GetDisplayRect(ControlGetHandle($TestGUI, "", $TestTAB))
; 删除 GUI
GUIDelete($TestGUI)
; 返回顶端标签值
Return $aPos[1]
EndFunc
Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
$iGUIWidth = BitAND($lParam, 0xFFFF)
$iGUIHeight = BitShift($lParam, 16)
; 设置标志
$fResized = True
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_SIZE