本帖最后由 水木子 于 2015-11-30 16:17 编辑
哦!是吗!afan前辈说的那个帖子我还没来得及看,这是我根据你的要求写的。
以前也没有写过关于滚动条的东西,看你提问,我正好也对这个有兴趣,所以就试试呗!
思路比较简单,就是在Tab中内嵌子窗口,然后给子窗口添加滚动条。
代码如下,希望对你有帮助。
#include <GuiTab.au3>
#include 'GUIScrollbars_Ex.au3'
$MyGui0 = GUICreate('标签页控件 GUI', 800, 400)
GUISetFont(9)
$Tab = GUICtrlCreateTab(10, 10, 780, 380)
_GUICtrlTab_SetMinTabWidth($Tab, 80)
$TabItem1 = GUICtrlCreateTabItem('第一页')
$Button1_1 = GUICtrlCreateButton('测试按钮1-1', 420, 350, 85, 25)
$TabItem2 = GUICtrlCreateTabItem('第二页')
$Button2_1 = GUICtrlCreateButton('测试按钮2-1', 420, 350, 85, 25)
$Button2_2 = GUICtrlCreateButton('测试按钮2-2', 550, 350, 85, 25)
$TabItem3 = GUICtrlCreateTabItem('第三页')
$Button3_1 = GUICtrlCreateButton('测试按钮3-1', 420, 350, 85, 25)
$Button3_2 = GUICtrlCreateButton('测试按钮3-2', 550, 350, 85, 25)
$Button3_3 = GUICtrlCreateButton('测试按钮3-3', 680, 350, 85, 25)
GUICtrlCreateTabItem('')
Global $aCtrlCount1[20]
Global $iNumber = 4
Global $iSpacingX = 200, $iSpacingY = 50
$MyGui1 = GUICreate('', 776, 300, 11, 31, $WS_POPUP, $WS_EX_MDICHILD, $MyGui0)
For $i = 0 To UBound($aCtrlCount1) - 1
$aCtrlCount1[$i] = GUICtrlCreateCheckbox('复选框 1 - ' & $i + 1, $iSpacingX * Mod($i, $iNumber) + 30, $iSpacingY * Floor($i / $iNumber) + 40, 100, 20)
Next
GUICtrlCreateGroup('组框 1 - 1', 10, 10, 740, UBound($aCtrlCount1) * 12.5 + 40)
If UBound($aCtrlCount1) > 20 Then _GUIScrollbars_Generate($MyGui1, 0, UBound($aCtrlCount1) * 12.5 + 40, 0, 0, True)
Global $aCtrlCount2[50]
$MyGui2 = GUICreate('', 776, 300, 11, 31, $WS_POPUP, $WS_EX_MDICHILD, $MyGui0)
For $i = 0 To UBound($aCtrlCount2) - 1
$aCtrlCount2[$i] = GUICtrlCreateCheckbox('复选框 2 - ' & $i + 1, $iSpacingX * Mod($i, $iNumber) + 30, $iSpacingY * Floor($i / $iNumber) + 40, 100, 20)
Next
GUICtrlCreateGroup('组框 2 - 1', 10, 10, 740, UBound($aCtrlCount2) * 12.5 + 40)
If UBound($aCtrlCount2) > 20 Then _GUIScrollbars_Generate($MyGui2, 0, UBound($aCtrlCount2) * 12.5 + 40, 0, 0, True)
Global $aCtrlCount3[100]
$MyGui3 = GUICreate('', 776, 300, 11, 31, $WS_POPUP, $WS_EX_MDICHILD, $MyGui0)
For $i = 0 To UBound($aCtrlCount3) - 1
$aCtrlCount3[$i] = GUICtrlCreateCheckbox('复选框 3 - ' & $i + 1, $iSpacingX * Mod($i, $iNumber) + 30, $iSpacingY * Floor($i / $iNumber) + 40, 100, 20)
Next
GUICtrlCreateGroup('组框 3 - 1', 10, 10, 740, UBound($aCtrlCount3) * 12.5 + 40)
If UBound($aCtrlCount3) > 20 Then _GUIScrollbars_Generate($MyGui3, 0, UBound($aCtrlCount3) * 12.5 + 40, 0, 0, True)
GUISetState(@SW_SHOW, $MyGui1)
GUISetState(@SW_SHOW, $MyGui0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1_1
MsgBox(0, 0, 'Test')
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab
$hWndTab = GUICtrlGetHandle($Tab)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTab
Switch $iCode
Case $NM_CLICK
$iTabItemIndex = _GUICtrlTab_GetCurFocus($hWndTab)
Switch $iTabItemIndex
Case 0
GUISetState(@SW_HIDE, $MyGui2)
GUISetState(@SW_HIDE, $MyGui3)
GUISetState(@SW_SHOW, $MyGui1)
Case 1
GUISetState(@SW_HIDE, $MyGui1)
GUISetState(@SW_HIDE, $MyGui3)
GUISetState(@SW_SHOW, $MyGui2)
Case 2
GUISetState(@SW_HIDE, $MyGui1)
GUISetState(@SW_HIDE, $MyGui2)
GUISetState(@SW_SHOW, $MyGui3)
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
附上UDF函数,不好意思,我已经忘了出处了,感谢作者!
顺便提一下,_GUIScrollbars_Generate 这个函数也可以创建水平滚动条。
|