Jump to content

Recommended Posts

Posted (edited)

Hey all.

I decided to make myself a slider. something like this one

Posted Image

I've got some progress but there are some problems.

1) the thingy (Rectangle) won't stay on the bar if I move it too fast.

2) Script uses lots of resources.

Here's my code (Files are attached)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$hGUI = GUICreate("Test", 300, 200, 100, 100)
$Pic1 = GUICtrlCreatePic("", 48, 80, 204, 16)
GUICtrlSetImage($Pic1, @ScriptDir & "\A.bmp")
$Pic2 = GUICtrlCreatePic("", 88, 72, 28, 34)
GUICtrlSetImage($Pic2, @ScriptDir & "\B.bmp")
$lab = GUICtrlCreateLabel("",48,120,204,16)
GUISetState(@SW_SHOW)




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            $Pos = ControlGetPos("", "", $Pic2)
            $Curs = GUIGetCursorInfo($hGUI)
            $Dif = $Curs[0] - $Pos[0]
            If $Pos[0] <= $Curs[0] And $Curs[0] <= $Pos[0] + 28 And $Pos[1] <= $Curs[1] And $Curs[1] <= $Pos[1] + 34 Then
                Do
                    $CursPos = GUIGetCursorInfo($hGUI)
                    If $CursPos[0] - $Dif > 47 And $CursPos[0] - $Dif + 28 < 253 Then GUICtrlSetPos($Pic2, ($CursPos[0] - $Dif))
                Until $CursPos[2] = 0
            EndIf

    EndSwitch
WEnd

any help would be greatly appreciated :)

Test.rar

Edited by n1maS
Posted

Hey all.

I decided to make myself a slider. something like this one

Posted Image

I've got some progress but there are some problems.

any help would be greatly appreciated :)

Trackbars (Slider) can be custom skinned by Customdrawing or Ownerdrawing.

I've used a skinning dll in the past to theme a slider in a script, otherwise I haven't the need to bother working out the details of customdrawing a slider.

Yashied posted an example of painting the background image behind a slider that used customdrawing.

At the time, I did a few tests theming the slider, then left it.

Here is the updated code modified from Yashied's post with hard coded metrics, no image alpha transparency support and without image state code (hot/focused/disabled).

Version with background image has high cpu usage when trackbar moved (NM_CUSTOMDRAW message) and

some optimization is needed.

Alternately use a layered gui for transparency.

Or use UEZ's custom trackbar posted in your other thread just as I was logging in to post this.

post-22637-0-01000100-1346940624_thumb.j

Solid colour Background

;coded by rover 2k12 - modified from customdrawn slider background code by Yashied
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global Const $tagNMCUSTOMDRAW = $tagNMHDR & ';dword DrawStage;handle hDC;long Rect[4];dword_ptr ItemSpec;uint ItemState;lparam ItemlParam'
Global Const $STM_GETIMAGE = 0x0173
Global $iBuffer, $hBitmap1, $hBitmap2, $bmWidth1, $bmHeight1, $bmWidth2, $bmHeight2, $cSldr1, $cSldr2, $hSlider1, $hSlider2

_Main()

Func _Main()
Local $iLoad = BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION, $LR_LOADTRANSPARENT), $Msg
$hBitmap1 = _WinAPI_LoadImage(0, @ScriptDir & '\B.bmp', $IMAGE_BITMAP, 0, 0, $iLoad); LoadImage API only works with BMP files or BMP resources
$hBitmap2 = _WinAPI_LoadImage(0, @ScriptDir & '\A.bmp', $IMAGE_BITMAP, 0, 0, $iLoad)
_GetBitmapSize($hBitmap1, $bmWidth1, $bmHeight1)
_GetBitmapSize($hBitmap2, $bmWidth2, $bmHeight2)

GUICreate('Custom Skin Slider', 300, 150)
GUISetBkColor(0x494949)

$cSldr1 = GUICtrlCreateDummy()
$cSldr2 = GUICtrlCreateDummy()

Local $cEdit1 = GUICtrlCreateInput("0", 10, 26, 42, 24, BitOR($ES_CENTER, $ES_READONLY)) ;does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control)
GUICtrlSetFont(-1, 12, 800, 1, "Arial")
GUICtrlSetColor(-1, 0x00EEEE)
GUICtrlSetBkColor(-1, 0x494949)

Local $cEdit2 = GUICtrlCreateInput("0", 10, $bmHeight1 + 42, 42, 24, BitOR($ES_CENTER, $ES_READONLY));does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control)
GUICtrlSetFont(-1, 12, 800, 1, "Arial")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x363636)

GUICtrlCreateSlider(60, 20, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP))
$hSlider1 = GUICtrlGetHandle(-1)
GUICtrlSetCursor(-1, 0)
_SendMessage($hSlider1, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar
GUICtrlSetBkColor(-1, 0x494949)

GUICtrlCreateSlider(60, $bmHeight1 + 36, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP))
$hSlider2 = GUICtrlGetHandle(-1)
GUICtrlSetCursor(-1, 0)
_SendMessage($hSlider2, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar
GUICtrlSetBkColor(-1, 0x494949)

GUIRegisterMsg($WM_HSCROLL, "_WM_HVSCROLL")
;GUIRegisterMsg($WM_VSCROLL, "_WM_HVSCROLL")
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()

While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hBitmap1)
_WinAPI_DeleteObject($hBitmap2)
Exit
Case $cSldr1
GUICtrlSetData($cEdit1, GUICtrlRead($cSldr1))
Case $cSldr2
GUICtrlSetData($cEdit2, GUICtrlRead($cSldr2))
EndSwitch
WEnd

EndFunc

Func _WM_HVSCROLL($hWnd, $Msg, $wParam, $lParam)
Switch $lParam
Case $hSlider1, $hSlider2
Local $iCtrlID = _WinAPI_GetDlgCtrlID($lParam)
Local $iPos = GUICtrlRead($iCtrlID)
If $iBuffer <> $iPos Then ; buffer read slider value to prevent unnecessary updating at start/end of slider range.
$iBuffer = $iPos
;ConsoleWrite(' Slider = ' & $iPos & @CRLF)
Switch $lParam
Case $hSlider1
GUICtrlSendToDummy($cSldr1, $iPos)
Case $hSlider2
GUICtrlSendToDummy($cSldr2, $iPos)
EndSwitch
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_HVSCROLL

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam, $lParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
Local $Code = DllStructGetData($tNMHDR, 'Code')
Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom')
Switch $hWndFrom
Case $hSlider1, $hSlider2
Switch $Code
Case $NM_CUSTOMDRAW
Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
Local $DrawStage = DllStructGetData($tNMCD, 'DrawStage')
Local $ItemSpec = DllStructGetData($tNMCD, 'ItemSpec')
Local $hDC, $hMemDC, $hPrev
Switch $DrawStage
Case $CDDS_PREPAINT
DllStructSetData($tNMCD, 'ItemState', BitXOR(DllStructGetData($tNMCD, 'ItemState'), $CDIS_FOCUS)) ; Remove focus Rectangle
Return $CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
Local $nLeft = DllStructGetData($tNMCD, 'Rect', 1)
Local $nTop = DllStructGetData($tNMCD, 'Rect', 2)
Local $nRight = DllStructGetData($tNMCD, 'Rect', 3)
Local $nBottom = DllStructGetData($tNMCD, 'Rect', 4)
Local $nWidth = $nRight - $nLeft
Local $nHeight = $nBottom - $nTop
$hDC = DllStructGetData($tNMCD, 'hDC')
Switch $ItemSpec
Case $TBCD_TICS
Return $CDRF_SKIPDEFAULT ; draw custom ticks from bitmap or remove tics
;Return $CDRF_DODEFAULT ; draw tics from current theme
Case $TBCD_CHANNEL
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap2)
_WinAPI_BitBlt($hDC, $nLeft, $nTop - 16, $nWidth, $bmHeight2, $hMemDC, 0, 0, $MERGECOPY)
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
Return $CDRF_SKIPDEFAULT ;custom draw channel with bitmap or remove channel
;Return $CDRF_DODEFAULT ;draw channel from current theme
Case $TBCD_THUMB
If ($nWidth - $bmWidth1) > 0 Then
$nLeft += (($nWidth - $bmWidth1) / 2)
$nWidth = $bmWidth1
EndIf
If ($nHeight - $bmHeight1) > 0 Then
$nTop += ($nHeight - $bmHeight1) / 2
$nHeight = $bmHeight1
EndIf
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap1)
_WinAPI_BitBlt($hDC, $nLeft, $nTop - 10, $nWidth, $nHeight, $hMemDC, 0, 0, $SRCCOPY)
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
Return $CDRF_SKIPDEFAULT ;custom draw thumb with bitmap
;Return $CDRF_DODEFAULT ;draw thumb from current theme
EndSwitch
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func _GetBitmapSize($hBitmap, ByRef $X, ByRef $Y)
Local $iRet = _WinAPI_GetObject($hBitmap, 0, 0)
Local $tBitmap = DllStructCreate("int bmType;int bmWidth;int bmHeight;" & _
"int bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;long_ptr bmBits")
If DllStructGetSize($tBitmap) <> $iRet Then Return SetError(1, 0, -1)
$iRet = _WinAPI_GetObject($hBitmap, $iRet, DllStructGetPtr($tBitmap))
$X = DllStructGetData($tBitmap, "bmWidth")
$Y = DllStructGetData($tBitmap, "bmHeight")
EndFunc ;==>_GetBitmapSize

Image Background

(High cpu when trackbar moved)

;coded by rover 2k12 - modified from customdrawn slider background code by Yashied
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global Const $tagNMCUSTOMDRAW = $tagNMHDR & ';dword DrawStage;handle hDC;long Rect[4];dword_ptr ItemSpec;uint ItemState;lparam ItemlParam'
Global Const $STM_GETIMAGE = 0x0173
Global $hTemp = 0, $hPic, $iBuffer, $hBitmap1, $hBitmap2, $bmWidth1, $bmHeight1, $bmWidth2, $bmHeight2, $cSldr1, $cSldr2, $hSlider1, $hSlider2

_Main()

Func _Main()
Local $iLoad = BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION, $LR_LOADTRANSPARENT), $Msg
$hBitmap1 = _WinAPI_LoadImage(0, @ScriptDir & '\B.bmp', $IMAGE_BITMAP, 0, 0, $iLoad); LoadImage API only works with BMP files or BMP resources
$hBitmap2 = _WinAPI_LoadImage(0, @ScriptDir & '\A.bmp', $IMAGE_BITMAP, 0, 0, $iLoad)
_GetBitmapSize($hBitmap1, $bmWidth1, $bmHeight1)
_GetBitmapSize($hBitmap2, $bmWidth2, $bmHeight2)

GUICreate('Custom Skin Slider', 300, 150)
GUISetBkColor(0x494949)

Local $Wow64 = "", $Msg
If @AutoItX64 Then $Wow64 = "\Wow6432Node"
Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg"
GUICtrlCreatePic($sPath, 0, 0, 413, 161)
GUICtrlSetState(-1, $GUI_DISABLE)
$hPic = GUICtrlGetHandle(-1)

$cSldr1 = GUICtrlCreateDummy()
$cSldr2 = GUICtrlCreateDummy()

Local $cEdit1 = GUICtrlCreateInput("0", 10, 26, 42, 24, BitOR($ES_CENTER, $ES_READONLY)) ;does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control)
GUICtrlSetFont(-1, 12, 800, 1, "Arial")
GUICtrlSetColor(-1, 0x00EEEE)
GUICtrlSetBkColor(-1, 0x494949)

Local $cEdit2 = GUICtrlCreateInput("0", 10, $bmHeight1 + 42, 42, 24, BitOR($ES_CENTER, $ES_READONLY));does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control)
GUICtrlSetFont(-1, 12, 800, 1, "Arial")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x363636)

GUICtrlCreateSlider(60, 20, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP))
$hSlider1 = GUICtrlGetHandle(-1)
GUICtrlSetCursor(-1, 0)
_SendMessage($hSlider1, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar
GUICtrlSetBkColor(-1, 0x494949)

GUICtrlCreateSlider(60, $bmHeight1 + 36, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP))
$hSlider2 = GUICtrlGetHandle(-1)
GUICtrlSetCursor(-1, 0)
_SendMessage($hSlider2, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar
GUICtrlSetBkColor(-1, 0x494949)

GUIRegisterMsg($WM_HSCROLL, "_WM_HVSCROLL")
;GUIRegisterMsg($WM_VSCROLL, "_WM_HVSCROLL")
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()

While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hBitmap1)
_WinAPI_DeleteObject($hBitmap2)
Exit
Case $cSldr1
GUICtrlSetData($cEdit1, GUICtrlRead($cSldr1))
Case $cSldr2
GUICtrlSetData($cEdit2, GUICtrlRead($cSldr2))
EndSwitch
WEnd

EndFunc

Func _WM_HVSCROLL($hWnd, $Msg, $wParam, $lParam)
Switch $lParam
Case $hSlider1, $hSlider2
Local $iCtrlID = _WinAPI_GetDlgCtrlID($lParam)
Local $iPos = GUICtrlRead($iCtrlID)
If $iBuffer <> $iPos Then ; buffer read slider value to prevent unnecessary updating at start/end of slider range.
$iBuffer = $iPos
;ConsoleWrite(' Slider = ' & $iPos & @CRLF)
Switch $lParam
Case $hSlider1
GUICtrlSendToDummy($cSldr1, $iPos)
Case $hSlider2
GUICtrlSendToDummy($cSldr2, $iPos)
EndSwitch
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_HVSCROLL

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam, $lParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
Local $Code = DllStructGetData($tNMHDR, 'Code')
Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom')
Switch $hWndFrom
Case $hSlider1, $hSlider2
Switch $Code
Case $NM_CUSTOMDRAW
Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
Local $DrawStage = DllStructGetData($tNMCD, 'DrawStage')
Local $ItemSpec = DllStructGetData($tNMCD, 'ItemSpec')
Local $hDC = DllStructGetData($tNMCD, 'hDC')
Local $hMemDC, $hBitmap, $hPrev, $aPos
Switch $DrawStage
Case $CDDS_PREPAINT, $CDDS_POSTPAINT
$aPos = ControlGetPos($hWndFrom, '', '')
Switch $DrawStage
Case $CDDS_PREPAINT
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _SendMessage($hPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0)
$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_BitBlt($hDC, 0, 0, $aPos[2], $aPos[3], $hMemDC, $aPos[0], $aPos[1], $SRCCOPY)
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
DllStructSetData($tNMCD, 'ItemState', BitXOR(DllStructGetData($tNMCD, 'ItemState'), $CDIS_FOCUS)) ; Remove focus Rectangle
Return BitOR($CDRF_NOTIFYITEMDRAW, $CDRF_NOTIFYPOSTPAINT)
Case $CDDS_POSTPAINT
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
If Not $hTemp Then
$hTemp = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3])
$hPrev = _WinAPI_SelectObject($hMemDC, $hTemp)
_WinAPI_BitBlt($hMemDC, 0, 0, $aPos[2], $aPos[3], $hDC, 0, 0, $MERGECOPY)
Else
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hPrev = _WinAPI_SelectObject($hMemDC, $hTemp)
_WinAPI_BitBlt($hDC, 0, 0, $aPos[2], $aPos[3], $hMemDC, 0, 0, $SRCCOPY)
EndIf
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
Return $CDRF_DODEFAULT
EndSwitch
Case $CDDS_ITEMPREPAINT
If $hTemp Then
_WinAPI_DeleteObject($hTemp)
$hTemp = 0
EndIf
Local $nLeft = DllStructGetData($tNMCD, 'Rect', 1)
Local $nTop = DllStructGetData($tNMCD, 'Rect', 2)
Local $nRight = DllStructGetData($tNMCD, 'Rect', 3)
Local $nBottom = DllStructGetData($tNMCD, 'Rect', 4)
Local $nWidth = $nRight - $nLeft
Local $nHeight = $nBottom - $nTop

Switch $ItemSpec
Case $TBCD_TICS
Return $CDRF_SKIPDEFAULT ; draw custom ticks from bitmap or remove tics
;Return $CDRF_DODEFAULT ; draw tics from current theme
Case $TBCD_CHANNEL
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap2)
_WinAPI_BitBlt($hDC, $nLeft, $nTop - 16, $nWidth, $bmHeight2, $hMemDC, 0, 0, $MERGECOPY)
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
Return $CDRF_SKIPDEFAULT ;custom draw channel with bitmap or remove channel
;Return $CDRF_DODEFAULT ;draw channel from current theme
Case $TBCD_THUMB
If ($nWidth - $bmWidth1) > 0 Then
$nLeft += (($nWidth - $bmWidth1) / 2)
$nWidth = $bmWidth1
EndIf
If ($nHeight - $bmHeight1) > 0 Then
$nTop += ($nHeight - $bmHeight1) / 2
$nHeight = $bmHeight1
EndIf
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap1)
_WinAPI_BitBlt($hDC, $nLeft, $nTop - 10, $nWidth, $nHeight, $hMemDC, 0, 0, $SRCCOPY)
_WinAPI_SelectObject($hMemDC, $hPrev)
_WinAPI_DeleteDC($hMemDC)
Return $CDRF_SKIPDEFAULT ;custom draw thumb with bitmap
;Return $CDRF_DODEFAULT ;draw thumb from current theme
EndSwitch
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func _GetBitmapSize($hBitmap, ByRef $X, ByRef $Y)
Local $iRet = _WinAPI_GetObject($hBitmap, 0, 0)
Local $tBitmap = DllStructCreate("int bmType;int bmWidth;int bmHeight;" & _
"int bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;long_ptr bmBits")
If DllStructGetSize($tBitmap) <> $iRet Then Return SetError(1, 0, -1)
$iRet = _WinAPI_GetObject($hBitmap, $iRet, DllStructGetPtr($tBitmap))
$X = DllStructGetData($tBitmap, "bmWidth")
$Y = DllStructGetData($tBitmap, "bmHeight")
EndFunc ;==>_GetBitmapSize

I see fascists...

Posted (edited)

Indeed I mixed up the topics. :whistle:

Nice examples rover! :thumbsup: I searched for Yashied's code but didn't find it and decided to hack something with built-in graphic creator using GDI+.
 

;coded by UEZ build 2013-09-03 beta
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--best --lzma

#include <SliderConstants.au3>
;~ #include <WindowsConstants.au3>;~~~
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 0)

Global Const $IMAGE_BITMAP = 0
Global Const $STM_SETIMAGE = 0x0172

_GDIPlus_Startup()

Global $hGUI = GUICreate("New Slider beta by UEZ 2012-2013", 580, 280)
Global $iW = 300, $iH = 16

Global $aSlider1 = GUICtrlCreateHSlider(100, 50, $iW, $iH, 0xFF4080F0)
Global $idLabel = GUICtrlCreateLabel("Volume", 10, 46, 70, 30)
GUICtrlSetFont(-1, 16)
Global $idInput1 = GUICtrlCreateInput($aSlider1[7], 420, 46, 42, 24, BitOR($ES_CENTER, $ES_READONLY))
GUICtrlSetFont(-1, 12)
Global $iSliderPos = 50

Global $aSlider2 = GUICtrlCreateHSlider(120, 100, $iW + 30, 30, 0xFF205020, @ScriptDir & "\button_smiley.png", "", $iSliderPos)
Global $idInput2 = GUICtrlCreateInput($aSlider2[7], 10, 100, 42, 24)
GUICtrlSetFont(-1, 12)
Global $iSlider = GUICtrlCreateSlider(6, 150, $iW + 156, 45, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_NOTHUMB, $TBS_NOTHUMB))
GUICtrlSetLimit(-1, 200, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $idButton = GUICtrlCreateButton("OK", 56, 99, 40, 26)

Global $aSlider3 = GUICtrlCreateHSlider(20, 180, $iW + 130, 50, 0, @ScriptDir & "\star.png", @ScriptDir & "\Texture.jpg", $iSliderPos)


Global $aSlider4 = GUICtrlCreateVSlider(520, 20, 24, 240, 0xFF505050)
;~ Global $aSlider4 = GUICtrlCreateVSlider(520, 20, 24, 240, 0, "", @ScriptDir & "\TextureRotated.jpg")


GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlSetOnEvent($aSlider1[0], "CheckSliderMove")
GUICtrlSetOnEvent($aSlider2[0], "CheckSliderMove")
GUICtrlSetOnEvent($aSlider3[0], "CheckSliderMove")
GUICtrlSetOnEvent($aSlider4[0], "CheckSliderMove")
GUICtrlSetOnEvent($idButton, "UpdateSlider")

Do
Until Not Sleep(3000)

Func UpdateSlider()
    SetSliderPosHMan($aSlider2, GUICtrlRead($idInput2))
EndFunc   ;==>UpdateSlider

Func _Exit()
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func CheckSliderMove()
    Local $aRes = GUIGetCursorInfo($hGUI), $aPosW, $aPosH
    Switch $aRes[4]
        Case $aSlider1[0]
            While $aRes[2] * Sleep(20)
                $aRes = GUIGetCursorInfo($hGUI)
                SetSliderPosH($aSlider1, $aRes[0])
                GUICtrlSetData($idInput1, $aSlider1[7])
                $aPosW = WinGetPos($hGUI)
                ToolTip("Value: " & $aSlider1[7], $aPosW[0] + $aRes[0], $aPosW[1] + $aRes[1] + 50)
            WEnd
            ToolTip("")
        Case $aSlider2[0]
            While $aRes[2] * Sleep(20)
                $aRes = GUIGetCursorInfo($hGUI)
                SetSliderPosH($aSlider2, $aRes[0])
                GUICtrlSetData($idInput2, $aSlider2[7])
            WEnd
        Case $aSlider3[0]
            While $aRes[2] * Sleep(20)
                $aRes = GUIGetCursorInfo($hGUI)
                SetSliderPosH($aSlider3, $aRes[0])
                $aPosW = WinGetPos($hGUI)
                ToolTip("Value: " & $aSlider3[7], $aPosW[0] + $aRes[0], $aPosW[1] + $aRes[1] + 50)
            WEnd
            ToolTip("")
        Case $aSlider4[0]
            While $aRes[2] * Sleep(20)
                $aRes = GUIGetCursorInfo($hGUI)
                SetSliderPosV($aSlider4, $aRes[1])
                $aPosH = WinGetPos($hGUI)
                ToolTip("Value: " & $aSlider4[7], $aPosH[0] + $aRes[0], $aPosH[1] + $aRes[1] + 50)
            WEnd
            ToolTip("")
    EndSwitch
EndFunc   ;==>CheckSliderMove

Func SetSliderPosHMan(ByRef $aSlider, $iPos)
    Local $aPos, $aPosW
    $iNewPos = 1 + Int($aSlider[1] + $iPos * $aSlider[5] + $aSlider[3])
    GUICtrlSetPos($aSlider[0], Max($aSlider[1], Min($iNewPos - $aSlider[3], $aSlider[4])), $aSlider[2])
    $aPos = ControlGetPos($hGUI, "", $aSlider[0])
    $aPosW = WinGetPos($hGUI)
    $aSlider[7] = $iPos ;Int(($aPos[0] + $aSlider[3] - $aSlider[6]) / $aSlider[5])
EndFunc   ;==>SetSliderPosHMan

Func SetSliderPosH(ByRef $aSlider, $iPos)
    Local $aPos, $aPosW
    GUICtrlSetPos($aSlider[0], Max($aSlider[1], Min($iPos - $aSlider[3], $aSlider[4])), $aSlider[2])
    $aPos = ControlGetPos($hGUI, "", $aSlider[0])
    $aPosW = WinGetPos($hGUI)
    $aSlider[7] = Int(($aPos[0] + $aSlider[3] - $aSlider[6]) / $aSlider[5])
EndFunc   ;==>SetSliderPosH

Func SetSliderPosV(ByRef $aSlider, $iPos)
    Local $aPos, $aPosH
    GUICtrlSetPos($aSlider[0], $aSlider[2], Max($aSlider[1], Min($iPos - $aSlider[3], $aSlider[4])))
    $aPos = ControlGetPos($hGUI, "", $aSlider[0])
    $aPosH = WinGetPos($hGUI)
    $aSlider[7] = Int(($aPos[1] + $aSlider[3] - $aSlider[6]) / $aSlider[5])
EndFunc   ;==>SetSliderPosV

Func GUICtrlCreateHSlider($iX, $iY, $iW, $iH, $iColor, $sFileThumb = "", $sFileBg = "", $iValThumb = 0, $iColorThumb = 0xD0A00000, $iColorThumb_Center = 0xFFFFA0A0, $iValMin = 0, $iValMax = 100, $fSize = 0.025, $fScale = 1.5)
    Local $hHBitmap_Thumb, $hHBitmap_Bg
    Local $idPic_Bg = GUICtrlCreatePic("", $iX, $iY, $iW, $iH)
    GUICtrlSetState(-1, $GUI_DISABLE)
    If $sFileBg <> "" And FileExists($sFileBg) Then
        $hHBitmap_Bg = _GDIPlus_CreateHBitmapFromFile($sFileBg, $iW, $iH)
    Else
        $hHBitmap_Bg = _GDIPlus_CreateRoundRectImage($iW, $iH, $iColor, $fSize)
    EndIf
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Bg, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Bg))
    _WinAPI_DeleteObject($hHBitmap_Bg)
    Local $iH_Thumb = $iH * $fScale
    Local $fRatio = $iW / Abs($iValMax - $iValMin)
    Local $idPic_Thumb = GUICtrlCreatePic("", $iX - $iH_Thumb / 2 + $iValThumb * $fRatio, $iY - ($iH_Thumb - $iH) / 2, $iH_Thumb, $iH_Thumb)
    If $sFileThumb <> "" And FileExists($sFileThumb) Then
        $hHBitmap_Thumb = _GDIPlus_CreateHBitmapFromFile($sFileThumb, $iH_Thumb, $iH_Thumb)
    Else
        $hHBitmap_Thumb = _GDIPlus_CreateEllipseThumb($iH_Thumb, $iColorThumb, $iColorThumb_Center)
    EndIf
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Thumb, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Thumb))
    _WinAPI_DeleteObject($hHBitmap_Thumb)
    Local $aSlider[8] = [   $idPic_Thumb, _                 ;0 control id
                            $iX - $iH_Thumb / 2, _          ;1 min x position thumb
                            $iY - ($iH_Thumb - $iH) / 2, _  ;2 center position thumb height
                            $iH_Thumb / 2, _                ;3 center thumb height
                            $iX + $iW - $iH_Thumb / 2, _    ;4 end x position
                            $fRatio, _                      ;5 ratio
                            $iX, _                          ;6 start x position
                            $iValThumb]                     ;7 thumb size ratio
    Return $aSlider
EndFunc   ;==>GUICtrlCreateHSlider

Func GUICtrlCreateVSlider($iX, $iY, $iW, $iH, $iColor, $sFileThumb = "", $sFileBg = "", $iValThumb = 0, $iColorThumb = 0xD0005000, $iColorThumb_Center = 0xFF80E080, $iValMin = 0, $iValMax = 100, $fSize = 0.025, $fScale = 1.5)
    Local $hHBitmap_Thumb, $hHBitmap_Bg
    Local $idPic_Bg = GUICtrlCreatePic("", $iX, $iY, $iW, $iH)
    GUICtrlSetState(-1, $GUI_DISABLE)
    If $sFileBg <> "" And FileExists($sFileBg) Then
        $hHBitmap_Bg = _GDIPlus_CreateHBitmapFromFile($sFileBg, $iW, $iH)
    Else
        $hHBitmap_Bg = _GDIPlus_CreateRoundRectImage($iH, $iW, $iColor, $fSize, True, True)
    EndIf
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Bg, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Bg))
    _WinAPI_DeleteObject($hHBitmap_Bg)
    Local $iW_Thumb = $iW * $fScale
    Local $fRatio = $iH / Abs($iValMax - $iValMin)
    Local $idPic_Thumb = GUICtrlCreatePic("", $iX + ($iW - $iW_Thumb) / 2 + $iValThumb * $fRatio, $iY - ($iW_Thumb - $iH) / 2, $iW_Thumb, $iW_Thumb)
    If $sFileThumb <> "" And FileExists($sFileThumb) Then
        $hHBitmap_Thumb = _GDIPlus_CreateHBitmapFromFile($sFileThumb, $iW_Thumb, $iW_Thumb)
    Else
        $hHBitmap_Thumb = _GDIPlus_CreateEllipseThumb($iW_Thumb, $iColorThumb, $iColorThumb_Center)

    EndIf
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Thumb, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Thumb))
    _WinAPI_DeleteObject($hHBitmap_Thumb)
    Local $aSlider[8] = [   $idPic_Thumb, _                 ;0 control id
                            $iY - $iW_Thumb / 2, _          ;1 min y position thumb
                            $iX - ($iW_Thumb - $iW) / 2, _  ;2 center position thumb width
                            $iW_Thumb / 2, _                ;3 center thumb height
                            $iY + $iH - $iW_Thumb / 2, _    ;4 end Y position
                            $fRatio, _                      ;5 ratio
                            $iY, _                          ;6 start Y position
                            $iValThumb]                     ;7 thumb size ratio
    Return $aSlider
EndFunc   ;==>GUICtrlCreateVSlider

Func _GDIPlus_CreateRoundRectImage($iW, $iH, $iColor = 0xFF4080F0, $fSize = 0.025, $hHBitmap = True, $iRotate = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath_Bg = $aResult[2]
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath_Fg = $aResult[2]
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    Local $iColor_Bg = 0xFF000000 + 0x10000 * Max(BitShift(BitAND($iColor, 0x00FF0000) / 3, 16), 0x10) + 0x100 * Max(BitShift(BitAND($iColor, 0x0000FF00) / 3, 8), 0x10) + Max(BitAND($iColor, 0x000000FF / 3), 0x10)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iColor_Bg)
    Local $dW = Int($iW * $fSize)
    DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Bg, "float", 0, "float", 0, "float", $dW, "float", $iH, "float", 90, "float", 180) ;left arc
    DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Bg, "float", $iW - $dW - 1, "float", 0, "float", $dW, "float", $iH, "float", -90, "float", 180) ;right arc
    DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath_Bg)
    DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush, "handle", $hPath_Bg)

    $iH *= 0.89
    Local $iColor2 = 0xFF000000 + 0x10000 * Min(BitShift(BitAND($iColor, 0x00FF0000), 16) * 3, 0xFF) + 0x100 * Min(BitShift(BitAND($iColor, 0x0000FF00), 8) * 3, 0xFF) + Min(BitAND($iColor, 0x000000FF) * 3, 0xFF)
    Local $tRectF = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", DllStructGetPtr($tRectF), "int", $iColor2, "int", $iColor, "int", 1, "int", 0, "int*", 0)
    Local $hBrush_Gradient = $aResult[6]

    DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Fg, "float", 1, "float", 0, "float", $dW * 0.8, "float", $iH, "float", 90, "float", 180)
    DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Fg, "float", $iW - $dW - $dW / 5, "float", 0, "float", $dW * 0.8, "float", $iH, "float", -90, "float", 180)
    DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath_Fg)

    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Gradient, "handle", $hPath_Fg)

    DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath_Bg)
    DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath_Fg)

    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush_Gradient)

    Switch $iRotate
        Case 1
            DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", 1)
        Case 2
            DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", 3)
    EndSwitch

    If $hHBitmap Then
        Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_CreateRoundRectImage

Func _GDIPlus_CreateEllipseThumb($iSize, $iColor = 0xD0A00000, $iColor_Center = 0xFFFFA0A0, $hHBitmap = True, $sFile = "")
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    DllCall($ghGDIPDll, "int", "GdipAddPathEllipse", "handle", $hPath, "float", 0, "float", 0, "float", $iSize, "float", $iSize)
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    Local $hBrush_Gradient = $aResult[2]
    Local $fCenter = $iSize / 2
    Local $tPointF = DllStructCreate("float;float")
    DllStructSetData($tPointF, 1, $fCenter * 0.6)
    DllStructSetData($tPointF, 2, $fCenter * 0.4)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterPoint", "handle", $hBrush_Gradient, "ptr", DllStructGetPtr($tPointF))
    $tARGB = DllStructCreate("int")
    DllStructSetData($tARGB, 1, $iColor, 1)
    DllCall($ghGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush_Gradient, "int", DllStructGetPtr($tARGB), "int*", 1)
    DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "handle", $hBrush_Gradient, "int", True)
    DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterColor", "handle", $hBrush_Gradient, "int", $iColor_Center)
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iSize, "int", $iSize, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Gradient, "handle", $hPath)
    DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath)
    DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath)
    Local $hPen = _GDIPlus_PenCreate(0xD0080808)
    _GDIPlus_GraphicsDrawEllipse($hCtxt, 0, 0, $iSize - 1, $iSize - 1, $hPen)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BrushDispose($hBrush_Gradient)
    If $hHBitmap Then
        Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_CreateEllipseThumb

Func _GDIPlus_CreateHBitmapFromFile($sFile, $iW, $iH)
    Local $hBmp = _GDIPlus_BitmapCreateFromFile($sFile)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "handle", $hCtxt, "int", 7)
    _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBmp, 0, 0, $iW, $iH)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_GraphicsDispose($hCtxt)
    Local $hHBmp = _WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBmp
EndFunc   ;==>_GDIPlus_CreateHBitmapFromFile

Func _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) ;create 32-bit bitmap v5 (alpha channel supported)
    Local $tBIHDR, $aRet, $tData, $pBits, $hResult = 0
    $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aRet[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;')
    DllStructSetData($tBIHDR, 'bV5Size', DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 'bV5Width', $aRet[2])
    DllStructSetData($tBIHDR, 'bV5Height', $aRet[3])
    DllStructSetData($tBIHDR, 'bV5Planes', 1)
    DllStructSetData($tBIHDR, 'bV5BitCount', 32)
    DllStructSetData($tBIHDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIHDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIHDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIHDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIHDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIHDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIHDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIHDR, 'bV5Intent', 4) ; $LCS_GM_IMA
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
        DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $aRet[2] * $aRet[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
        $hResult = $hResult[0]
    Else
        $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_WinAPI_BitmapCreateDIBFromBitmap

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc   ;==>Min

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc   ;==>Max

 


It is beta and probably buggy!

All needed files in the attachment -> New Slider.7z (73 download previously)

post-29844-0-59531500-1378243480_thumb.j

Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Indeed I mixed up the topics. :whistle:

Nice examples rover! :thumbsup: I searched for Yashied's code but didn't find it and decided to hack something with built-in graphic creator using GDI+.

Br,

UEZ

Thanks UEZ

Nice pure math trackbar in GDI+!

Any idea on code to use alpha transparent images for the trackbar thumb?

Rounded thumb png's?

I see fascists...

Posted

@rover: I modified the code from post#3. Do you mean something like that? Don't forget to download the png image...

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Thank you guys.

rover, your examples are awesome but it would be great if i could use PNGs.

UEZ, glad to have you on this forum :idiot:

your examples are nice as well but the trackbar thumb somehow flicker if i use image background.

There's also another method which uses child GUI.

I've just modified it from Melba23's post.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>


Global Const $SC_DRAGMOVE = 0xF012


$hGUI = GUICreate("Test", 450, 200)
$Bar = GUICtrlCreatePic("", 15, 70, 408, 32)
GUICtrlSetImage($Bar, @ScriptDir & "\A.bmp")
GUISetState(@SW_SHOW)
Global $iBorder = _WinAPI_GetSystemMetrics(8)
Global $iBar = _WinAPI_GetSystemMetrics(4)
Global $aMain_Pos = WinGetPos($hGUI)


$hGUI_Slider = GUICreate("", 56, 68, 10, 52, $WS_POPUP,BitOR($WS_EX_MDICHILD,$WS_EX_TRANSPARENT), $hGUI)
$hPic = GUICtrlCreatePic("", 0, 0, 56, 68)
GUICtrlSetImage($hPic, @ScriptDir & "\B.bmp")
GUISetState(@SW_SHOW, $hGUI_Slider)
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")

While 1
$aMsg = GUIGetMsg(1)
Switch $aMsg[1]
Case $hGUI
Switch $aMsg[0]
Case $GUI_EVENT_CLOSE
     Exit
EndSwitch
Case $hGUI_Slider
Switch $aMsg[0]
Case $GUI_EVENT_PRIMARYDOWN
     _SendMessage($hGUI_Slider, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndSwitch
EndSwitch
WEnd


Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
If $hWnd = $hGUI_Slider Then
$aMain_Pos = WinGetPos($hGUI)
Local $iY = $aMain_Pos[1] + $iBorder + $iBar + 52
Local $iX_Min = $aMain_Pos[0] + $iBorder + 15
Local $iX_Max = $aMain_Pos[0] + $iBorder + 367
Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
Local $iLeft = DllStructGetData($stWinPos, 3)
Local $iTop = DllStructGetData($stWinPos, 4)
Local $iWidth = DllStructGetData($stWinPos, 5)
Local $iHeight = DllStructGetData($stWinPos, 6)

If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
If $iTop <> $iY Then DllStructSetData($stWinPos, 4, $iY)
EndIf
EndFunc ;==>WM_WINDOWPOSCHANGING

But the problem with this is that I can't make the child GUI transparent. :thumbsdown:

Edited by n1maS
Posted

My version is a different approach and I don't know how to avoid the flickering. It seems that the pic control gets repainted with an empty control and put the image into the control every time the control moves.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

That's true.

it took a me a day but in the end i gave up trying.

you don't have any idea about the third method (Child GUI Transparency) ?

:guitar:

Posted (edited)

Yes, you have to use GDI+ to load and convert the png image as shown in the example code with the smiley (_GDIPlus_CreateEllipseThumbFromFile() function)!

If I find some time a will have a look to your code...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

You can try something like this here but the png transparency is not fully supported!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()

$hGUI = GUICreate("Test", 450, 200)
$Bar = GUICtrlCreatePic("", 15, 70, 408, 32)
GUICtrlSetImage($Bar, @ScriptDir & "A.bmp")
Global $iBorder = _WinAPI_GetSystemMetrics(8)
Global $iBar = _WinAPI_GetSystemMetrics(4)
Global $aMain_Pos = WinGetPos($hGUI)

Global Const $IMAGE_BITMAP = 0
Global Const $STM_SETIMAGE = 0x0172
Global Const $iTransCol = 0x101010
Global $hGUI_Slider = GUICreate("", 0, 0, 100, 52, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_LAYERED, $hGUI)
Global $hBitmap = _GDIPlus_CreateHBitmapFromFile(@ScriptDir & "button_smiley.png", 56, 68)
_WinAPI_MakeGUITransparent($hGUI_Slider, $hBitmap, 56, 68)
GUISetState(@SW_SHOW, $hGUI_Slider)
GUISetState(@SW_SHOW, $hGUI)

GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
            EndSwitch
        Case $hGUI_Slider
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
                Case $GUI_EVENT_PRIMARYDOWN
                    _SendMessage($hGUI_Slider, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
            EndSwitch
    EndSwitch
WEnd

Func _Exit()
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

Func _WinAPI_MakeGUITransparent($hGUI, $hHBitmap, $iW, $iH, $iTrans = 0xFF)
    Local $hScrDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    Local $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    Local $tSize = DllStructCreate($tagSIZE)
    Local $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iW)
    DllStructSetData($tSize, "Y", $iH)
    Local $tSource = DllStructCreate($tagPOINT)
    Local $pSource = DllStructGetPtr($tSource)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iTrans)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_DeleteDC($hMemDC)
    Return 1
EndFunc   ;==>_WinAPI_MakeGUITransparentGUI

Func _GDIPlus_CreateHBitmapFromFile($sFile, $iW, $iH)
    Local $hBmp = _GDIPlus_BitmapCreateFromFile($sFile)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtxt, "int", 7)
    _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBmp, 0, 0, $iW, $iH)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_GraphicsDispose($hCtxt)
    Local $hHBmp = _WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBmp
EndFunc   ;==>_GDIPlus_CreateHBitmapFromFile

Func _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) ;create 32-bit bitmap v5 (alpha channel supported)
    Local $tBIHDR, $aRet, $tData, $pBits, $hResult = 0
    $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aRet[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;')
    DllStructSetData($tBIHDR, 'bV5Size', DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 'bV5Width', $aRet[2])
    DllStructSetData($tBIHDR, 'bV5Height', $aRet[3])
    DllStructSetData($tBIHDR, 'bV5Planes', 1)
    DllStructSetData($tBIHDR, 'bV5BitCount', 32)
    DllStructSetData($tBIHDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIHDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIHDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIHDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIHDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIHDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIHDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIHDR, 'bV5Intent', 4) ; $LCS_GM_IMA
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
        DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $aRet[2] * $aRet[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
        $hResult = $hResult[0]
    Else
        $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    $tData = 0
    $tBIHDR = 0
    Return $hResult
EndFunc   ;==>_WinAPI_BitmapCreateDIBFromBitmap

Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $hGUI_Slider Then
        $aMain_Pos = WinGetPos($hGUI)
        Local $iY = $aMain_Pos[1] + $iBorder + $iBar + 52
        Local $iX_Min = $aMain_Pos[0] + $iBorder + 15
        Local $iX_Max = $aMain_Pos[0] + $iBorder + 367
        Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
        Local $iLeft = DllStructGetData($stWinPos, 3)
        Local $iTop = DllStructGetData($stWinPos, 4)
        Local $iWidth = DllStructGetData($stWinPos, 5)
        Local $iHeight = DllStructGetData($stWinPos, 6)

        If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
        If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
        If $iTop <> $iY Then DllStructSetData($stWinPos, 4, $iY)
    EndIf
EndFunc   ;==>WM_WINDOWPOSCHANGING

But it is not flickering on movement...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Thanks a lot UEZ. You made my day :D

It looks vey nice! but as you said transparency is not full. can you fix it too?

BTW, your Load_BMP_From_Mem function worked perfectly with PNG.

Thanks

Edited by n1maS
Posted (edited)

Thanks.

Can you mark this topic as Solved?

maybe it'll help someone else.

Edited by n1maS
Posted (edited)

Um one more thing UEZ

try to a create a label with text (code in post#10)

the problem is that the label doesn't display anything.

never mind. problem solved. :idiot:

Edited by n1maS

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...