name22

SliderEx UDF

Jun 29th, 2011
230
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GDIP.au3>
  2. #include <WinAPI.au3>
  3. #include <WindowsConstants.au3>
  4. #include <Constants.au3>
  5.  
  6. ; - Author: name22 (www.autoit.de)
  7.  
  8. _GDIPlus_Startup()
  9.  
  10. Global $aSliderExData[1][14]
  11. $aSliderExData[0][0] = 0
  12.  
  13. GUIRegisterMsg($WM_PAINT, "__SliderEx_ReDraw")
  14. OnAutoItExitRegister("_GDIPlus_Shutdown")
  15. AdlibRegister("__SliderEx_CheckMouse", 20)
  16.  
  17. Func _SliderEx_Create($hWnd, $iX, $iY, $iWidth, $iHeight, $iMin, $iMax, $ColorBG1 = 0xFF0F0F0F, $ColorBG2 = 0xFFF0F0F0, $ColorSlider1 = 0xFFA0A0A0, $ColorSlider2 = 0xFFE0E0E0, $ColorEdge = 0xFF505050, $ColorShadow = 0xD0000000, $iShadowLength = 8)
  18.     $aSliderExData[0][0] += 1
  19.     ReDim $aSliderExData[$aSliderExData[0][0] + 1][14]
  20.  
  21.     $aSliderExData[$aSliderExData[0][0]][0] = 0
  22.     $aSliderExData[$aSliderExData[0][0]][1] = $iMin
  23.     $aSliderExData[$aSliderExData[0][0]][2] = $iMax
  24.     $aSliderExData[$aSliderExData[0][0]][3] = DllStructCreate("int X;int Y;int Width;int Height")
  25.     DllStructSetData($aSliderExData[$aSliderExData[0][0]][3], "X", $iX)
  26.     DllStructSetData($aSliderExData[$aSliderExData[0][0]][3], "Y", $iY)
  27.     DllStructSetData($aSliderExData[$aSliderExData[0][0]][3], "Width", $iWidth)
  28.     DllStructSetData($aSliderExData[$aSliderExData[0][0]][3], "Height", $iHeight)
  29.     $aSliderExData[$aSliderExData[0][0]][4] = $hWnd
  30.     $aSliderExData[$aSliderExData[0][0]][5] = _GDIPlus_GraphicsCreateFromHWND($hWnd)
  31.     $aSliderExData[$aSliderExData[0][0]][6] = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $aSliderExData[$aSliderExData[0][0]][5])
  32.     $aSliderExData[$aSliderExData[0][0]][7] = _GDIPlus_ImageGetGraphicsContext($aSliderExData[$aSliderExData[0][0]][6])
  33.     _GDIPlus_GraphicsSetSmoothingMode($aSliderExData[$aSliderExData[0][0]][7], 2)
  34.     $aSliderExData[$aSliderExData[0][0]][8] = _GDIPlus_LineBrushCreate(0, 0, $iWidth + 1, 0, $ColorBG1, $ColorBG2)
  35.     $aSliderExData[$aSliderExData[0][0]][9] = _GDIPlus_LineBrushCreate(0, 0, 5, 0, $ColorSlider1, $ColorSlider2, 1)
  36.     $aSliderExData[$aSliderExData[0][0]][10] = _GDIPlus_LineBrushCreate(0, 0, $iShadowLength, 0, $ColorShadow, 0x00000000)
  37.     $aSliderExData[$aSliderExData[0][0]][11] = _GDIPlus_PenCreate($ColorEdge)
  38.     GUISwitch($hWnd)
  39.     $aSliderExData[$aSliderExData[0][0]][12] = GUICtrlCreateLabel("", $iX - 5, $iY, $iWidth + 10, $iHeight)
  40.     $aSliderExData[$aSliderExData[0][0]][13] = $iShadowLength
  41.  
  42.     __SliderEx_Draw($aSliderExData[0][0])
  43.  
  44.     Return $aSliderExData[0][0]
  45. EndFunc   ;==>_SliderEx_Create
  46.  
  47. Func __SliderEx_Draw($cSlEx)
  48.     _GDIPlus_LineBrushTranslateTransform($aSliderExData[$cSlEx][9], $aSliderExData[$cSlEx][0] - 5, 0)
  49.     _GDIPlus_LineBrushTranslateTransform($aSliderExData[$cSlEx][10], $aSliderExData[$cSlEx][0] + 5, 0)
  50.     _GDIPlus_GraphicsFillRect($aSliderExData[$cSlEx][7], 0, 0, DllStructGetData($aSliderExData[$cSlEx][3], "Width"), DllStructGetData($aSliderExData[$cSlEx][3], "Height"), $aSliderExData[$cSlEx][8])
  51.     _GDIPlus_GraphicsFillRect($aSliderExData[$cSlEx][7], $aSliderExData[$cSlEx][0] - 5, 2, 10, DllStructGetData($aSliderExData[$cSlEx][3], "Height") - 4, $aSliderExData[$cSlEx][9])
  52.     _GDIPlus_GraphicsFillRect($aSliderExData[$cSlEx][7], $aSliderExData[$cSlEx][0] + 5, 2, $aSliderExData[$cSlEx][13] - 1, DllStructGetData($aSliderExData[$cSlEx][3], "Height") - 4, $aSliderExData[$cSlEx][10])
  53.     _GDIPlus_GraphicsDrawRect($aSliderExData[$cSlEx][7], $aSliderExData[$cSlEx][0] - 5, 2, 10, DllStructGetData($aSliderExData[$cSlEx][3], "Height") - 4, $aSliderExData[$cSlEx][11])
  54.     _GDIPlus_GraphicsDrawRect($aSliderExData[$cSlEx][7], 0, 0, DllStructGetData($aSliderExData[$cSlEx][3], "Width"), DllStructGetData($aSliderExData[$cSlEx][3], "Height"), $aSliderExData[$cSlEx][11])
  55.     _GDIPlus_LineBrushTranslateTransform($aSliderExData[$cSlEx][9], -($aSliderExData[$cSlEx][0] - 5), 0)
  56.     _GDIPlus_LineBrushTranslateTransform($aSliderExData[$cSlEx][10], -($aSliderExData[$cSlEx][0] + 5), 0)
  57.  
  58.     _WinAPI_RedrawWindow($aSliderExData[$cSlEx][4], 0, 0, $RDW_UPDATENOW)
  59.     _GDIPlus_GraphicsDrawImageRect($aSliderExData[$cSlEx][5], $aSliderExData[$cSlEx][6], DllStructGetData($aSliderExData[$cSlEx][3], "X"), DllStructGetData($aSliderExData[$cSlEx][3], "Y"), DllStructGetData($aSliderExData[$cSlEx][3], "Width"), DllStructGetData($aSliderExData[$cSlEx][3], "Height"))
  60.     _WinAPI_RedrawWindow($aSliderExData[$cSlEx][4], 0, 0, $RDW_VALIDATE)
  61. EndFunc   ;==>__SliderEx_Draw
  62.  
  63. Func __SliderEx_ReDraw()
  64.     For $i = 1 To $aSliderExData[0][0]
  65.         _WinAPI_RedrawWindow($aSliderExData[$i][4], 0, 0, $RDW_UPDATENOW)
  66.         _GDIPlus_GraphicsDrawImageRect($aSliderExData[$i][5], $aSliderExData[$i][6], DllStructGetData($aSliderExData[$i][3], "X"), DllStructGetData($aSliderExData[$i][3], "Y"), DllStructGetData($aSliderExData[$i][3], "Width"), DllStructGetData($aSliderExData[$i][3], "Height"))
  67.         _WinAPI_RedrawWindow($aSliderExData[$i][4], 0, 0, $RDW_VALIDATE)
  68.     Next
  69. EndFunc   ;==>__SliderEx_ReDraw
  70.  
  71. Func __SliderEx_CheckMouse()
  72.     For $i = 1 To $aSliderExData[0][0]
  73.         $aCursorInfo = GUIGetCursorInfo($aSliderExData[$i][4])
  74.         If $aCursorInfo[2] And $aCursorInfo[4] = $aSliderExData[$i][12] Then
  75.             $iPosTmp = $aCursorInfo[0] - DllStructGetData($aSliderExData[$i][3], "X")
  76.             Select
  77.                 Case $iPosTmp < 0
  78.                     _SliderEx_SetPos($i, 0)
  79.                 Case $iPosTmp > DllStructGetData($aSliderExData[$i][3], "Width")
  80.                     _SliderEx_SetPos($i, DllStructGetData($aSliderExData[$i][3], "Width"))
  81.                 Case Else
  82.                     _SliderEx_SetPos($i, $aCursorInfo[0] - DllStructGetData($aSliderExData[$i][3], "X"))
  83.             EndSelect
  84.         EndIf
  85.     Next
  86. EndFunc   ;==>__SliderEx_CheckMouse
  87.  
  88. Func _SliderEx_CalculatePos($cSlEx, $iValue)
  89.     $VPP = DllStructGetData($aSliderExData[$cSlEx][3], "Width") / ($aSliderExData[$cSlEx][2] - $aSliderExData[$cSlEx][1])
  90.     Return Round($iValue * $VPP)
  91. EndFunc
  92.  
  93. Func _SliderEx_CalculateValue($cSlEx, $iPos)
  94.     $PPV = ($aSliderExData[$cSlEx][2] - $aSliderExData[$cSlEx][1]) / DllStructGetData($aSliderExData[$cSlEx][3], "Width")
  95.     Return $aSliderExData[$cSlEx][1] + Ceiling($iPos * $PPV)
  96. EndFunc
  97.  
  98. Func _SliderEx_SetValue($cSlEx, $iValue)
  99.     _SliderEx_SetPos($cSlEx, _SliderEx_CalculatePos($cSlEx, $iValue))
  100. EndFunc
  101.  
  102. Func _SliderEx_SetPos($cSlEx, $iPos)
  103.     $aSliderExData[$cSlEx][0] = $iPos
  104.     __SliderEx_Draw($cSlEx)
  105. EndFunc
  106.  
  107. Func _SliderEx_GetValue($cSlEx)
  108.     Return _SliderEx_CalculateValue($cSlEx, $aSliderExData[$cSlEx][0])
  109. EndFunc
  110.  
  111. Func _SliderEx_Destroy($cSlEx)
  112.     _GDIPlus_GraphicsDispose($aSliderExData[$cSlEx][5])
  113.     _GDIPlus_GraphicsDispose($aSliderExData[$cSlEx][7])
  114.     _GDIPlus_BitmapDispose($aSliderExData[$cSlEx][6])
  115.     _GDIPlus_BrushDispose($aSliderExData[$cSlEx][8])
  116.     _GDIPlus_BrushDispose($aSliderExData[$cSlEx][9])
  117. EndFunc   ;==>_SliderEx_Destroy
RAW Paste Data