|
本帖最后由 jevonleen 于 2012-5-31 19:49 编辑
自己解决了滚动控制条自动居上的问题,在帮助文档看到了这个函数:_GUIScrollBars_SetScrollInfoPos($hWnd, $fnBar, $nPos).同时谢谢user3000!
利用分页标签切换页面,但各标签垂直高度不同,如何通过点击按钮重设置滚动控制条高度,并让滚动条居上?
例如以下代码,我想在显示TAB1的时候,滚动控制条高度为62,在显示TAB2的时候,滚动控制条高度为31,并且切换到不同标签页面时,让滚动控制和自动居上!
我不是申手党,在论坛搜了很久,也百度了很长时间,但始终解决不了!请高手帮我修正一下代码,谢谢!#include <ScrollBarConstants.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <GUIListBox.au3>
Dim $a = 31
$Form1 = GUICreate("Scrollbars", 500, 300)
GUISetBkColor(0xF4F5F7,$Form1)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($Form1, 0, $a)
;-----------------------------------------------------------------------------------------------
GUICtrlCreateTab(0, 0, 300, 200)
$tab1 = GUICtrlCreateTabItem("tab1")
$tabpic1 = GUICtrlCreatePic(@ScriptDir & '\img4.jpg',0,22,0,0);62
$tab2 = GUICtrlCreateTabItem("tab2")
$tabpic2 = GUICtrlCreatePic(@ScriptDir & '\img5.jpg',0,22,0,0);31
GUICtrlCreateTabItem("")
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $tab1
$a = 62
Case $tab2
$a = 31
EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) ;设置垂直滚动条
#forceref $Msg, $wParam, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
;获取所有垂直滚动条信息
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
;为稍后进行比较保存位置
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ;点击HOME键盘键
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ;点击END键盘键
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ;点击顶端箭头
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ;点击底部箭头
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ;点击滚动箱上端的快速滚动
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ;点击滚动箱上端的快速滚动
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ;拖动滚动箱
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
;~ // 设置位置然后修正它. 由于窗口的调整可能会和设置的值不同.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// 如果位置改变, 滚动窗口并升级
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) ;设置窗口尺寸
#forceref $Msg, $wParam
Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$xClientMax = $aSB_WindowInfo[$index][1]
$xChar = $aSB_WindowInfo[$index][2]
$yChar = $aSB_WindowInfo[$index][3]
$ivMax = $aSB_WindowInfo[$index][7]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
;修正客户区域尺寸
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index][4] = $xClient
$aSB_WindowInfo[$index][5] = $yClient
;设置垂直滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", $ivMax)
DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;设置水平滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar)
DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
Return $GUI_RUNDEFMSG
EndFunc
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|