找回密码
 加入
搜索
查看: 4572|回复: 6

[图形处理] 如何实现图片控件超过窗口,窗口有滚动条?

  [复制链接]
发表于 2010-8-18 18:44:04 | 显示全部楼层 |阅读模式
本帖最后由 itljl 于 2010-8-19 13:06 编辑



如图在编辑器中是可以实现的,把代码生成后就不行了.

曾经试过论坛的一种方式,首先是设置GUI的样式,然后注册一些消息. 这种方法只能对对创建时图片控件的大小来正确显示滚动条.但重设一次图片控件,改变图片控件的大小后,滚动条就不准了.

谁有更好的办法吗?谢谢.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2010-8-18 19:16:38 | 显示全部楼层
示例,当改变控件大小后,窗口滚动条不能正确显示
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

$hGUI = GUICreate("ScrollBar Example", 400, 400, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUISetBkColor(0x000000)

$Pic1 = GUICtrlCreatePic("C:\001.JPG", 8, 8, 480, 100)

;~ GUISwitch($hGUI)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

GUISetState()

_GUIScrollBars_Init($hGUI)

MsgBox(0, 0, 0)
GUICtrlSetPos($Pic1, -1, -1, 1680, 1050)
GUICtrlSetImage($Pic1, "C:\002.JPG")
GUISwitch($hGUI)
_GUIScrollBars_Init($hGUI)

While 1
        $GUIMsg = GUIGetMsg()

        Switch $GUIMsg
                Case $GUI_EVENT_CLOSE
                        ExitLoop
        EndSwitch
WEnd

Exit


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)

        ; Retrieve the dimensions of the client area.
        $xClient = BitAND($lParam, 0x0000FFFF)
        $yClient = BitShift($lParam, 16)
        $aSB_WindowInfo[$index][4] = $xClient
        $aSB_WindowInfo[$index][5] = $yClient

        ; Set the vertical scrolling range and page size
        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)

        ; Set the horizontal scrolling range and page size
        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   ;==>WM_SIZE

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
        #forceref $Msg, $lParam
        Local $nScrollCode = BitAND($wParam, 0x0000FFFF)

        Local $index = -1, $xChar, $xPos
        Local $Min, $Max, $Page, $Pos, $TrackPos

        For $x = 0 To UBound($aSB_WindowInfo) - 1
                If $aSB_WindowInfo[$x][0] = $hWnd Then
                        $index = $x
                        $xChar = $aSB_WindowInfo[$index][2]
                        ExitLoop
                EndIf
        Next
        If $index = -1 Then Return 0

;~         ; Get all the horizontal scroll bar information
        Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
        $Min = DllStructGetData($tSCROLLINFO, "nMin")
        $Max = DllStructGetData($tSCROLLINFO, "nMax")
        $Page = DllStructGetData($tSCROLLINFO, "nPage")
        ; Save the position for comparison later on
        $xPos = DllStructGetData($tSCROLLINFO, "nPos")
        $Pos = $xPos
        $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
        #forceref $Min, $Max
        Switch $nScrollCode

                Case $SB_LINELEFT ; user clicked left arrow
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

                Case $SB_LINERIGHT ; user clicked right arrow
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

                Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

                Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)

                Case $SB_THUMBTRACK ; user dragged the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
        EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

        DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
        _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
        _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
        ;// If the position has changed, scroll the window and update it
        $Pos = DllStructGetData($tSCROLLINFO, "nPos")
        If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HSCROLL

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


        ; Get all the vertial scroll bar information
        Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
        $Min = DllStructGetData($tSCROLLINFO, "nMin")
        $Max = DllStructGetData($tSCROLLINFO, "nMax")
        $Page = DllStructGetData($tSCROLLINFO, "nPage")
        ; Save the position for comparison later on
        $yPos = DllStructGetData($tSCROLLINFO, "nPos")
        $Pos = $yPos
        $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

        Switch $nScrollCode
                Case $SB_TOP ; user clicked the HOME keyboard key
                        DllStructSetData($tSCROLLINFO, "nPos", $Min)

                Case $SB_BOTTOM ; user clicked the END keyboard key
                        DllStructSetData($tSCROLLINFO, "nPos", $Max)

                Case $SB_LINEUP ; user clicked the top arrow
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

                Case $SB_LINEDOWN ; user clicked the bottom arrow
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

                Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

                Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)

                Case $SB_THUMBTRACK ; user dragged the scroll box
                        DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
        EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

        DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
        _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
        _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
        ;// If the position has changed, scroll the window and update it
        $Pos = DllStructGetData($tSCROLLINFO, "nPos")

        If ($Pos <> $yPos) Then
                _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
                $yPos = $Pos
        EndIf

        Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL
发表于 2010-8-19 12:21:49 | 显示全部楼层
谢谢,正用
 楼主| 发表于 2010-8-20 14:50:38 | 显示全部楼层
谢谢,正用
andersonljw 发表于 2010-8-19 12:21

有问题啊,还用?
发表于 2010-8-20 15:03:03 | 显示全部楼层
这个滚动条不准~ 还差很远
发表于 2010-8-21 17:56:43 | 显示全部楼层
借鉴部分 还是有用
发表于 2010-9-6 09:20:54 | 显示全部楼层
回复 4# itljl


    用一部分即可
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 13:47 , Processed in 0.080224 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表