Jump to content
Sign in to follow this  
PhoenixXL

Custom Scrollbar

Recommended Posts

PhoenixXL

I have already made a regarding the same issue. But its old enough to start the discussion again there.
I wanted to have a custom scrollbar for an edit control. This is the script, it works as required.

CScrollBar

#include-once
#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPIEx.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <Misc.au3>
#include <GUIEdit.au3>
#include <Array.au3>

Global $iWidth_VSCROLL = _WinAPI_GetSystemMetrics($SM_CXVSCROLL)
Global $hGraphic, $hGraphicGUI, $hBMPBuff

;Double-Click
Global $iDoubleClickTime = DllCall("user32.dll", "uint", "GetDoubleClickTime")
$iDoubleClickTime = $iDoubleClickTime[0]

;User-Custom Messages
Global $WM_UPDATETHUMB = $WM_APP + 11 ;Called when the height of the thumb has to be changed.
Global $WM_THUMBMOVE = $WM_APP + 12 ;Called when the Thumb has been clicked
Global $WM_ARROWDOWN = $WM_APP + 13 ;Called when the Arrow buttons have been clicked.
Global $WM_PAINTSCROLLBAR = $WM_APP + 14 ;Implements the painting of the scroll bar over the NC area of the EditBox.

Global Const $tagNCCALCSIZE_PARAMS = $tagRECT & ";" & $tagRECT & ";" & $tagRECT & ";ptr PWINDOWPOS"

; Register callback function and obtain handle to _New_WndProc
Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam")
; Get pointer to _New_WndProc
Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc)

Global $___cEdit ; Handle of the Edit
Global $___pOld_WndProc ; Old Window Procedure's Address

_GDIPlus_Startup()

Global $hPen = _GDIPlus_PenCreate(0xAAFCD667, 2), _
        $hBrush = _GDIPlus_BrushCreateSolid(0xAAFCD667), _
        $hFormat = _GDIPlus_StringFormatCreate(), _
        $hFamily = _GDIPlus_FontFamilyCreate("Wingdings"), _
        $hPath = _GDIPlus_PathCreate()

Func Startup_CustomScrollBar($hEdit)


    $___cEdit = $hEdit ;get the handle of the edit
    $___pOld_WndProc = _SubClass($hEdit, $___pNew_WndProc) ;store the old WndProc

    ;post a WM_NCCALCSIZE msg.
    _WinAPI_SetWindowPos($hEdit, Default, Default, Default, Default, Default, $SWP_FRAMECHANGED)

EndFunc   ;==>Startup_CustomScrollBar

Func Shutdown_CustomScrollBar();Mem Release

    ;unsubclass the control
    _SubClass($___cEdit, $___pOld_WndProc)

    ;dispose the resources
    _Gdiplus_PathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_StringFormatDispose($hFormat)

    _GDIPlus_FontFamilyDispose($hFamily)

    DllCallbackFree($___hNew_WndProc)
EndFunc   ;==>Shutdown_CustomScrollBar

;The path of the Top Arrow button
;This could be rotated to obtain the Bottom Arrow button's path.
Func TopBtn_Path(ByRef $hPath, $iX, $iY, $iSide)
    ;* Not required when the path is in order.
    _GDIPlus_PathStartFigure($hPath) ;*
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX + $iSide, $iY)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX, $iY)
    _GDIPlus_PathAddLine($hPath, $iX, $iY, $iX, $iY + $iSide)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iSide / 2, $iSide, $iSide, 180, 180)
    _GDIPlus_PathCloseFigure($hPath) ;*
EndFunc   ;==>TopBtn_Path

;The Path of the Thumb
Func ThumbBtn_Path(ByRef $hPath, $iX, $iY, $iHeight, $iSide)

    ;* Not required when the path is in order.
    _GDIPlus_PathStartFigure($hPath) ;*
    _GDIPlus_PathAddLine($hPath, $iX, $iY, $iX, $iY + $iHeight)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - $iSide / 2, $iSide, $iSide, 180, -180)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iHeight, $iX + $iSide, $iY)
    _GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, 180)
    _GDIPlus_PathCloseFigure($hPath) ;*

EndFunc   ;==>ThumbBtn_Path

Func _SubClass($hWnd, $pNew_WindowProc)
    Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc)
    If @error Then Return SetError(1, 0, 0)
    If $iRes = 0 Then Return SetError(1, 0, 0)
    Return SetError(0, 0, $iRes)
EndFunc   ;==>_SubClass

;The new window procedure of the edit control.
Func _New_WndProc($hWnd, $iMsg, $wParam, $lParam)
    Static $aRegion[3], $i_Thumb_Height = -1, $i_TrackHeight, $iY_Thumb = -1, $iPixel_Per_Line_Scale = 1, $iThumb_Pic = 0, $iTrack_Pic = 0

    Static $hDC, $hGfx

    Switch $iMsg

        Case $WM_NCCALCSIZE

            $tNCCALCSIZE_PARAMS = DllStructCreate($tagNCCALCSIZE_PARAMS, $lParam)

            DllStructSetData($tNCCALCSIZE_PARAMS, 1, DllStructGetData($tNCCALCSIZE_PARAMS, 1) + 2)
            DllStructSetData($tNCCALCSIZE_PARAMS, 2, DllStructGetData($tNCCALCSIZE_PARAMS, 2) + 2)
            DllStructSetData($tNCCALCSIZE_PARAMS, 3, DllStructGetData($tNCCALCSIZE_PARAMS, 3) - 2 - $iWidth_VSCROLL) ;Space for VSCROLL Bar
            DllStructSetData($tNCCALCSIZE_PARAMS, 4, DllStructGetData($tNCCALCSIZE_PARAMS, 4) - 2)

            Return 0

        Case $WM_NCPAINT

            ;the first draw.
            If $i_Thumb_Height = -1 Then _SendMessage($hWnd, $WM_UPDATETHUMB, 0, 0)


        Case $WM_PAINTSCROLLBAR

            $iRet = _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, _
                    $wParam, $lParam)

            $iWidth = _WinAPI_GetWindowWidth($hWnd) - _WinAPI_GetClientWidth($hWnd) - 4
            $iHeight = _WinAPI_GetClientHeight($hWnd)

            ;Set the Range
            SetInRange($i_Thumb_Height, 15, $i_TrackHeight)
            SetInRange($iY_Thumb, 0, $i_TrackHeight - $i_Thumb_Height)

            $hHbmp = hHbmp_ScrollButtons_And_Track($iWidth, $iHeight, 0xFF000000 + GUICtrlGetBkColor($hWnd, _WinAPI_GetClientWidth($hWnd), $iHeight), $aRegion, _Iif($iY_Thumb < 0, 0, $iY_Thumb), $i_Thumb_Height) ;
            GUICtrlSendMsg($iTrack_Pic, 370, $IMAGE_BITMAP, $hHbmp) ;370 = $STM_SETBITMAP
            _WinAPI_DeleteObject($hHbmp)

            _WinAPI_EmptyWorkingSet()

            Return $iRet

        Case $WM_NCHITTEST

            $tPoint = DllStructCreate($tagPoint)
            DllStructSetData($tPoint, 1, _WinAPI_LoWord($lParam))
            DllStructSetData($tPoint, 2, _WinAPI_HiWord($lParam))
            _WinAPI_ScreenToClient($hWnd, $tPoint)

            $tRect = Return_CLientRect($hWnd)
            If _WinAPI_PtInRect($tRect, $tPoint) Then Return $HTBORDER

        Case $WM_NCLBUTTONDOWN

            $tPoint = _WinAPI_GetMousePos(True, $hWnd)

            If _GDIPlus_RegionIsVisiblePoint($aRegion[0], DllStructGetData($tPoint, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint, 2) - 2, $hGfx) Then

                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $SB_LINEUP, 0)

            ElseIf _GDIPlus_RegionIsVisiblePoint($aRegion[1], DllStructGetData($tPoint, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint, 2) - 2, $hGfx) Then

                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $SB_LINEDOWN, 1)

            ElseIf _GDIPlus_RegionIsVisiblePoint($aRegion[2], DllStructGetData($tPoint, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint, 2) - 2, $hGfx) Then

                _WinAPI_PostMessage($hWnd, $WM_THUMBMOVE, 0, 0)

            Else

                $tRect = Return_CLientRect($hWnd)
                If _WinAPI_PtInRect($tRect, $tPoint) Then

                    $iY_Thumb = DllStructGetData($tPoint, 2) - (($i_Thumb_Height / 2) + ($iWidth_VSCROLL - 2))
                    $iLine_Scroll = Floor(($iY_Thumb / $iPixel_Per_Line_Scale))
                    $iLine_Scroll_Count = $iLine_Scroll - _GUICtrlEdit_GetFirstVisibleLine($hWnd)
                    _SendMessage($hWnd, $EM_LINESCROLl, 0, $iLine_Scroll_Count)
                    _SendMessage($hWnd, $WM_PAINTSCROLLBAR, 0, 0)

                EndIf
            EndIf

        Case $WM_CHAR, $WM_UNDO, $EM_UNDO, $WM_HOTKEY
            _WinAPI_PostMessage($hWnd, $WM_UPDATETHUMB, 0, 0)

        Case $WM_SIZE, $WM_SIZING
            $iRet = _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, _
                    $wParam, $lParam)
            $aPos = ControlGetPos("", "", $hWnd)

            If $iTrack_Pic Then
                GUICtrlSetPos($iTrack_Pic, $aPos[0] + 2 + _WinAPI_GetClientWidth($hWnd), $aPos[1] + 2, $iWidth_VSCROLL, _WinAPI_GetClientHeight($hWnd))
            Else
                $iTrack_Pic = GUICtrlCreatePic("", $aPos[0] + 2 + _WinAPI_GetClientWidth($hWnd), $aPos[1] + 2, $iWidth_VSCROLL, _WinAPI_GetClientHeight($hWnd))
                GUICtrlSetBkColor(-1, 0)
            EndIf

            _SendMessage($hWnd, $WM_UPDATETHUMB)

            If $hDC Then ;release the old ones
                _GDIPlus_GraphicsDispose($hGfx)
                _WinAPI_ReleaseDC($hDC, $hWnd)
            EndIf

            ;update the new graphics and DC
            $hDC = _WinAPI_GetWindowDC($hWnd)
            $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)

            Return $iRet

        Case $WM_KEYDOWN

            Switch $wParam

                Case $VK_DOWN, $VK_UP, $VK_PRIOR, $VK_NEXT ;Down
                    $iRet = _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, _
                            $wParam, $lParam)
                    _SendMessage($hWnd, $WM_UPDATETHUMB)
                    Return $iRet

                Case $VK_END, $VK_HOME
                    If _IsPressed("11") Then ;CTRL Pressed

                        _SendMessage($hWnd, $WM_VSCROLL, _WinAPI_MakeLong($SB_BOTTOM + $VK_END - $wParam, 0))

                        $iY_Thumb = _Iif($wParam = $VK_END, $i_TrackHeight - $i_Thumb_Height, 0)

                        ;Redraw the window, _Winapi_RedrawWindow didn't work
                        _SendMessage($hWnd, $WM_PAINTSCROLLBAR)

                    EndIf
            EndSwitch

        Case $WM_MOUSEWHEEL

            $iDelta = _WinAPI_HiWord($wParam)
            $iCount = Abs($iDelta) / 120

            For $i = 1 To $iCount

                _SendMessage($hWnd, $WM_ARROWDOWN, _Iif($iDelta > 0, $SB_LINEUP, $SB_LINEDOWN), -$iDelta)

            Next

        Case $WM_UPDATETHUMB

            ;Calculate the required vars
            $i_LineCount = _GUICtrlEdit_GetLineCount($hWnd)
            $i_ScrollBarHeight = _WinAPI_GetClientHeight($hWnd)
            $i_LineHeight = GetLineHeight($hWnd)
            $iMax_LineVisible = Floor($i_ScrollBarHeight / $i_LineHeight)
            $i_PageHeight = $i_LineCount * $i_LineHeight
            $i_TrackHeight = $i_ScrollBarHeight - (2 * ($iWidth_VSCROLL - 2))
            $i_CurLine = _GUICtrlEdit_GetFirstVisibleLine($hWnd)

            ;Set the Thumb size
            $i_Thumb_Height = $i_TrackHeight * ($iMax_LineVisible * $i_LineHeight / $i_PageHeight)


            ;Set the Scale
            $iPixel_Per_Line_Scale = ($i_TrackHeight - $i_Thumb_Height) / ($i_LineCount - $iMax_LineVisible)

            ;Set the Thumb Pos
            $iY_Thumb = (($i_CurLine / ($i_LineCount - $iMax_LineVisible)) * ($i_TrackHeight - $i_Thumb_Height))

            ;Redraw the window, _Winapi_RedrawWindow didn't work
            _SendMessage($hWnd, $WM_PAINTSCROLLBAR, 0, 0)


        Case $WM_THUMBMOVE
            $iLine_InPage = _WinAPI_GetClientHeight($hWnd) / GetLineHeight($hWnd)
            $Y_Offset = _WinAPI_GetMousePosY(True, $hWnd) - $iY_Thumb
            $iY_Thumb_Prev = $iY_Thumb
            Local $iOutofBounds = False

            While _IsPressed("01")
                $Mouse_Y = _WinAPI_GetMousePosY(True, $hWnd)

                #cs - need to be improved
                    Select  ;halt if out of bounds
                    Case $Mouse_Y < $Y_Offset Or $Mouse_Y - $Y_Offset > $i_TrackHeight - $i_Thumb_Height

                    Switch $iOutofBounds
                    Case True
                    Sleep(10)
                    ContinueLoop

                    Case False
                    $iOutofBounds = True
                    EndSwitch

                    EndSelect
                #ce

                Switch $Mouse_Y - $Y_Offset ;pause if mouse isn't moved
                    Case $iY_Thumb

                        Sleep(10)
                        ContinueLoop

                    Case Else

                        $iY_Thumb = $Mouse_Y - $Y_Offset
                        $iOutofBounds = True
                        $iLine_Scroll = Floor(($iY_Thumb / $iPixel_Per_Line_Scale))
                        $iLine_Scroll_Count = $iLine_Scroll - _GUICtrlEdit_GetFirstVisibleLine($hWnd)
                        _SendMessage($hWnd, $EM_LINESCROLl, 0, $iLine_Scroll_Count)
                        _SendMessage($hWnd, $WM_PAINTSCROLLBAR)

                        Sleep(20)
                EndSwitch

            WEnd

        Case $WM_ARROWDOWN

            ;lParam = +ve : Down Arrow lParam = -ve : Up Arrow
            Local $iDirection = $wParam
            If $wParam = 0 Then $iDirection = _Iif($lParam > 0, $SB_LINEDOWN, $SB_LINEUP)
            _GUICtrlEdit_Scroll($hWnd, $iDirection)

            $iY_Thumb = _Iif($lParam > 0, $iY_Thumb + $iPixel_Per_Line_Scale, $iY_Thumb - $iPixel_Per_Line_Scale)

            _SendMessage($hWnd, $WM_PAINTSCROLLBAR, 0, 0)

            ;Continuous dragging
            Static $i_Start_Drag = False

            If _IsPressed("01") And $i_Start_Drag = False Then
                $iTimer = TimerInit()

                While _IsPressed("01")
                    If TimerDiff($iTimer) >= $iDoubleClickTime Then
                        $i_Start_Drag = True
                        ExitLoop
                    EndIf
                WEnd
            EndIf

            If _IsPressed("01") Then
                Sleep(15)
                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $wParam, $lParam)
            Else
                $i_Start_Drag = False
            EndIf



    EndSwitch

    ; Pass to the Original Window Procedure.
    Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, _
            $wParam, $lParam)
EndFunc   ;==>_New_WndProc

Func hHbmp_ScrollButtons_And_Track($iWidth, $iHeight, $iBkColor, ByRef $aRegion, $iThumb_Y, $iThumb_Height)

    If $iHeight < 2 * ($iWidth_VSCROLL - 2) Then Return 0

    Local $hFont = _GDIPlus_FontCreate($hFamily, $iWidth_VSCROLL / 2 - 1, 2)

    ;Image Containing the Scroll Bar
    $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    $hGfx_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx_Bmp, 2)
    _GDIPlus_GraphicsClear($hGfx_Bmp, $iBkColor) ;Set Bkcolor of the Bmp to that of the Edit

    #cs - Doesn't work as expected
        ;Invalidate and erase the part of the edit containing ScrollBar.
        $tRect = Return_CLientRect($hWnd, $iX, $iY, $iX + $iWidth, $iY + $iHeight)
        _WinAPI_RedrawWindow($hWnd, $tRect, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))
    #ce

    _Gdiplus_PathReset($hPath)

    ;Top Button
    TopBtn_Path($hPath, 0, 1, $iWidth_VSCROLL - 2)
    $aRegion[0] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath) ;The Curve part

    _Gdiplus_PathReset($hPath)

    ;Bottom Button
    TopBtn_Path($hPath, 0, $iHeight - $iWidth_VSCROLL + 1, $iWidth_VSCROLL - 2)
    _PathRotate($hPath, 180)
    $aRegion[1] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath)

    _Gdiplus_PathReset($hPath)

    ;Thumb
    ThumbBtn_Path($hPath, 0, $iWidth_VSCROLL - 2 + $iThumb_Y, $iThumb_Height, $iWidth_VSCROLL - 2)
    $aRegion[2] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath)

    ;Draw something more

    $iSide = $iWidth / 2 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 51, 180, $hPen)
    $iSide = $iWidth / 3 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 230, 110, $hPen)

    ;Arrows

    $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGfx_Bmp, ChrW(217), $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGfx_Bmp, ChrW(217), $hFont, $aInfo[0], $hFormat, $hBrush) ;Up Arrow

    $tLayout = _GDIPlus_RectFCreate(0, $iHeight - ($iWidth_VSCROLL - 2) / 2, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGfx_Bmp, ChrW(218), $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGfx_Bmp, ChrW(218), $hFont, $aInfo[0], $hFormat, $hBrush) ;Down Arrow

    ;Draw the image on the GUI
    $hHbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)

    ;Mem Release
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_GraphicsDispose($hGfx_Bmp)
    _GDIPlus_ImageDispose($hBmp)

    Return $hHbmp
EndFunc   ;==>hHbmp_ScrollButtons_And_Track

#cs
    Func hHbmp_ScrollThumb($iWidth, $iHeight, $iBkColor, ByRef $aRegion, $iThumb_Y, $iThumb_Height)

    _Gdiplus_PathReset($hPath)

    ;Thumb
    ThumbBtn_Path($hPath, 0, $iWidth_VSCROLL - 2 + $iThumb_Y, $iThumb_Height, $iWidth_VSCROLL - 2)
    $aRegion[2] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath)

    ;Draw something more

    $iSide = $iWidth / 2 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 51, 180, $hPen)
    $iSide = $iWidth / 3 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 230, 110, $hPen)

    EndFunc   ;==>hHbmp_ScrollThumb
#ce

Func SetInRange(ByRef $iVar, $iMin, $iMax)
    $iVar = _Iif($iVar < $iMin, $iMin, $iVar)
    $iVar = _Iif($iVar > $iMax, $iMax, $iVar)
EndFunc   ;==>SetInRange

Func Return_CLientRect($hWnd, $iX = -1, $iY = -1, $iWidth = -1, $iHeight = -1)


    $tRect = DllStructCreate($tagRECT)

    If $iX = -1 And $iY = -1 And $iWidth = -1 And $iHeight = -1 Then

        DllStructSetData($tRect, 1, _WinAPI_GetClientWidth($hWnd) + 2)
        DllStructSetData($tRect, 2, 2)
        DllStructSetData($tRect, 3, _WinAPI_GetWindowWidth($hWnd) - 2)
        DllStructSetData($tRect, 4, _WinAPI_GetClientHeight($hWnd))

    Else

        DllStructSetData($tRect, 1, $iX)
        DllStructSetData($tRect, 2, $iY)
        DllStructSetData($tRect, 3, $iX + $iWidth)
        DllStructSetData($tRect, 4, $iY + $iHeight)

    EndIf


    Return $tRect
EndFunc   ;==>Return_CLientRect

Func GetCurLineIndex($hEdit)
    $aSel = _GUICtrlEdit_GetSel($hEdit)
    If $aSel[0] = $aSel[1] Then
        Return _GUICtrlEdit_LineFromChar($hEdit)
    Else
        _GUICtrlEdit_SetSel($hEdit, -1, -1)
        $iRet = _GUICtrlEdit_LineFromChar($hEdit)
        _GUICtrlEdit_SetSel($hEdit, $aSel[0], $aSel[1])
        Return $iRet
    EndIf
EndFunc   ;==>GetCurLineIndex

;Thanks to Guinness - http://www.autoitscript.com/forum/topic/125684-guictrlgetbkcolor-get-the-background-color-of-a-control/
Func GUICtrlGetBkColor($hWnd, $iX = 0, $iY = 0) ;Modified - PXL
    If IsHWnd($hWnd) = 0 Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, $iX, $iY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

;Thanks to UEZ - http://www.autoitscript.com/forum/topic/150160-solved-gdi-path-transform-rotate/#entry1072071
Func _PathRotate($hPath, $iAngle) ;Modified - PXL
    $aBounds = _GdiPLus_PathGetWorldBounds($hPath)
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + $aBounds[2] / 2, $aBounds[1] + $aBounds[3] / 2)
    _GDIPlus_MatrixRotate($hMatrix, $iAngle)
    _GDIPlus_MatrixTranslate($hMatrix, -($aBounds[0] + $aBounds[2] / 2), -($aBounds[1] + $aBounds[3] / 2))
    _GDIPlus_PathTransform($hPath, $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
EndFunc   ;==>_PathRotate

Func GetLineHeight($hEdit)
    ; Create DC
    $hDC = _WinAPI_GetDC($hEdit)
    $hFont = _SendMessage($hEdit, $WM_GETFONT) ; $WM_GetFont
    $hPrev_Font = _WinAPI_SelectObject($hDC, $hFont)

    Local $tSize = DllStructCreate("int;int")

    DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", "¤", "int", 1, "ptr", DllStructGetPtr($tSize))

    _WinAPI_SelectObject($hDC, $hPrev_Font)
    _WinAPI_ReleaseDC($hEdit, $hDC)

    Return DllStructGetData($tSize, 2)
EndFunc   ;==>GetLineHeight

Func MapWindowPoints($hWndFrom, $hWndTo, $lpPoints, $cPoints)

    $aRet = DllCall("user32.dll", "int", "MapWindowPoints", "hwnd", $hWndFrom, "hwnd", $hWndTo, "ptr", $lpPoints, "int", $cPoints)

    If @error Or $aRet[0] = 0 Then Return SetError(@error, 0, -1)
    Return $aRet[0]

EndFunc   ;==>MapWindowPoints

Test

#include <CScrollBar.au3> ;What ever name you give to the UDF

$hGui = GUICreate("Paths", 400, 400, -1, -1, $WS_SIZEBOX + $WS_MINIMIZEBOX)

Local $String
For $i = 1 To 50 ;No. of lines
    For $j = Random(33, 127, 1) To Random(33, 127, 1) ;No of chars in a line
        $String &= Chr($j)
    Next
    $String &= @CRLF
Next

GUICtrlCreateEdit($String, 5, 5, 200, 300, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL))
Startup_CustomScrollBar(GUICtrlGetHandle(-1))
GUISetState()


Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Shutdown_CustomScrollBar()
            Exit
    EndSwitch
Until 0

The CPU consumed upon moving the thumb is approx 12-18. So is it much enough to stop this project in Autoit. I just want some reviews and what users think about this script. The above is just implemented with Vertical Scrollbar.
Thanks for you time :)

Edited by PhoenixXL
  • Like 2

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

Hi,

Very nice example. The CPU overload is due to the Draw_ScrollBar function called multiple times for only one move (redrawing the scrollbar 20 times in less than one sec).

I see a possible improvement: shift the code that returns the same thing each time to the startup function and avoid the redraw if it's not necessary.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

I see a possible improvement: shift the code that returns the same thing each time to the startup function and avoid the redraw if it's not necessary.

Tried many a times, but upon declaring the local variables( of function Draw_ScrollBar) to global, Autoit crashes on my computer. Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

Here is a start :

#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPIEx.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <Misc.au3>
#include <GUIEdit.au3>
#include <Array.au3>

Global $iWidth_VSCROLL = _WinAPI_GetSystemMetrics($SM_CXVSCROLL)
Global $hGraphic, $hGraphicGUI, $hBMPBuff

;Double-Click
Global $iDoubleClickTime = DllCall("user32.dll", "uint", "GetDoubleClickTime")
$iDoubleClickTime = $iDoubleClickTime[0]

;User-Custom Messages
Global $WM_UPDATETHUMB = $WM_APP + 11
Global $WM_THUMBMOVE = $WM_APP + 12
Global $WM_ARROWDOWN = $WM_APP + 13

Global Const $tagNCCALCSIZE_PARAMS = $tagRECT & ";" & $tagRECT & ";" & $tagRECT & ";ptr PWINDOWPOS"

; Register callback function and obtain handle to _New_WndProc
Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam")
; Get pointer to _New_WndProc
Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc)

Global $___cEdit ; Handle of the Edit
Global $___pOld_WndProc ; Old Window Procedure's Address

Global $_hPen = 0, $_hBrush = 0, $_hFormat = 0, $_hFamily = 0

_GDIPlus_Startup()

Func Startup_CustomScrollBar($hEdit)
    $___cEdit = $hEdit
    $___pOld_WndProc = _SubClass($hEdit, $___pNew_WndProc)

    _WinAPI_SetWindowPos($hEdit, Default, Default, Default, Default, Default, $SWP_FRAMECHANGED)

    $_hPen = _GDIPlus_PenCreate(0xAAFCD667, 2)
    $_hBrush = _GDIPlus_BrushCreateSolid(0xAAFCD667)

    $_hFormat = _GDIPlus_StringFormatCreate()
    $_hFamily = _GDIPlus_FontFamilyCreate("Wingdings")
EndFunc   ;==>Startup_CustomScrollBar

Func Shutdown_CustomScrollBar();Mem Release
    _SubClass($___cEdit, $___pOld_WndProc)

    DllCallbackFree($___hNew_WndProc)

    _GDIPlus_FontFamilyDispose($_hFamily)
    _GDIPlus_StringFormatDispose($_hFormat)

    _GDIPlus_BrushDispose($_hBrush)
    _GDIPlus_PenDispose($_hPen)
EndFunc   ;==>Shutdown_CustomScrollBar

Func TopBtn_Path(ByRef $hPath, $iX, $iY, $iSide)
    ;* Not required when the path is in order.

    _GDIPlus_PathStartFigure($hPath)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX + $iSide, $iY)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX, $iY)
    _GDIPlus_PathAddLine($hPath, $iX, $iY, $iX, $iY + $iSide)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iSide / 2, $iSide, $iSide, 180, 180)
    _GDIPlus_PathCloseFigure($hPath)
EndFunc   ;==>TopBtn_Path

Func ThumbBtn_Path(ByRef $hPath, $iX, $iY, $iHeight, $iSide)
    ;* Not required when the path is in order.

    _GDIPlus_PathStartFigure($hPath)
    _GDIPlus_PathAddLine($hPath, $iX, $iY, $iX, $iY + $iHeight)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - $iSide / 2, $iSide, $iSide, 180, -180)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iHeight, $iX + $iSide, $iY)
    _GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, 180)
    _GDIPlus_PathCloseFigure($hPath)
EndFunc   ;==>ThumbBtn_Path

Func _SubClass($hWnd, $pNew_WindowProc)
    Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc)
    If @error Then Return SetError(1, 0, 0)
    If $iRes = 0 Then Return SetError(1, 0, 0)

    Return SetError(0, 0, $iRes)
EndFunc   ;==>_SubClass

Func _New_WndProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_SETCURSOR, $WM_NCMOUSEMOVE, $WM_MOUSEMOVE, $WM_MOUSELEAVE
            Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)
    EndSwitch

    Local Static $aRegion[3], $i_Thumb_Height = 0, $i_TrackHeight = 0, $iY_Thumb = 0, $iPixel_Per_Line_Scale = 1
    Local Static $hDC = 0, $hGfx = 0, $tPoint = DllStructCreate($tagPOINT), $blTop = False, $blBottom = False

    If $hDC = 0 Then
        $hDC = _WinAPI_GetWindowDC($hWnd)
        $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)
    EndIf

    Switch $iMsg
        Case $WM_NCCALCSIZE
            Local $tNCCALCSIZE_PARAMS = DllStructCreate($tagNCCALCSIZE_PARAMS, $lParam)

            DllStructSetData($tNCCALCSIZE_PARAMS, 1, DllStructGetData($tNCCALCSIZE_PARAMS, 1) + 2)
            DllStructSetData($tNCCALCSIZE_PARAMS, 2, DllStructGetData($tNCCALCSIZE_PARAMS, 2) + 2)
            DllStructSetData($tNCCALCSIZE_PARAMS, 3, DllStructGetData($tNCCALCSIZE_PARAMS, 3) - 2 - $iWidth_VSCROLL) ;Space for VSCROLL Bar
            DllStructSetData($tNCCALCSIZE_PARAMS, 4, DllStructGetData($tNCCALCSIZE_PARAMS, 4) - 2)

            $tNCCALCSIZE_PARAMS = 0

            Return 0
        Case $WM_NCPAINT, $WM_NCACTIVATE
;~          $iRet = _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)

            $iX = _WinAPI_GetClientWidth($hWnd) + 2
            $iY = 2
            $iWidth = _WinAPI_GetWindowWidth($hWnd) - _WinAPI_GetClientWidth($hWnd) - 4
            $iHeight = _WinAPI_GetClientHeight($hWnd)

            Local $iY_Thumbtmp = $iY_Thumb

            ;Set the Range
            SetInRange($i_Thumb_Height, 15, $i_TrackHeight)
            SetInRange($iY_Thumbtmp, 0, $i_TrackHeight - $i_Thumb_Height)

            If Not $blTop And Not $blBottom _ ;not initialized
                    Or ($iY_Thumbtmp = $iY_Thumb _ ;in the range
                    And ($blTop And $iY_Thumbtmp > 0 Or Not $blTop) _ ;not already at the top
                    And ($blBottom And $iY_Thumbtmp < ($i_TrackHeight - $i_Thumb_Height) Or Not $blBottom)) Then ;not already at the bottom

                $iY_Thumbtmp = _Iif($iY_Thumbtmp < 0, 0, $iY_Thumbtmp)
                Draw_ScrollBar($hGfx, $iX, $iY, $iWidth, $iHeight, 0xFF000000 + GUICtrlGetBkColor($hWnd, $iX - 2, $iHeight), $aRegion, $iY_Thumbtmp, $i_Thumb_Height)
            EndIf

            $iY_Thumb = $iY_Thumbtmp

            If $iY_Thumb = 0 Then
                $blTop = True
                $blBottom = False
            ElseIf $iY_Thumb = $i_TrackHeight - $i_Thumb_Height Then
                $blBottom = True
                $blTop = False
            EndIf

;~          Return $iRet
        Case $WM_NCHITTEST
            DllStructSetData($tPoint, 1, _WinAPI_LoWord($lParam))
            DllStructSetData($tPoint, 2, _WinAPI_HiWord($lParam))

            _WinAPI_ScreenToClient($hWnd, $tPoint)

            $tRect = Return_CLientRect($hWnd)

            If _WinAPI_PtInRect($tRect, $tPoint) Then Return $HTBORDER
        Case $WM_NCLBUTTONDOWN
            Local $tPoint2 = _WinAPI_GetMousePos(True, $hWnd)

            If _GDIPlus_RegionIsVisiblePoint($aRegion[0], DllStructGetData($tPoint2, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint2, 2) - 2, $hGfx) Then
                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $SB_LINEUP, 0)
            ElseIf _GDIPlus_RegionIsVisiblePoint($aRegion[1], DllStructGetData($tPoint2, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint2, 2) - 2, $hGfx) Then
                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $SB_LINEDOWN, 1)
            ElseIf _GDIPlus_RegionIsVisiblePoint($aRegion[2], DllStructGetData($tPoint2, 1) - _WinAPI_GetClientWidth($hWnd) - 2, DllStructGetData($tPoint2, 2) - 2, $hGfx) Then
                _WinAPI_PostMessage($hWnd, $WM_THUMBMOVE, 0, 0)
            Else
                $tRect = Return_CLientRect($hWnd)

                If _WinAPI_PtInRect($tRect, $tPoint2) Then
                    $iY_Thumb = DllStructGetData($tPoint2, 2) - (($i_Thumb_Height / 2) + ($iWidth_VSCROLL - 2))
                    $iLine_Scroll = Floor(($iY_Thumb / $iPixel_Per_Line_Scale))
                    $iLine_Scroll_Count = $iLine_Scroll - _GUICtrlEdit_GetFirstVisibleLine($hWnd)

                    _SendMessage($hWnd, $EM_LINESCROLL, 0, $iLine_Scroll_Count)
                    _SendMessage($hWnd, $WM_NCPAINT, 0, 0)
                EndIf
            EndIf
        Case $WM_SIZING, $WM_SIZE, $WM_CHAR, $WM_UNDO, $EM_UNDO, $WM_HOTKEY
            _WinAPI_PostMessage($hWnd, $WM_UPDATETHUMB, 0, 0)
        Case $WM_KEYDOWN
            Switch $wParam
                Case $VK_DOWN, $VK_UP, $VK_PRIOR, $VK_NEXT ;Down
;~                  $iRet = _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)

                    _SendMessage($hWnd, $WM_UPDATETHUMB, 0, 0)

;~                  Return $iRet
                Case $VK_END, $VK_HOME
                    If _IsPressed("11") Then ;CTRL Pressed
                        _SendMessage($hWnd, $WM_VSCROLL, _WinAPI_MakeLong($SB_BOTTOM + $VK_END - $wParam, 0))

                        $iY_Thumb = _Iif($wParam = $VK_END, $i_TrackHeight - $i_Thumb_Height, 0)

                        ;Redraw the window, _WinAPI_RedrawWindow didn't work
                        _SendMessage($hWnd, $WM_NCPAINT, 0, 0)
                    EndIf
            EndSwitch
        Case $WM_MOUSEWHEEL
            $iDelta = _WinAPI_HiWord($wParam)
            $iCount = Abs($iDelta) / 120

            For $i = 1 To $iCount
                _SendMessage($hWnd, $WM_ARROWDOWN, _Iif($iDelta > 0, $SB_LINEUP, $SB_LINEDOWN), -$iDelta)
            Next
        Case $WM_UPDATETHUMB
            ;Calculate the required vars
            $i_LineCount = _GUICtrlEdit_GetLineCount($hWnd)
            $i_ScrollBarHeight = _WinAPI_GetClientHeight($hWnd)
            $i_LineHeight = GetLineHeight($hWnd)
            $iMax_LineVisible = Floor($i_ScrollBarHeight / $i_LineHeight)
            $i_PageHeight = $i_LineCount * $i_LineHeight
            $i_TrackHeight = $i_ScrollBarHeight - (2 * ($iWidth_VSCROLL - 2))
            $i_CurLine = _GUICtrlEdit_GetFirstVisibleLine($hWnd)

            ;Set the Thumb size
            $i_Thumb_Height = $i_TrackHeight * ($iMax_LineVisible * $i_LineHeight / $i_PageHeight)

            ;Set the Scale
            $iPixel_Per_Line_Scale = ($i_TrackHeight - $i_Thumb_Height) / ($i_LineCount - $iMax_LineVisible)

            ;Set the Thumb Pos
            $iY_Thumb = (($i_CurLine / ($i_LineCount - $iMax_LineVisible)) * ($i_TrackHeight - $i_Thumb_Height))

            ;Redraw the window, _Winapi_RedrawWindow didn't work
            _SendMessage($hWnd, $WM_NCPAINT, 0, 0)
        Case $WM_THUMBMOVE
            $iLine_InPage = _WinAPI_GetClientHeight($hWnd) / GetLineHeight($hWnd)
            $Y_Offset = _WinAPI_GetMousePosY(True, $hWnd) - $iY_Thumb
            $iY_Thumb_Prev = $iY_Thumb

            While _IsPressed("01")
                $Mouse_Y = _WinAPI_GetMousePosY(True, $hWnd)
                $iY_Thumb = $Mouse_Y - $Y_Offset

                $iLine_Scroll = Floor(($iY_Thumb / $iPixel_Per_Line_Scale))
                $iLine_Scroll_Count = $iLine_Scroll - _GUICtrlEdit_GetFirstVisibleLine($hWnd)
                _SendMessage($hWnd, $EM_LINESCROLL, 0, $iLine_Scroll_Count)
                _SendMessage($hWnd, $WM_NCPAINT, 0, 0)

                $iY_Thumb_Prev = $iY_Thumb

                Sleep(10)
            WEnd
        Case $WM_ARROWDOWN
            ;lParam = +ve : Down Arrow lParam = -ve : Up Arrow
            Local $iDirection = $wParam
            If $wParam = 0 Then $iDirection = _Iif($lParam > 0, $SB_LINEDOWN, $SB_LINEUP)
            _GUICtrlEdit_Scroll($hWnd, $iDirection)

            $iY_Thumb = _Iif($lParam > 0, $iY_Thumb + $iPixel_Per_Line_Scale, $iY_Thumb - $iPixel_Per_Line_Scale)

            _SendMessage($hWnd, $WM_NCPAINT, 0, 0)

            ;Continuous dragging
            Static $i_Start_Drag = False

            If _IsPressed("01") And $i_Start_Drag = False Then
                $iTimer = TimerInit()

                While _IsPressed("01")
                    If TimerDiff($iTimer) >= $iDoubleClickTime Then
                        $i_Start_Drag = True
                        ExitLoop
                    EndIf

                    Sleep(10)
                WEnd
            EndIf

            If _IsPressed("01") Then
                Sleep(15)
                _WinAPI_PostMessage($hWnd, $WM_ARROWDOWN, $wParam, $lParam)
            Else
                $i_Start_Drag = False
            EndIf
    EndSwitch

    ; Pass to the Original Window Procedure.
    Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_New_WndProc

Func Draw_ScrollBar($hGfx, $iX, $iY, $iWidth, $iHeight, $iBkColor, ByRef $aRegion, $iThumb_Y, $iThumb_Height)
    $hPath = _GDIPlus_PathCreate() ;Our Path

    $hFont = _GDIPlus_FontCreate($_hFamily, $iWidth_VSCROLL / 2 - 1, 2)

    ;Image Containing the Scroll Bar
    $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    $hGfx_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx_Bmp, 2)
    _GDIPlus_GraphicsClear($hGfx_Bmp, $iBkColor) ;Set Bkcolor of the Bmp to that of the Edit

    #cs - Doesn't work as expected
        ;Invalidate and erase the part of the edit containing ScrollBar.
        $tRect = Return_CLientRect($hWnd, $iX, $iY, $iX + $iWidth, $iY + $iHeight)
        _WinAPI_RedrawWindow($hWnd, $tRect, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))
    #ce

    ;Top Button
    TopBtn_Path($hPath, 0, 1, $iWidth_VSCROLL - 2)
    $aRegion[0] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath) ;The Curve part

    _Gdiplus_PathReset($hPath)

    ;Bottom Button
    TopBtn_Path($hPath, 0, $iHeight - $iWidth_VSCROLL + 1, $iWidth_VSCROLL - 2)
    _PathRotate($hPath, 180)
    $aRegion[1] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath)

    _Gdiplus_PathReset($hPath)

    ;Thumb
    ThumbBtn_Path($hPath, 0, $iWidth_VSCROLL - 2 + $iThumb_Y, $iThumb_Height, $iWidth_VSCROLL - 2)
    $aRegion[2] = _GDIPlus_RegionCreateFromPath($hPath)
    _Gdiplus_GraphicsFillPath($hGfx_Bmp, $hPath)

    ;Draw something more
    $iSide = $iWidth / 2 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 51, 180, $_hPen)
    $iSide = $iWidth / 3 - 2
    _GDIPlus_GraphicsDrawArc($hGfx_Bmp, $iWidth / 2 - $iSide, $iWidth_VSCROLL - 2 + $iThumb_Y + $iThumb_Height / 2 - $iSide, 2 * $iSide, 2 * $iSide, 230, 110, $_hPen)

    ;Arrows
    $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGfx_Bmp, ChrW(217), $hFont, $tLayout, $_hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGfx_Bmp, ChrW(217), $hFont, $aInfo[0], $_hFormat, $_hBrush) ;Up Arrow

    $tLayout = _GDIPlus_RectFCreate(0, $iHeight - ($iWidth_VSCROLL - 2) / 2, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGfx_Bmp, ChrW(218), $hFont, $tLayout, $_hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGfx_Bmp, ChrW(218), $hFont, $aInfo[0], $_hFormat, $_hBrush) ;Down Arrow

    ;Draw the image on the GUI
    _GDIPlus_GraphicsDrawImage($hGfx, $hBmp, $iX, $iY)

    ;Mem Release
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_FontDispose($hFont)

    _GDIPlus_GraphicsDispose($hGfx_Bmp)
    _GDIPlus_ImageDispose($hBmp)

    Return 1
EndFunc   ;==>Draw_ScrollBar

Func SetInRange(ByRef $iVar, $iMin, $iMax)
    $iVar = _Iif($iVar < $iMin, $iMin, $iVar)
    $iVar = _Iif($iVar > $iMax, $iMax, $iVar)
EndFunc   ;==>SetInRange

Func Return_CLientRect($hWnd, $iX = -1, $iY = -1, $iWidth = -1, $iHeight = -1)
    $tRect = DllStructCreate($tagRECT)

    If $iX = -1 And $iY = -1 And $iWidth = -1 And $iHeight = -1 Then
        DllStructSetData($tRect, 1, _WinAPI_GetClientWidth($hWnd) + 2)
        DllStructSetData($tRect, 2, 2)
        DllStructSetData($tRect, 3, _WinAPI_GetWindowWidth($hWnd) - 2)
        DllStructSetData($tRect, 4, _WinAPI_GetClientHeight($hWnd))
    Else
        DllStructSetData($tRect, 1, $iX)
        DllStructSetData($tRect, 2, $iY)
        DllStructSetData($tRect, 3, $iX + $iWidth)
        DllStructSetData($tRect, 4, $iY + $iHeight)
    EndIf

    Return $tRect
EndFunc   ;==>Return_CLientRect

Func GetCurLineIndex($hEdit)
    $aSel = _GUICtrlEdit_GetSel($hEdit)
    If $aSel[0] = $aSel[1] Then
        Return _GUICtrlEdit_LineFromChar($hEdit)
    Else
        _GUICtrlEdit_SetSel($hEdit, -1, -1)
        $iRet = _GUICtrlEdit_LineFromChar($hEdit)
        _GUICtrlEdit_SetSel($hEdit, $aSel[0], $aSel[1])
        Return $iRet
    EndIf
EndFunc   ;==>GetCurLineIndex

;Thanks to Guinness - http://www.autoitscript.com/forum/topic/125684-guictrlgetbkcolor-get-the-background-color-of-a-control/
Func GUICtrlGetBkColor($hWnd, $iX = 0, $iY = 0) ;Modified - PXL
    If IsHWnd($hWnd) = 0 Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, $iX, $iY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

;Thanks to UEZ - http://www.autoitscript.com/forum/topic/150160-solved-gdi-path-transform-rotate/#entry1072071
Func _PathRotate($hPath, $iAngle) ;Modified - PXL
    $aBounds = _GdiPLus_PathGetWorldBounds($hPath)
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + $aBounds[2] / 2, $aBounds[1] + $aBounds[3] / 2)
    _GDIPlus_MatrixRotate($hMatrix, $iAngle)
    _GDIPlus_MatrixTranslate($hMatrix, -($aBounds[0] + $aBounds[2] / 2), -($aBounds[1] + $aBounds[3] / 2))
    _GDIPlus_PathTransform($hPath, $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
EndFunc   ;==>_PathRotate

Func GetLineHeight($hEdit)
    ; Create DC
    $hDC = _WinAPI_GetDC($hEdit)
    $_hFont = _SendMessage($hEdit, $WM_GETFONT) ; $WM_GetFont
    $hPrev_Font = _WinAPI_SelectObject($hDC, $_hFont)

    Local $tSize = DllStructCreate("int;int")

    DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", "¤", "int", 1, "ptr", DllStructGetPtr($tSize))

    _WinAPI_SelectObject($hDC, $hPrev_Font)
    _WinAPI_ReleaseDC($hEdit, $hDC)

    Return DllStructGetData($tSize, 2)
EndFunc   ;==>GetLineHeight

I don't know why the scrollbar is not visible on the start up, however the idea is here.

Draw the scrollbar only if there is a move, this can be much improved.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Im pretty sure your looking for a marquee effect, melba made a decent one that i have used (works great as a mini console for errors)

Share this post


Link to post
Share on other sites
FireFox
:blink:

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

tony, this topic has no relation with marquee

I guess it would be better if we would just draw the required part that is if the user clicks the thumb, the thumb is only updated rather than the whole bitmap.

The graphics object could be updated in every resize message. Lets find out where it goes

Thanks for the suggestion firefox.


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

Updated the example with a PIC control.

Increased the sleep in the ThumbMove,

made the local constants as global variables

CPU usage is reduced by 25%

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone

      I was playing a little bit with "Screen Capture" UDF, and I was trying to make a "Window" capture, but, since I made a GUI which through I fire the event "Capture", my GUI is captured as well, and I don't want to
      This is the line of code that makes the capture:
       
      _ScreenCapture_CaptureWnd($strScreenCaptureFileName, $objActiveWindow, 0, 0, -1, -1, False) And these are the lines of code which select the "active" window:
       
      Local $objCurrentWindow = 9999 If _IsPressed("01") Then $objCurrentWindow = WinGetHandle("[ACTIVE]") If $objCurrentWindow <> $objMyGUI Then $objActiveWindow = $objCurrentWindow EndIf EndIf Sorry If I made stupid mistakes
      Thanks in advance.

      Francesco
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with _GUICtrlButton_Create function. How can i change this button's (or the entire form's) font ?. The in-built GUICtrlSetFont function is not working even when i convert the control handle to control ID with _WinAPI_GetDlgCtrlID ( ) function.  Do i need to use CreateFont api finction and send WM_SETFONT message ? Or is there any other easy and safe ways to do this ?. Thanks in advance.
      Note : This window is created by CreateWindowEx function, not by GUICreate function. 
    • Bilgus
      By Bilgus
      Draw Path Points allows you to make line paths for drawing with gdi
      You can even load an image and trace the outline
      Save and load functionality undo and redo zoom and scale; Don't Forget Rotate!
      ;Draw Path Points BILGUS 2018 ;Includes #include <File.au3> #include <GDIPlus.au3> #include <GUIConstants.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiTab.au3> #include <Misc.au3> If OnAutoItExitRegister("_Exit") <> 0 Then _GDIPlus_Startup() ;initialize GDI+ ConsoleWrite("GDI+ Started" & @CRLF) EndIf Opt("MouseCoordMode", 2) ;Relative coords to the client area of the active window Opt("PixelCoordMode", 2) ;Relative coords to the client area of the active window Global $g_iXScale = 8 Global $g_iYScale = $g_iXScale Global $g_sFileSave = @ScriptDir & "\DrawPath.txt" ;Default Global $g_bClosePath = False Global $g_bShowImage = False Global $g_sImagefile = "" Global $g_iUndo_Max = 50 Global $g_asUndo_Files[1] = [""] Global $g_asRedo_Files[1] = [""] Global $g_aPath_Points[1][2] = [[0, 0]] Global $g_aPath_Rot_Points Global $g_hForm1 = GUICreate("Draw Path Points", 615, 437, 192, 124) Global $g_hSelSquare = GUICtrlCreateLabel("", 0, 0, 0, 0, $SS_BLACKFRAME, $WS_EX_TOPMOST) GUICtrlSetState(-1, $GUI_HIDE) ;------------------------------------------------------------------------------- Global Enum $eC1_delete, $eC1_del_all, $eC1_update, $eC1_shift_dn, $eC1_shift_up, _ $eC1_closepath, $eC1_showimg, $eC1_lock, $eC1_undo, $eC1_redo, $aCtl1_LAST Global $g_ahCtl1[$aCtl1_LAST] Control_Create_Group1() ;------------------------------------------------------------------------------- Global Enum $eC2_zin, $eC2_zout, $eC2_dgroup, $eC2_decx, $eC2_incx, $eC2_decy, _ $eC2_incy, $eC2_edit_rot, $eC2_rot, $eC2_ud_rot, $eC2_rev, $eC2_toall, $aCtl2_LAST Global $g_ahCtl2[$aCtl2_LAST] Control_Create_Group2() ;------------------------------------------------------------------------------- Global $g_hBtn_load = GUICtrlCreateButton("Load", 5, 1, 35, 20) Global $g_hBtn_save = GUICtrlCreateButton("Save", 40, 1, 35, 20) Global $g_hBtn_arr_disp = GUICtrlCreateButton("Array", 75, 1, 35, 20) Global $g_hEdit_encoded = GUICtrlCreateEdit("", 115, 2, 50, 18, $ES_READONLY + $ES_AUTOHSCROLL, $WS_EX_STATICEDGE + $WS_EX_TRANSPARENT) Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 201, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL) Global $g_hList1_LVN = GUICtrlCreateDummy() ;listview notifications Global $g_hImage1 = GUICtrlCreatePic("", 200, 16, 400, 400, -1, $WS_EX_LAYERED) Global $g_hTab1 = GUICtrlCreateTab(1, 225, 20, 500, $TCS_VERTICAL) GUICtrlCreateTabItem(" ") GUICtrlSetState(-1, $GUI_SHOW) ; will be display first GUICtrlCreateTabItem(" ") GUICtrlCreateTabItem("") ; end tabitem definition For $i = 0 To UBound($g_ahCtl2) - 1 GUICtrlSetState($g_ahCtl2[$i], $GUI_HIDE) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") List_Update() List_Index() GUISetState(@SW_SHOW) State_Save($g_aPath_Points) Points_Update($g_aPath_Points) Global $g_nMsg = 0 While 1 $g_nMsg = GUIGetMsg() If $g_nMsg > 0 And $g_nMsg <> $g_ahCtl2[$eC2_ud_rot] And $g_nMsg <> $g_ahCtl2[$eC2_edit_rot] And GUICtrlRead($g_ahCtl2[$eC2_edit_rot]) <> 0 Then ;ConsoleWrite("Cancel_Rotate? " & $g_nMsg & @CRLF) If MsgBox($MB_ICONQUESTION + $MB_OKCANCEL + $MB_DEFBUTTON2, "Save?", "Save Rotated Points?", 10) == $IDOK Then _GUICtrlEdit_SetText($g_ahCtl2[$eC2_edit_rot], "0") $g_aPath_Points = $g_aPath_Rot_Points State_Save($g_aPath_Points) List_Update(List_Index()) Else _GUICtrlEdit_SetText($g_ahCtl2[$eC2_edit_rot], "0") Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, List_Index()) ;, True) EndIf EndIf Switch $g_nMsg Case $GUI_EVENT_CLOSE Exit Case $g_hTab1 Tab1_Select() Case $g_hSelSquare ;ConsoleWrite("SelSquare" & @CRLF) SelSquare_Drag() Case $g_hList1 ;ConsoleWrite("List1 " & $g_nMsg & @CRLF) Local $iIndex = List_Index() If $iIndex <> -1 Then Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) _GUICtrlListView_SetItemSelected($g_hList1, $iIndex, True, True) EndIf Case $g_hList1_LVN Point_Selected($g_aPath_Points, $g_hImage1, List_Index()) Case $g_hList1_LVN Case $g_hImage1 Image1_Clicked() Case $g_hBtn_save Btn_save_Clicked() Case $g_hBtn_load Btn_load_Clicked() Case $g_hBtn_arr_disp _ArrayDisplay($g_aPath_Points) ;------------------------------------------------------------------- Case $g_ahCtl1[$eC1_shift_up] $iIndex = List_Index() Point_Swap($iIndex, -1) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_shift_dn] $iIndex = List_Index() Point_Swap($iIndex, 1) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_del_all] $g_aPath_Points = 0 Global $g_aPath_Points[1][2] = [[0, 0]] List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_delete] $iIndex = List_Index() Point_Delete($iIndex) _GUICtrlListView_ClickItem($g_hList1, $iIndex) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_redo] $g_aPath_Points = State_Restore($g_aPath_Points, False) List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_undo] $g_aPath_Points = State_Restore($g_aPath_Points, True) List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_update] List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Ascii_Points($g_aPath_Points) _GUICtrlEdit_SetSel($g_hEdit_encoded, 0, -1) Case $g_ahCtl1[$eC1_closepath] $g_bClosePath = Control_IsChecked($g_ahCtl1[$eC1_closepath]) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) If $g_bClosePath Then GUICtrlSetState($g_ahCtl2[$eC2_rev], $GUI_DISABLE) Else GUICtrlSetState($g_ahCtl2[$eC2_rev], $GUI_ENABLE) EndIf Case $g_ahCtl1[$eC1_showimg] If Not $g_bShowImage Then $g_sImagefile = FileOpenDialog("Select an image", SplitDir($g_sImagefile), "All Files(*.*)", 0, SplitFileName($g_sImagefile), $g_hForm1) EndIf $g_bShowImage = Control_IsChecked($g_ahCtl1[$eC1_showimg]) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) ;------------------------------------------------------------------- Case $g_ahCtl2[$eC2_zin] If Control_IsChecked($g_ahCtl2[$eC2_toall]) Then Points_Scale(1, 1) Else $g_iXScale += 1 $g_iYScale += 1 Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf _GUICtrlListView_ClickItem($g_hList1, List_Index()) Case $g_ahCtl2[$eC2_zout] If Control_IsChecked($g_ahCtl2[$eC2_toall]) Then Points_Scale(-1, -1) Else $g_iXScale -= 1 $g_iYScale -= 1 Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf _GUICtrlListView_ClickItem($g_hList1, List_Index()) Case $g_ahCtl2[$eC2_rev] $iIndex = List_Index() $g_aPath_Points = Points_Reverse($g_aPath_Points) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) ;, True) List_Update($iIndex) Case $g_ahCtl2[$eC2_edit_rot] ;ConsoleWrite("Rotate" & @CRLF) $iIndex = List_Index() Local $iDegrees = GUICtrlRead($g_ahCtl2[$eC2_edit_rot]) $g_aPath_Rot_Points = Points_Rotate($g_aPath_Points, $iDegrees) Points_Update($g_aPath_Rot_Points, $g_bClosePath, $g_bShowImage, $iIndex) ;, True) Case $g_ahCtl2[$eC2_incx] Point_Adjust(1, 0, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_decx] Point_Adjust(-1, 0, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_incy] Point_Adjust(0, 1, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_decy] Point_Adjust(0, -1, Control_IsChecked($g_ahCtl2[$eC2_toall])) EndSwitch WEnd ;---------------------------------------------------------------------------------------------------- Func _Exit() _GDIPlus_Shutdown() ConsoleWrite("GDI+ Stopped" & @CRLF) State_Destroy() EndFunc ;==>_Exit Func Ascii_Points($aPts) ;encodes points into an ascii string Local Const $iChrOffset = 33 Local Const $iMaxOffset = 126 - $iChrOffset If Not IsArray($aPts) Then Return Local $sAscEnc = StringFormat("%03i%05i", $iChrOffset, UBound($aPts) * 2 + 8) If _ArrayMin($aPts) >= 0 And (_ArrayMax($aPts) - _ArrayMin($aPts)) <= $iMaxOffset Then For $i = 0 To UBound($aPts) - 1 $sAscEnc = $sAscEnc & Chr($aPts[$i][0] + $iChrOffset) & Chr($aPts[$i][1] + $iChrOffset) Next EndIf _GUICtrlEdit_SetText($g_hEdit_encoded, $sAscEnc) EndFunc ;==>Ascii_Points Func Btn_load_Clicked() ConsoleWrite("Load: " & SplitDir($g_sFileSave) & @CRLF) $g_sFileSave = FileOpenDialog("Select a save file", SplitDir($g_sFileSave), "All Files(*.*)", 0, SplitFileName($g_sFileSave), $g_hForm1) _FileReadToArray($g_sFileSave, $g_aPath_Points, 0, ",") If @error Then Dim $g_aPath_Points[1][2] = [[0, 0]] Else State_Destroy() State_Save($g_aPath_Points) EndIf List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Btn_load_Clicked Func Btn_save_Clicked() List_Update(List_Index()) $g_sFileSave = FileOpenDialog("Select a save file", SplitDir($g_sFileSave), "All Files(*.*)", 0, SplitFileName($g_sFileSave), $g_hForm1) _FileWriteFromArray($g_sFileSave, $g_aPath_Points, 0, Default, ",") EndFunc ;==>Btn_save_Clicked Func Control_Create_Group1() Local $iX = 30 Local $iY = 225 $g_ahCtl1[$eC1_delete] = GUICtrlCreateButton("Delete", $iX + 0, $iY + 0, 50, 20) $g_ahCtl1[$eC1_shift_dn] = GUICtrlCreateButton("+", $iX + 70, $iY + 0, 20, 20) $g_ahCtl1[$eC1_shift_up] = GUICtrlCreateButton("-", $iX + 95, $iY + 0, 20, 20) $g_ahCtl1[$eC1_del_all] = GUICtrlCreateButton("Delete All", $iX + 0, $iY + 25, 50, 20) $g_ahCtl1[$eC1_update] = GUICtrlCreateButton("Update", $iX + 70, $iY + 25, 50, 20) $g_ahCtl1[$eC1_undo] = GUICtrlCreateButton("Undo", $iX + 0, $iY + 50, 50, 20) $g_ahCtl1[$eC1_redo] = GUICtrlCreateButton("Redo", $iX + 70, $iY + 50, 50, 20) GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) $g_ahCtl1[$eC1_closepath] = GUICtrlCreateCheckbox("Complete", $iX + 0, $iY + 70, 65, 25) $g_ahCtl1[$eC1_showimg] = GUICtrlCreateCheckbox("Image", $iX + 0, $iY + 90, 65, 25) $g_ahCtl1[$eC1_lock] = GUICtrlCreateCheckbox("Locked", $iX + 0, $iY + 110, 65, 25) EndFunc ;==>Control_Create_Group1 Func Control_Create_Group2() Local $iX = 30 Local $iY = 225 $g_ahCtl2[$eC2_rev] = GUICtrlCreateButton("Reverse", $iX + 0, $iY + 0, 50, 20) $g_ahCtl2[$eC2_edit_rot] = GUICtrlCreateInput("0", $iX + 0, $iY + 25, 40, 20) $g_ahCtl2[$eC2_ud_rot] = GUICtrlCreateUpdown(-1) GUICtrlSetLimit($eC2_ud_rot, 360, -360) $g_ahCtl2[$eC2_rot] = GUICtrlCreateButton("", $iX + 40, $iY + 25, 10, 20) $g_ahCtl2[$eC2_dgroup] = GUICtrlCreateGroup("Coords", 5 + $iX + 70, $iY + 0, 55, 70) $g_ahCtl2[$eC2_decy] = GUICtrlCreateButton("-", 24 + $iX + 70, 16 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_incy] = GUICtrlCreateButton("+", 24 + $iX + 70, 48 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_decx] = GUICtrlCreateButton("-", 8 + $iX + 70, 32 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_incx] = GUICtrlCreateButton("+", 40 + $iX + 70, 32 + $iY + 0, 17, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $g_ahCtl2[$eC2_zout] = GUICtrlCreateButton("Zoom -", $iX + 0, $iY + 75, 50, 20) $g_ahCtl2[$eC2_zin] = GUICtrlCreateButton("Zoom +", $iX + 75, $iY + 75, 50, 20) $g_ahCtl2[$eC2_toall] = GUICtrlCreateCheckbox("Apply to all", $iX + 0, $iY + 100, 80, 25) EndFunc ;==>Control_Create_Group2 Func Control_IsChecked($IdCtrl) Return (BitAND(GUICtrlRead($IdCtrl), $GUI_CHECKED) = $GUI_CHECKED) EndFunc ;==>Control_IsChecked Func GDI_Draw_ArrayPoints(ByRef $aPts, $hImage, $g_bClosePath, $iX, $iY, $sFileName, $iSelected = -1) Local $hWnd = GUICtrlGetHandle($hImage) If UBound($aPts) > 1 Then Local $aPoints = GDI_Points($aPts, $iX, $iY) Else Local $aPoints[1][2] = [[0, 0]] EndIf Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;create a graphics object from a window handle _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF) If FileExists($sFileName) Then Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFileName) Local Const $iWidth = ScaleX(_GDIPlus_ImageGetWidth($hBitmap)) Local Const $iHeight = ScaleY(_GDIPlus_ImageGetHeight($hBitmap)) Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iWidth, $iHeight) ;resize image _GDIPlus_BitmapDispose($hBitmap) ;Done with initial bitmap _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) _GDIPlus_BitmapDispose($hBitmap_Scaled) EndIf Local $hPen = _GDIPlus_PenCreate(0xFFFF0000, ScaleX(1)) Local $hEndCap = _GDIPlus_ArrowCapCreate(1, 1) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) If $g_bClosePath Then _GDIPlus_GraphicsDrawPolygon($hGraphics, $aPoints, $hPen) Local $iX0, $iY0, $iX1, $iY1 For $i = 1 To $aPoints[0][0] If Not $g_bClosePath And $i < $aPoints[0][0] Then $iX0 = $aPoints[$i][0] $iY0 = $aPoints[$i][1] $iX1 = $aPoints[$i + 1][0] $iY1 = $aPoints[$i + 1][1] _GDIPlus_GraphicsDrawLine($hGraphics, $iX0, $iY0, $iX1, $iY1, $hPen) EndIf Next _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Point_Selected($aPts, $hImage, $iSelected) EndFunc ;==>GDI_Draw_ArrayPoints Func GDI_Line_hPath_From_Points($aPts, $iXorig, $iYorig) ;Returns hpath object be sure to delete it when finished Local $hPath = _GDIPlus_PathCreate() ;Create new path object Local $aPoints = GDI_Points($aPts, $iXorig, $iYorig) Local $iX0, $iY0, $iX1, $iY1 If IsArray($aPoints) Then For $i = 1 To $aPoints[0][0] - 1 $iX0 = $aPoints[$i][0] $iY0 = $aPoints[$i][1] $iX1 = $aPoints[$i + 1][0] $iY1 = $aPoints[$i + 1][1] _GDIPlus_PathAddLine($hPath, $iX0, $iY0, $iX1, $iY1) Next EndIf Return $hPath ;_GDIPlus_PathDispose($hPath) EndFunc ;==>GDI_Line_hPath_From_Points Func GDI_Points($aPts, $iXo, $iYO) Local $aGDIPts If IsArray($aPts) And UBound($aPts) > 1 Then Local $aGDIPts[UBound($aPts) + 1][2] $aGDIPts[0][0] = UBound($aPts) For $i = 1 To $aGDIPts[0][0] ;Build points list $aGDIPts[$i][0] = ScaleX($aPts[$i - 1][0]) + $iXo $aGDIPts[$i][1] = ScaleY($aPts[$i - 1][1]) + $iYO Next Else Local $aGDIPts[1][2] = [[0, 0]] EndIf Return $aGDIPts EndFunc ;==>GDI_Points Func Image1_Clicked() If Not Control_IsChecked($g_ahCtl1[$eC1_lock]) Then Local $aCPos = ControlGetPos(GUICtrlGetHandle($g_hImage1), "", 0) Local $aPos = MouseGetPos() If IsArray($aPos) And IsArray($aCPos) Then Local $iXn = Int(($aPos[0] - $aCPos[0] + ScaleX(1) / 2) / ScaleX(1)) Local $iYn = Int(($aPos[1] - $aCPos[1] + ScaleY(1) / 2) / ScaleY(1)) Point_Add(List_Index(), $iXn, $iYn) EndIf Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Else ToolTip("Locked") Sleep(500) ToolTip("") EndIf EndFunc ;==>Image1_Clicked Func List_Index() Static Local $hWndList1 = GUICtrlGetHandle($g_hList1) Local $iIndex = _GUICtrlListView_GetSelectionMark($hWndList1) If _GUICtrlListView_GetItemSelected($g_hList1, $iIndex) Then Return $iIndex Return -1 EndFunc ;==>List_Index Func List_Update($iIndex = -1) Static $hWnd_List1 = GUICtrlGetHandle($g_hList1) _GUICtrlListView_BeginUpdate($g_hList1) _GUICtrlListView_DeleteAllItems($hWnd_List1) For $i = 0 To UBound($g_aPath_Points) - 1 GUICtrlCreateListViewItem($i & "|" & $g_aPath_Points[$i][0] & "|" & $g_aPath_Points[$i][1], $g_hList1) Next If $iIndex > -1 Then _GUICtrlListView_ClickItem($g_hList1, $iIndex) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) EndIf _GUICtrlListView_EndUpdate($g_hList1) EndFunc ;==>List_Update Func Point_Add($iIndex, $iX, $iY) If $iIndex <> -1 Then _ArrayInsert($g_aPath_Points, $iIndex, $iX & "|" & $iY, 0) _GUICtrlListView_InsertItem($g_hList1, $iIndex, $iIndex) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iX, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iY, 2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) Else _ArrayAdd($g_aPath_Points, $iX & "|" & $iY, 0) GUICtrlCreateListViewItem(UBound($g_aPath_Points) - 1 & "|" & $iX & "|" & $iY, $g_hList1) _GUICtrlListView_EnsureVisible($g_hList1, UBound($g_aPath_Points) - 1) EndIf State_Save($g_aPath_Points) EndFunc ;==>Point_Add Func Point_Adjust($iX, $iY, $bToAll) If Not $bToAll Then Local $iIndex = List_Index() If $iIndex == -1 And IsArray($g_aPath_Points) Then $iIndex = UBound($g_aPath_Points) - 1 If $iIndex == -1 Then Return $g_aPath_Points[$iIndex][0] += $iX $g_aPath_Points[$iIndex][1] += $iY _GUICtrlListView_SetItemText($g_hList1, $iIndex, $g_aPath_Points[$iIndex][0], 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $g_aPath_Points[$iIndex][1], 2) If $iIndex <> UBound($g_aPath_Points) - 1 Then _GUICtrlListView_ClickItem($g_hList1, $iIndex) Else For $i = 0 To UBound($g_aPath_Points) - 1 $g_aPath_Points[$i][0] += $iX $g_aPath_Points[$i][1] += $iY Next List_Update(List_Index()) EndIf State_Save($g_aPath_Points) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Point_Adjust Func Point_Delete($iIndex) If $iIndex <> -1 Then _ArrayDelete($g_aPath_Points, $iIndex) _GUICtrlListView_DeleteItem($g_hList1, $iIndex) State_Save($g_aPath_Points) ;List_Update($iIndex) EndIf EndFunc ;==>Point_Delete Func Point_Modify($iIndex, $iX, $iY) If $iIndex <> -1 Then $g_aPath_Points[$iIndex][0] = $iX $g_aPath_Points[$iIndex][1] = $iY _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iX, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iY, 2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) State_Save($g_aPath_Points) EndIf EndFunc ;==>Point_Modify Func Point_Selected($aPts, $hImage, $iIndex) If $iIndex > -1 Then GUICtrlSetState($g_hSelSquare, $GUI_HIDE) Local $hWnd = GUICtrlGetHandle($hImage) Local $aPos = ControlGetPos($hWnd, "", 0) If IsArray($aPos) And IsArray($aPts) Then _WinAPI_RedrawWindow($hWnd, Default, Default, $RDW_ERASENOW) Local $iXs = ScaleX($aPts[$iIndex][0]) + $aPos[0] - ScaleX(1) / 2 Local $iYs = ScaleY($aPts[$iIndex][1]) + $aPos[1] - ScaleY(1) / 2 WinMove(GUICtrlGetHandle($g_hSelSquare), "", $iXs, $iYs, ScaleX(1), ScaleY(1)) GUICtrlSetState($g_hSelSquare, $GUI_SHOW) ;ConsoleWrite("Point_Selected" & @CRLF) Else ConsoleWriteError("Error: Point_Selected" & @CRLF) EndIf EndIf EndFunc ;==>Point_Selected Func Point_Swap($iIndex1, $iNext) _GUICtrlListView_BeginUpdate($g_hList1) Local $iIndex2 = 0 Local $aTmp = 0 If $iIndex1 <> -1 Then $iIndex2 = $iIndex1 + $iNext If $iIndex2 > UBound($g_aPath_Points) - 1 Then $iIndex2 = 0 ElseIf $iIndex2 < 0 Then $iIndex2 = UBound($g_aPath_Points) - 1 EndIf _ArraySwap($g_aPath_Points, $iIndex1, $iIndex2) Local $iX1 = _GUICtrlListView_GetItemText($g_hList1, $iIndex1, 2) Local $iY1 = _GUICtrlListView_GetItemText($g_hList1, $iIndex1, 2) Local $iX2 = _GUICtrlListView_GetItemText($g_hList1, $iIndex2, 2) Local $iY2 = _GUICtrlListView_GetItemText($g_hList1, $iIndex2, 2) _GUICtrlListView_SetItemText($g_hList1, $iIndex1, $iX2, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex1, $iY2, 2) _GUICtrlListView_SetItemText($g_hList1, $iIndex2, $iX1, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex2, $iY1, 2) _GUICtrlListView_ClickItem($g_hList1, $iIndex2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex2) Else ;ConsoleWrite("Array Shift" & @CRLF) If $iNext > 0 Then ;ARRAY SHIFT -- Melba23 Local $iUBound = UBound($g_aPath_Points) ; Get size of array $aTmp = _ArrayExtract($g_aPath_Points, 0, $iUBound - 2) ; Extract all but last _ArrayInsert($aTmp, 0, _ArrayExtract($g_aPath_Points, $iUBound - 1, Default)) ; Insert last at top $g_aPath_Points = $aTmp Else $aTmp = _ArrayExtract($g_aPath_Points, 1, Default) ; Extract all but top row _ArrayAdd($aTmp, _ArrayExtract($g_aPath_Points, 0, 0)) ; Add top row at bottom $g_aPath_Points = $aTmp EndIf List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf State_Save($g_aPath_Points) _GUICtrlListView_EndUpdate($g_hList1) EndFunc ;==>Point_Swap Func Points_Reverse($aPts) Local $hPath = GDI_Line_hPath_From_Points($aPts, 0, 0) ;_GDIPlus_PathFlatten($hPath) _GDIPlus_PathReverse($hPath) Local $aPoints = _GDIPlus_PathGetPoints($hPath) _GDIPlus_PathDispose($hPath) If IsArray($aPoints) Then ;ConsoleWrite("Flipped_Points" & @CRLF) Global $aPts_Rev[$aPoints[0][0]][2] For $i = 1 To $aPoints[0][0] $aPts_Rev[$i - 1][0] = Int($aPoints[$i][0] / ScaleX(1)) $aPts_Rev[$i - 1][1] = Int($aPoints[$i][1] / ScaleY(1)) Next Return $aPts_Rev Else Return $aPts EndIf EndFunc ;==>Points_Reverse Func Points_Rotate($aPts, $iDegrees) Local $hPath = GDI_Line_hPath_From_Points($aPts, 0, 0) ;_GDIPlus_PathFlatten($hPath) Local $hPen = _GDIPlus_PenCreate(0x0, ScaleX(1)) Local $aBounds = _GDIPlus_PathGetWorldBounds($hPath, 0, $hPen) _GDIPlus_PenDispose($hPen) If IsArray($aBounds) Then Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + $aBounds[2] / 2, $aBounds[1] + $aBounds[3] / 2) _GDIPlus_MatrixRotate($hMatrix, $iDegrees) _GDIPlus_MatrixTranslate($hMatrix, -($aBounds[0] + $aBounds[2] / 2), -($aBounds[1] + $aBounds[3] / 2)) _GDIPlus_PathTransform($hPath, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndIf Local $aPoints = _GDIPlus_PathGetPoints($hPath) _GDIPlus_PathDispose($hPath) If IsArray($aPoints) Then ;ConsoleWrite("Rotate_Points" & @CRLF) Dim $aPts_Rev[$aPoints[0][0]][2] For $i = 1 To $aPoints[0][0] $aPts_Rev[$i - 1][0] = Int($aPoints[$i][0] / ScaleX(1)) $aPts_Rev[$i - 1][1] = Int($aPoints[$i][1] / ScaleY(1)) Next Return $aPts_Rev Else Return $aPts EndIf EndFunc ;==>Points_Rotate Func Points_Scale($iScaleX, $iScaleY) For $i = 0 To UBound($g_aPath_Points) - 1 If $iScaleX > 0 Then $g_aPath_Points[$i][0] *= 2 Else $g_aPath_Points[$i][0] /= 2 EndIf If $iScaleY > 0 Then $g_aPath_Points[$i][1] *= 2 Else $g_aPath_Points[$i][1] /= 2 EndIf Next State_Save($g_aPath_Points) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Points_Scale Func Points_Update($aPts, $g_bClosePath = False, $b_Show_Image = True, $iSelected = -1) Local $_Image_File = $g_sImagefile If Not $b_Show_Image Then $_Image_File = "" GDI_Draw_ArrayPoints($aPts, $g_hImage1, $g_bClosePath, 0, 0, $_Image_File, $iSelected) EndFunc ;==>Points_Update Func ScaleX($iX) Local $iXs = $g_iXScale If $iXs == 0 Then $iXs = -1 If $iXs > 0 Then $iX = $iX * $iXs Else $iX = $iX / Abs($iXs) EndIf Return $iX EndFunc ;==>ScaleX Func ScaleY($iY) Local $iYs = $g_iYScale If $iYs == 0 Then $iYs = -1 If $iYs > 0 Then $iY = $iY * $iYs Else $iY = $iY / Abs($iYs) EndIf Return $iY EndFunc ;==>ScaleY Func SelSquare_Drag() Local $iIndex = List_Index() If $iIndex <> -1 Then Local $cInfo = GUIGetCursorInfo($g_hForm1) Local $aPosSelOrig = ControlGetPos($g_hForm1, "", $g_hSelSquare) If IsArray($aPosSelOrig) Then Local $iSubtractX = $cInfo[0] - $aPosSelOrig[0] Local $iSubtractY = $cInfo[1] - $aPosSelOrig[1] EndIf If IsArray($cInfo) Then Do $cInfo = GUIGetCursorInfo($g_hForm1) ControlMove($g_hForm1, "", $g_hSelSquare, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) Until Not $cInfo[2] EndIf Local $aPosSelNew = ControlGetPos($g_hForm1, "", $g_hSelSquare) If IsArray($aPosSelNew) And IsArray($aPosSelOrig) Then Local $iXm = $g_aPath_Points[$iIndex][0] + Int(($aPosSelNew[0] - $aPosSelOrig[0]) / ScaleX(1)) Local $iYm = $g_aPath_Points[$iIndex][1] + Int(($aPosSelNew[1] - $aPosSelOrig[1]) / ScaleY(1)) Point_Modify($iIndex, $iXm, $iYm) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) EndIf EndIf EndFunc ;==>SelSquare_Drag Func SplitDir($FullPath) Local $sDrive, $sDir, $sDummy _PathSplit($FullPath, $sDrive, $sDir, $sDummy, $sDummy) Return $sDrive & $sDir EndFunc ;==>SplitDir Func SplitFileName($FullPath) Local $sDummy, $sFileName, $sExt _PathSplit($FullPath, $sDummy, $sDummy, $sFileName, $sExt) Return $sFileName & "" & $sExt EndFunc ;==>SplitFileName Func State_Cleanup(ByRef $a1) If (UBound($a1) > $g_iUndo_Max + 2) Then Local $a1Rem = _ArrayExtract($a1, 1, Default) $a1Rem[0] = $a1[0] Local $sTmp = $a1[1] If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite("Cleanup Delete (UnD) " & $sTmp & @CRLF) EndIf $a1 = $a1Rem EndIf EndFunc ;==>State_Cleanup Func State_Destroy($bRedo_Only = False) Local $sTmp While (UBound($g_asRedo_Files) > 1) $sTmp = _ArrayPop($g_asRedo_Files) If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite(", Delete (ReD) " & $sTmp) If @error Then ConsoleWriteError("Failed to Delete " & $sTmp) EndIf WEnd GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) If $bRedo_Only Then Return While (UBound($g_asUndo_Files) > 1) $sTmp = _ArrayPop($g_asUndo_Files) If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite(", Delete (UnD)" & $sTmp) If @error Then ConsoleWriteError("Failed to Delete " & $sTmp) EndIf WEnd GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) EndFunc ;==>State_Destroy Func State_Is_Diff(ByRef $a1, ByRef $a2) Local $bIsDiff = True If UBound($a1) = UBound($a2) Then $bIsDiff = False For $i = UBound($a1) - 1 To 0 Step -1 If $a1[$i][0] == $a2[$i][0] And $a1[$i][1] == $a2[$i][1] Then ContinueLoop Else ;ConsoleWrite("Diff " & $i & @CRLF) $bIsDiff = True ExitLoop EndIf Next Else ;ConsoleWrite("Diff " & @CRLF) EndIf Return $bIsDiff EndFunc ;==>State_Is_Diff Func State_Restore(ByRef $aPts, $bUndo) Local $sTmp = "" Local $aRes If $bUndo Then $sTmp = _ArrayPop($g_asUndo_Files) ;ConsoleWrite(", Restore (UnD)" & $sTmp) If $sTmp <> "" And FileExists($sTmp) Then _ArrayAdd($g_asRedo_Files, $sTmp) _FileReadToArray($sTmp, $aRes, 0, ",") If UBound($g_asUndo_Files) < 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) If UBound($g_asRedo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_ENABLE) If UBound($g_asUndo_Files) > 1 And Not State_Is_Diff($aPts, $aRes) Then Return State_Restore($aPts, $bUndo) If Not @error Then Return $aRes Else ConsoleWriteError("Failed to Restore " & $sTmp) EndIf Else $sTmp = _ArrayPop($g_asRedo_Files) ;ConsoleWrite(", Restore (ReD) " & $sTmp) If $sTmp <> "" And FileExists($sTmp) Then _ArrayAdd($g_asUndo_Files, $sTmp) _FileReadToArray($sTmp, $aRes, 0, ",") If UBound($g_asRedo_Files) < 2 Then GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) If UBound($g_asUndo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_ENABLE) If UBound($g_asRedo_Files) > 1 And Not State_Is_Diff($aPts, $aRes) Then Return State_Restore($aPts, $bUndo) If Not @error Then Return $aRes Else ConsoleWriteError("Failed to Restore " & $sTmp) EndIf EndIf Return $aPts EndFunc ;==>State_Restore Func State_Save($aPts) If $g_iUndo_Max < 1 Then Return Local $sTmp = _TempFile(@TempDir, "DPP_") If UBound($g_asRedo_Files) > 2 Then _ArrayAdd($g_asUndo_Files, _ArrayPop($g_asRedo_Files)) _ArrayAdd($g_asUndo_Files, $sTmp) _FileWriteFromArray($sTmp, $aPts, 0, Default, ",") If UBound($g_asRedo_Files) > 2 Then State_Destroy(True) State_Cleanup($g_asUndo_Files) ;ConsoleWrite("Save State " & UBound($g_asUndo_Files) & " " & $sTmp & @CRLF) If UBound($g_asUndo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_ENABLE) If @error Then MsgBox(0, @ScriptName & " Error", "Unable to create undo file " & $sTmp) GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) $g_iUndo_Max = 0 EndIf EndFunc ;==>State_Save Func Tab1_Select() Local $iStateCtl1, $iStateCtl2 Local $tabindex = GUICtrlRead($g_hTab1) ;ConsoleWrite("tab" & $tabindex + 1 & "_selected" & @CRLF) Select Case $tabindex = 0 $iStateCtl1 = $GUI_SHOW $iStateCtl2 = $GUI_HIDE Case $tabindex = 1 $iStateCtl1 = $GUI_HIDE $iStateCtl2 = $GUI_SHOW Case Else _GUICtrlTab_ActivateTab($g_hTab1, 0) Return EndSelect For $i = 0 To UBound($g_ahCtl1) - 1 GUICtrlSetState($g_ahCtl1[$i], $iStateCtl1) Next For $i = 0 To UBound($g_ahCtl2) - 1 GUICtrlSetState($g_ahCtl2[$i], $iStateCtl2) Next EndFunc ;==>Tab1_Select Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Static Local $hWndList1 = GUICtrlGetHandle($g_hList1) If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1) If @error Then Return $GUI_RUNDEFMSG If $wParam = $g_hList1 Then Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch DllStructGetData($tNMHDR, "Code") Case $LVN_KEYDOWN, $NM_CLICK GUICtrlSendToDummy($g_hList1_LVN, $lParam) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  


      DrawPathPoints.au3
    • okolaris
      By okolaris
      Hey everyone,
      I thought I might share my little Language UDF plus the more powerful SciTE Tool to ship Strings from SciTE into the xml file. While I haven't had the time to fully adapt the small UDF to one of the big XML-UDFs the so called "Language Transmitter" that basically writes the XML file for you runs mostly on "XML DOM wrapper (COM)" by eltorro. The Transmitter should work with other XML-Language-UDFs depending on their encoding.
       
      First let's start with the UDF, there are two functions of interest: _LangInit($sFilePath) and s($sString) As you will have guessed, _LangInit($sFilePath) is called once to initialize the UDF and s($sString) is used to receive the string to your key. Plain and simple.
      Now to the actual "new" part, the Language Transmitter. It basically allows you to transfer a selected String from SciTE into a xml file. While doing so it will scan for AutoIt variables, macros etc. and parse the string to fit StringFormat(). It then saves the formatted string in the xml file and returns the formatted call into SciTE. If the selected string is already defined it will directly parse the key into SciTE. To change the default output file, you can either edit the ini-file in the @ScriptDir of the LanguageTransmitter.exe or press Alt+A on empty space again and keep clicking cancel/no until the Transmitter let's you select the current output file. Standard output is strings.xml in the current opened AutoIt Script.
      Example:
      ; given the line: MsgBox(16, 'Error', 'Error message') ; select 'Error' run the Transmitter follow the instructions, repeat with 'Error message'. Outcome (e.g.): MsgBox(16, s('Error'), s('Error_msg')) ; Variables and Macro example: $sString = "Value: " & $iValue & @CRLF & 'Another value: '& $iValue2 ; Select the full string including all AutoIt variables and macros etc. in SciTE and press Alt+A (default) to run the LanguageTransmitter ; follow the instructions and it will then paste a formatted string like that into SciTE: $sVar = StringFormat(s('Key'), $iValue, $iValue2) ; the correlating xml entry should look like that: ; <string name="Key">Value: %s\r\nAnother value: %s</string> ; as you can see @CRLF has been replaced with \r\n as well. If you are working on a project and want to directly add a string to the xml file just start the Language Transmitter without selecting any text, enter your string and a key.
      SetUp/Installation
      Examples
      Since xml files are required all examples can be found in the zip file. There are two examples, one includes a language selection interface.
      Language File Checker
      I added a script to check whether the xml file contains all required strings or even unnecessary strings.
       
      Hope you like my little helper!
       
      UDF - LanguageSupport.zip
    • fenhanxue
      By fenhanxue
      i want to copy a picture file to clipboard, so that i can paste the picture through ctrl+V
      this is my code ,but it dosen't work :
      #AutoIt3Wrapper_UseX64 = n #Include <Clipboard.au3> #include <GDIPlus.au3> _GDIPlus_Startup() $hClipboard_Bitmap = _GDIPlus_BitmapCreateFromFile('C:\1.jpg') _ClipBoard_Open(0) _ClipBoard_SetDataEx($hClipboard_Bitmap,$CF_BITMAP) _ClipBoard_Close() _GDIPlus_Shutdown() can you help me
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.