Sign in to follow this  
Followers 0
PhoenixXL

Custom Scrollbar

9 posts in this topic

#1 ·  Posted (edited)

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
2 people like this

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



#2 ·  Posted (edited)

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

#3 ·  Posted (edited)

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

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

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
: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

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

#8 ·  Posted (edited)

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

very cool

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  
Followers 0

  • Similar Content

    • Larnil
      By Larnil
      This script generates Barnsleys Fractal Fern using script only.
      ; version 2017-10-03 ; Barnsley Fractal Fern ; by larnil #include <GUIConstants.au3> Dim $x, $y, $xn, $yn, $n, $r, $dc $WinSize = 800 ; window size ;Create graphics windows AutoItSetOption("GUIOnEventMode", 1) $GUI = GUICreate("Barnsley Fractal Fern", $WinSize, $WinSize, -1, -1) $Graphic = GuiCtrlCreateGraphic(0, 0, $WinSize, $WinSize) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Bye") ;Main $start = TimerInit() _Fern(800) ; hight of fern - can be larger than window MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") While 1 Sleep(100) WEnd Func Bye() Exit EndFunc Func _Fern($height) $f = $height/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $height/2 - $height/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $height*200 ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn GUICtrlSetGraphic($Graphic, $GUI_GR_PIXEL, $offset_x + $x * $f, $height - $y * $f) Next GUICtrlSetGraphic($Graphic, $GUI_GR_REFRESH) EndFunc ;==> Fern  
      Here is another example where I have used GDI (my very first attempt at using GDI by the way). This script can generate much larger Ferns and save them to file (png). I have used this script to generate a 20000 x 20000 pixel @ 600 dpi image. Looks really good printed out in full size.
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; Param Local Const $iPxColor = 0xFF00FF00 ; Pixel color for fractal Alpha/R/G/B Local Const $iBgColor = 0xFFFFFFFF ; Background color for image Alpha/R/G/B Local Const $iSize = 1000 ; Hight of fern in pixels - image will have this hight and width too Local Const $iIter = $iSize*400 ; Number of iterations - $iSize * 200 is a good starting point ; Call function ;$start = TimerInit() _Fern($iSize,$iIter) ;MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") ; Function for generating Barnsley Fractal Fern Func _Fern($Size,$Iter) _GDIPlus_Startup() ; initialize GDI+ Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($Size, $Size) ; create an empty bitmap Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; get the graphics context of the image _GDIPlus_GraphicsClear($hBmpCtxt, $iBgColor) ; Set the background color for empty bitmap ; Here the magic happens $x=0 ; init $y=0 ; init $f = $Size/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $Size/2 - $Size/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $Iter ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn _GDIPlus_BitmapSetPixel($hBitmap, $offset_x + $x * $f, $Size - $y * $f, $iPxColor) ; Change pixel color for calculated X,Y Next ; ==> End of magic $File = "\Fractal_Fern_"&StringRight(Hex($iPxColor),6)&"-"&StringRight(Hex($iBgColor),6)&"-"&$iSize&".png" _GDIPlus_ImageSaveToFile($hBitmap, @MyDocumentsDir & $File) ;save bitmap to disk ShellExecute(@MyDocumentsDir & $File); Show it to the world in your default image viewer ; Cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc ;==> _Fern  
       

    • imitto
      By imitto
      Hello all!
      I use Autoit for a while, already made some automation for a TV station's master control room with it. I made a UDF to easily work with PAL timecode and time with milliseconds, convert, add or subtract them. Feel free to use it if you want something like this
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=PAL Timecode Calculator UDF #AutoIt3Wrapper_Res_LegalCopyright=horvath.imre@gmail.com #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; #FUNCTION# ; Name...........: _tcAdd ; Description....: Returns addition of two timecodes ; Syntax.........: _tcAdd($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Sum of the two timecode in the selected format Func _tcAdd($fTc1, $fTc2, $fFormat = "P", $fHourFormat = 1) Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 + $fMs2 Return _msToTc($fSumMs, $fFormat, $fHourFormat) EndFunc ; #FUNCTION# ; Name...........: _tcsSub ; Description....: Returns addition of two timecodes ; Syntax.........: _tcSub($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Subtract $fTc2 from $fTc1 in the source format Func _tcSub($fTc1, $fTc2, $fFormat = "P") Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 - $fMs2 If $fSumMs < 0 Then $fSumMs = _tcToMs("24:00:00.00") - ($fSumMs * -1) EndIf Return _msToTc($fSumMs, $fFormat) EndFunc ; #FUNCTION# ; Name...........: _tcToMs ; Description....: Returns timecode converted to total milliseconds ; Syntax.........: _tcToMs($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: Milliseconds as an integer value Func _tcToMs($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return ($fTemp[4] * 40) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) Case 3 Return ($fTemp[4]) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) EndSwitch EndFunc ; #FUNCTION# ; Name...........: _msToTc ; Description....: Converts total milliseconds to timecode ; Syntax.........: _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) ; ; Parameters.....: $fIn - Time in milliseconds ; $fFormat - Output format "P": PAL TC (default) ; "M": hh:mm:ss.xxx where xxx are milliseconds ; $fHourFormat - Hour format "1": max. value is 23, then starts from 0 (default) ; "0": hours can be more then 23 ; ; Return value...: Timecode as string in the selected format Func _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) Switch $fFormat Case "P" Local $fFr = StringFormat("%02i", (StringRight($fIn, 3) - Mod(StringRight($fIn, 3), 40)) / 40) Case "M" Local $fFr = StringFormat("%03i", StringRight($fIn, 3)) EndSwitch $fIn = StringTrimRight($fIn, 3) Local $fSec = StringFormat("%02i", Mod($fIn, 60)) $fIn -= $fSec Local $fMinTot = $fIn / 60 Local $fMin = StringFormat("%02i", Mod($fMinTot, 60)) $fIn -= $fMin*60 Local $fHourTot = $fIn / 60 / 60 Switch $fHourFormat Case 1 $fHour = StringFormat("%02i", Mod($fHourTot, 24)) Case 0 $fHour = StringFormat("%02i", $fHourTot) EndSwitch Return($fHour & ":" & $fMin & ":" & $fSec & "." & $fFr) EndFunc ; #FUNCTION# ; Name...........: _tcFormatChange ; Description....: Toggle TC format ; Syntax.........: _tcFormatChange($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: PAL timecode or time with milliseconds as string, depends on input Func _tcFormatChange($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%03i", $fTemp[4]*40) Case 3 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%02i", ($fTemp[4]-Mod($fTemp[4], 40))/40) EndSwitch EndFunc And the example script:
      #include<_PAL_TC_Calc.au3> $palTC1 = "00:01:12.20" $palTC2 = "23:59:50.02" $msTC1 = "00:01:12.800" $msTC2 = "23:59:50.120" MsgBox(0, "1", _tcAdd($palTC1, $palTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "2", _tcAdd($palTC1, $palTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "3", _tcAdd($palTC1, $palTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "4", _tcAdd($msTC1, $msTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "5", _tcAdd($msTC1, $msTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "6", _tcAdd($msTC1, $msTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "7", _tcSub($palTC2, $palTC1)); Subtract $palTC1 from $palTC2, returns PAL TC format MsgBox(0, "8", _tcSub($palTC2, $palTC1, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format MsgBox(0, "9", _tcSub($msTC1, $msTC2)); Subtract $palTC1 from $palTC2, returns PAL TC format - when hits zero, counts back from 24:00:00.00 MsgBox(0, "10", _tcSub($msTC1, $msTC2, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format - when hits zero, counts back from 24:00:00.000 MsgBox(0, "11", _tcFormatChange($palTC2)); Convert PAL TC to time with milliseconds and back MsgBox(0, "12", _tcFormatChange($msTC2)); Convert PAL TC to time with milliseconds and back  
      TC_CALC_example.au3
      _PAL_TC_Calc.au3
    • TRAGENALPHA
      By TRAGENALPHA
      A small UDF to Modify the Console Interface.
      #include-once ;#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; =============================================================================================================================== ; Name...........: Console Modify ; Description ...: A small UDF to manipulate the Console Interface for scripts that are compiled as a console application. ; Syntax.........: _ConsoleClear() -- Clears the Console ; _ConsoleTitle("VALUE") - Sets the console title. ; _ConsoleWindow([WIDTH BUFFER SIZE], [HEIGHT BUFFER SIZE]) - Sets the Width and Height Buffer size of the console. ; Parameters ....: $bh6e5v_ctval = Title of the Console Window. ; $bh6e5v_cwwidth = Window width buffer size. ; $bh6e5v_cwheight = Window height buffer size. ; Return values .: True = Console window buffer size has been changed ; False = Failed to change console window buffer size. ; Author ........: TRAGENALPHA <3 ; Example .......: _ConsoleTitle("This is the new title") // _ConsoleWindow(200, 60) ; =============================================================================================================================== ; -- This is here because writing RunDos and including a whole UDF is too much. But this is basically just _RunDos() ;Func cmd($bh6e5v_ldvar) ; RunWait(@ComSpec & " /c " & $bh6e5v_ldval) ;EndFunc Func _ConsoleClear() RunWait(@ComSpec & " /c cls") EndFunc Func _ConsoleTitle($bh6e5v_ctval) RunWait(@ComSpec & " /c title " & $bh6e5v_ctval) EndFunc Func _ConsoleWindow($bh6e5v_cwwidth, $bh6e5v_cwheight) If IsNumber($bh6e5v_cwwidth) And IsNumber($bh6e5v_cwheight) And ($bh6e5v_cwwidth > 0) And ($bh6e5v_cwheight > 0) Then RunWait(@ComSpec & " /c mode con: cols=" & $bh6e5v_cwwidth & " lines=" & $bh6e5v_cwheight) Return True Else Return False EndIf EndFunc  
      ConsoleModify.au3
    • rudi
      By rudi
      Hello,
      very propably this has been asked before, well, I miss the thread(s) ...
      Is there a command line switch to tell the SciTE setup EXE to install silently ("/S") *AND* to end up with "edit" (instead of "run") as system wide default action for *.au3 files?
       

       
      As it can be done with the config tool:
      https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/SciTEConfigb1.PNG
       
      Regards, Rudi.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I'm working on a little project, and, I encountered a little strange error when I try to add some data to an array...
      The code I wrote is this:
      Func _WMI_Get_Win32_TemperatureProbe($blnCanUseWMI, $blnCustomArrayDisplay = False, $blnReturnEU = False) If $blnCanUseWMI Then Local $objWMI_QueryResult = $objWMI.ExecQuery("SELECT * FROM Win32_TemperatureProbe", "WQL", 32) If @error Then __ConsoleWrite("Error executing the query on Win32_TemperatureProbe class.", @error, 9999) Else Local $arrWin32_TemperatureProbe[1][3] _ArrayDelete($arrWin32_TemperatureProbe, 0) If @error Then __ConsoleWrite("Error deleting the 0st element $arrWin32_TemperatureProbe array.", @error, 9999) Else Local $objWMI_Variable = Null, $strWMI_QueryResult = "", $i = 0 For $objWMI_Variable In $objWMI_QueryResult $strWMI_QueryResult &= "QUERY RESULT" & "|# " & $i & "|/" & @CRLF & _ "Accuracy" & "|" & $objWMI_Variable.Accuracy & "|" & "[sint32]" & @CRLF & _ "Availability" & "|" & $objWMI_Variable.Availability & "|" & "[uint16]" & @CRLF & _ "Caption" & "|" & $objWMI_Variable.Caption & "|" & "[string]" & @CRLF & _ "ConfigManagerErrorCode" & "|" & $objWMI_Variable.ConfigManagerErrorCode & "|" & "[uint32]" & @CRLF & _ "ConfigManagerUserConfig" & "|" & $objWMI_Variable.ConfigManagerUserConfig & "|" & "[boolean]" & @CRLF & _ "CreationClassName" & "|" & $objWMI_Variable.CreationClassName & "|" & "[string]" & @CRLF & _ "CurrentReading" & "|" & $objWMI_Variable.CurrentReading & "|" & "[sint32]" & @CRLF & _ "Description" & "|" & $objWMI_Variable.Description & "|" & "[string]" & @CRLF & _ "DeviceID" & "|" & $objWMI_Variable.DeviceID & "|" & "[string]" & @CRLF & _ "ErrorCleared" & "|" & $objWMI_Variable.ErrorCleared & "|" & "[boolean]" & @CRLF & _ "ErrorDescription" & "|" & $objWMI_Variable.ErrorDescription & "|" & "[string]" & @CRLF & _ "InstallDate" & "|" & $objWMI_Variable.InstallDate & "|" & "[datetime]" & @CRLF & _ "IsLinear" & "|" & $objWMI_Variable.IsLinear & "|" & "[boolean]" & @CRLF & _ "LastErrorCode" & "|" & $objWMI_Variable.LastErrorCode & "|" & "[uint32]" & @CRLF & _ "LowerThresholdCritical" & "|" & $objWMI_Variable.LowerThresholdCritical & "|" & "[sint32]" & @CRLF & _ "LowerThresholdFatal" & "|" & $objWMI_Variable.LowerThresholdFatal & "|" & "[sint32]" & @CRLF & _ "LowerThresholdNonCritical" & "|" & $objWMI_Variable.LowerThresholdNonCritical & "|" & "[sint32]" & @CRLF & _ "MaxReadable" & "|" & $objWMI_Variable.MaxReadable & "|" & "[sint32]" & @CRLF & _ "MinReadable" & "|" & $objWMI_Variable.MinReadable & "|" & "[sint32]" & @CRLF & _ "Name" & "|" & $objWMI_Variable.Name & "|" & "[string]" & @CRLF & _ "NominalReading" & "|" & $objWMI_Variable.NominalReading & "|" & "[sint32]" & @CRLF & _ "NormalMax" & "|" & $objWMI_Variable.NormalMax & "|" & "[sint32]" & @CRLF & _ "NormalMin" & "|" & $objWMI_Variable.NormalMin & "|" & "[sint32]" & @CRLF & _ "PNPDeviceID" & "|" & $objWMI_Variable.PNPDeviceID & "|" & "[string]" & @CRLF & _ "PowerManagementCapabilities" & "|" & $objWMI_Variable.PowerManagementCapabilities & "|" & "[uint16]" & @CRLF & _ "PowerManagementSupported" & "|" & $objWMI_Variable.PowerManagementSupported & "|" & "[boolean]" & @CRLF & _ "Resolution" & "|" & $objWMI_Variable.Resolution & "|" & "[uint32]" & @CRLF & _ "Status" & "|" & $objWMI_Variable.Status & "|" & "[string]" & @CRLF & _ "StatusInfo" & "|" & $objWMI_Variable.StatusInfo & "|" & "[uint16]" & @CRLF & _ "SystemCreationClassName" & "|" & $objWMI_Variable.SystemCreationClassName & "|" & "[string]" & @CRLF & _ "SystemName" & "|" & $objWMI_Variable.SystemName & "|" & "[string]" & @CRLF & _ "Tolerance" & "|" & $objWMI_Variable.Tolerance & "|" & "[sint32]" & @CRLF & _ "UpperThresholdCritical" & "|" & $objWMI_Variable.UpperThresholdCritical & "|" & "[sint32]" & @CRLF & _ "UpperThresholdFatal" & "|" & $objWMI_Variable.UpperThresholdFatal & "|" & "[sint32]" & @CRLF & _ "UpperThresholdNonCritical" & "|" & $objWMI_Variable.UpperThresholdNonCritical & "|" & "[sint32]" $i+=1 Next ConsoleWrite($strWMI_QueryResult & @CRLF) _ArrayAdd($arrWin32_TemperatureProbe, $strWMI_QueryResult) ; I'll wait for an answer... See you later :) If @error Then __ConsoleWrite("Error inserting item #" & $i & " in the $arrWin32_TemperatureProbe array.", @error, 9999) Else If $blnCustomArrayDisplay Then _ArrayDisplay($arrWin32_TemperatureProbe, "Win32_TemperatureProbe:", "", 64 + 32 + 4, "|", "VARIABLE NAME|ACTUAL VALUE|ENGINEERING UNIT", 350, 0xD3D3D3) If @error Then __ConsoleWrite("Error displaying the $arrWin32_TemperatureProbe array.", @error, 9999) EndIf EndIf If $blnReturnEU = False Then _ArrayColDelete($arrWin32_TemperatureProbe, 2) If @error Then __ConsoleWrite("Error deleting the column #2 of $arrWin32_TemperatureProbe array.") EndIf EndIf If IsArray($arrWin32_TemperatureProbe) Then Return $arrWin32_TemperatureProbe Else Return False EndIf EndIf EndIf EndIf EndIf EndFunc And I get this error ( undocumented in the Help File on _ArrayAdd() function ):
      [15/09/2017 10:24:46] : Error inserting item #4 in the $arrWin32_TemperatureProbe array. > Error: 0 Adding a ConsoleWrite() before the _ArrayAdd() function, I can see the content of $strWMI_QueryResult, and, here it is:
      QUERY RESULT|# 0|/
      Accuracy|32768|[sint32]
      Availability||[uint16]
      Caption|Sensore numerico|[string]
      ConfigManagerErrorCode||[uint32]
      ConfigManagerUserConfig||[boolean]
      CreationClassName|Win32_TemperatureProbe|[string]
      CurrentReading||[sint32]
      Description|CPU Thermal Probe|[string]
      DeviceID|root\cimv2 0|[string]
      ErrorCleared||[boolean]
      ErrorDescription||[string]
      InstallDate||[datetime]
      IsLinear||[boolean]
      LastErrorCode||[uint32]
      LowerThresholdCritical||[sint32]
      LowerThresholdFatal||[sint32]
      LowerThresholdNonCritical||[sint32]
      MaxReadable|1270|[sint32]
      MinReadable|64266|[sint32]
      Name|Sensore numerico|[string]
      NominalReading||[sint32]
      NormalMax||[sint32]
      NormalMin||[sint32]
      PNPDeviceID||[string]
      PowerManagementCapabilities||[uint16]
      PowerManagementSupported||[boolean]
      Resolution|1000|[uint32]
      Status|Unknown|[string]
      StatusInfo||[uint16]
      SystemCreationClassName|Win32_ComputerSystem|[string]
      SystemName|DESKTOP-25LFPVU|[string]
      Tolerance|32768|[sint32]
      UpperThresholdCritical||[sint32]
      UpperThresholdFatal||[sint32]
      UpperThresholdNonCritical||[sint32]QUERY RESULT|# 1|/
      Accuracy|32768|[sint32]
      Availability||[uint16]
      Caption|Sensore numerico|[string]
      ConfigManagerErrorCode||[uint32]
      ConfigManagerUserConfig||[boolean]
      CreationClassName|Win32_TemperatureProbe|[string]
      CurrentReading||[sint32]
      Description|True Ambient Thermal Probe|[string]
      DeviceID|root\cimv2 1|[string]
      ErrorCleared||[boolean]
      ErrorDescription||[string]
      InstallDate||[datetime]
      IsLinear||[boolean]
      LastErrorCode||[uint32]
      LowerThresholdCritical||[sint32]
      LowerThresholdFatal||[sint32]
      LowerThresholdNonCritical||[sint32]
      MaxReadable|1270|[sint32]
      MinReadable|64266|[sint32]
      Name|Sensore numerico|[string]
      NominalReading||[sint32]
      NormalMax||[sint32]
      NormalMin||[sint32]
      PNPDeviceID||[string]
      PowerManagementCapabilities||[uint16]
      PowerManagementSupported||[boolean]
      Resolution|1000|[uint32]
      Status|Unknown|[string]
      StatusInfo||[uint16]
      SystemCreationClassName|Win32_ComputerSystem|[string]
      SystemName|DESKTOP-25LFPVU|[string]
      Tolerance|32768|[sint32]
      UpperThresholdCritical||[sint32]
      UpperThresholdFatal||[sint32]
      UpperThresholdNonCritical||[sint32]QUERY RESULT|# 2|/
      Accuracy|32768|[sint32]
      Availability||[uint16]
      Caption|Sensore numerico|[string]
      ConfigManagerErrorCode||[uint32]
      ConfigManagerUserConfig||[boolean]
      CreationClassName|Win32_TemperatureProbe|[string]
      CurrentReading||[sint32]
      Description|Memory Module Thermal Probe|[string]
      DeviceID|root\cimv2 2|[string]
      ErrorCleared||[boolean]
      ErrorDescription||[string]
      InstallDate||[datetime]
      IsLinear||[boolean]
      LastErrorCode||[uint32]
      LowerThresholdCritical||[sint32]
      LowerThresholdFatal||[sint32]
      LowerThresholdNonCritical||[sint32]
      MaxReadable|1270|[sint32]
      MinReadable|64266|[sint32]
      Name|Sensore numerico|[string]
      NominalReading||[sint32]
      NormalMax||[sint32]
      NormalMin||[sint32]
      PNPDeviceID||[string]
      PowerManagementCapabilities||[uint16]
      PowerManagementSupported||[boolean]
      Resolution|1000|[uint32]
      Status|Unknown|[string]
      StatusInfo||[uint16]
      SystemCreationClassName|Win32_ComputerSystem|[string]
      SystemName|DESKTOP-25LFPVU|[string]
      Tolerance|32768|[sint32]
      UpperThresholdCritical||[sint32]
      UpperThresholdFatal||[sint32]
      UpperThresholdNonCritical||[sint32]QUERY RESULT|# 3|/
      Accuracy|32768|[sint32]
      Availability||[uint16]
      Caption|Sensore numerico|[string]
      ConfigManagerErrorCode||[uint32]
      ConfigManagerUserConfig||[boolean]
      CreationClassName|Win32_TemperatureProbe|[string]
      CurrentReading||[sint32]
      Description|Video Card Thermal Probe|[string]
      DeviceID|root\cimv2 3|[string]
      ErrorCleared||[boolean]
      ErrorDescription||[string]
      InstallDate||[datetime]
      IsLinear||[boolean]
      LastErrorCode||[uint32]
      LowerThresholdCritical||[sint32]
      LowerThresholdFatal||[sint32]
      LowerThresholdNonCritical||[sint32]
      MaxReadable|1270|[sint32]
      MinReadable|64266|[sint32]
      Name|Sensore numerico|[string]
      NominalReading||[sint32]
      NormalMax||[sint32]
      NormalMin||[sint32]
      PNPDeviceID||[string]
      PowerManagementCapabilities||[uint16]
      PowerManagementSupported||[boolean]
      Resolution|1000|[uint32]
      Status|Unknown|[string]
      StatusInfo||[uint16]
      SystemCreationClassName|Win32_ComputerSystem|[string]
      SystemName|DESKTOP-25LFPVU|[string]
      Tolerance|32768|[sint32]
      UpperThresholdCritical||[sint32]
      UpperThresholdFatal||[sint32]
      UpperThresholdNonCritical||[sint32]
       
      Could please anyone help me out? 
      Thanks in advance
      Francesco