Viktor1703
AutoIT Гуру
- Сообщения
- 1,535
- Репутация
- 413
Не пойму как расчитать процентовку для бегунка, чтоб не зависила от ширины слайдера и максимальное значение было 100
Вот такой он получился:
Код:
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
Global $Procent = 1
$hForm = GUICreate("Test", 400, 300, -1, -1, -1, $WS_EX_COMPOSITED)
GUISetBkColor(0x000000)
$Font = GUICtrlCreatePic("", 80, 80, 128, 18)
_SetPNGIntoPicControl($Font, @ScriptDir & '\fon_reg.png')
GUICtrlSetState($Font, 128)
$Track = GUICtrlCreatePic("", 0, 0, 0, 0, 0x00000200)
_SetPNGIntoPicControl($Track, @ScriptDir & '\trek.png')
GUICtrlSetState($Track, $GUI_HIDE)
GUICtrlSetState($Font, 128)
GUICtrlSetState($Track, $GUI_ONTOP)
$Tip = GUICtrlCreatePic("", 0, 0, 39, 39, 0x00000200)
_SetPNGIntoPicControl($Tip, @ScriptDir & '\tip.png')
GUICtrlSetState($Tip, 128)
GUICtrlSetState($Tip, $GUI_HIDE)
$Proc = GUICtrlCreateLabel('', 0, 0, 39, 39, 0x01)
GUICtrlSetBkColor($Proc, -2)
GUICtrlSetColor($Proc, 0xFFFFFF)
GUICtrlSetState($Proc, $GUI_ONTOP)
$Reg = GUICtrlCreatePic("", 80, 80, 18, 18, 0x00000200)
_SetPNGIntoPicControl($Reg, @ScriptDir & '\reg.png')
GUICtrlSetState($Reg, $GUI_ONTOP)
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
GUISetState()
$OldStyle = DllCall('user32.dll', 'long_ptr', 'GetWindowLongPtrW', 'hwnd', $hForm, 'int', -16)
DllCall('user32.dll', 'long_ptr', 'SetWindowLongPtrW', 'hwnd', $hForm, 'int', -16, 'long_ptr', BitOR($OldStyle, 0x04000000, 0x02000000))
While True
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_MOUSEMOVE
If IsMouseOver(GUICtrlGetHandle($Reg)) Then
$Cursor = DllCall("user32.dll", "short", "GetAsyncKeyState", "int", 01)
If $Cursor[0] Then
$aMouse = MouseGetPos()
$aWindow = WinGetPos($hWnd)
$aX = ($aMouse[0] - $aWindow[0]) - 9
$FontPos = ControlGetPos($hWnd, "", $Font)
If $aX < $FontPos[0] Then $aX = 80
If $aX > ($FontPos[2] + $FontPos[0] - 18) Then $aX = ($FontPos[2] + 80) - 18
If $aX <= $FontPos[0] Then GUICtrlSetState($Track, $GUI_HIDE)
If $aX > 82 Then GUICtrlSetState($Track, $GUI_SHOW)
GUICtrlSetPos($Track, 86, 82, $aX - 80, 14)
GUICtrlSetPos($Reg, $aX, 80, 18, 18)
GUICtrlSetState($tip, $GUI_SHOW)
GUICtrlSetState($Proc, $GUI_SHOW)
GUICtrlSetPos($tip, $aX - 10, 35, 39, 39)
GUICtrlSetPos($Proc, $aX - 10, 45, 39, 20)
GUICtrlSetData($Proc, $Procent & "%")
$Procent = $aX - 80
EndIf
Else
GUICtrlSetState($Proc, $GUI_HIDE)
GUICtrlSetState($tip, $GUI_HIDE)
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func IsMouseOver($hWnd)
Local $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
Local $tPoint = DllStructCreate("long X;long Y")
DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $hWnd, "ptr", DllStructGetPtr($tRect))
DllCall("user32.dll", "bool", "GetCursorPos", "ptr", DllStructGetPtr($tPoint))
Local $iX = DllStructGetData($tPoint, "X")
Local $iY = DllStructGetData($tPoint, "Y")
Local $Ret = DllCall("user32.dll", "bool", "PtInRect", "ptr", DllStructGetPtr($tRect), "long", $iX, "long", $iY)
If @error Then Return SetError(@error, @extended, False)
Return $Ret[0]
EndFunc
Func _SetPNGIntoPicControl($iPic, $sPNGFile)
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($sPNGFile)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x172, 0, $hBitmap))
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc
Вот такой он получился: