rover Posted September 6, 2008 Share Posted September 6, 2008 (edited) Change displayed value format, title text, colour and dimensions of GUICtrlCreateSlider() controla workaround for updating slider tooltips for desired display format.Edit: scaled decimal places back down to 1Edit: fixed error with tooltip displaying 1.01 instead of 1.00 as pointed out by Andreik and corrected by Martin.Thanks Guys!expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GuiSlider.au3> #include <GuiToolTip.au3> Opt('MustDeclareVars', 1) Global $Slider, $hSlider, $hWndTT, $Dummy, $iBuffer, $iMode = 0, $iColour = 0, $Label1, $Label2 Example() Func Example() Local $hGUI, $msg, $BtnMode, $BtnColour $hGUI = GUICreate("Slider Tooltip Modifying Demo", 280, 100) $Slider = GUICtrlCreateSlider(40, 10, 200, 30, BitOR($TBS_AUTOTICKS, $TBS_TOOLTIPS)) $hSlider = GUICtrlGetHandle($Slider) GUICtrlSetLimit(-1, 201, 0) ; change min/max value GUICtrlSetData($Slider, 100) ; set cursor GUICtrlSetCursor(-1, 0) $hWndTT = _GUICtrlSlider_GetToolTips($hSlider) _GUICtrlSlider_SetTicFreq($hSlider, 1) ; set tics divisor _GUICtrlSlider_SetTipSide($hSlider, $TBTS_BOTTOM) _GUIToolTip_SetTitle($hWndTT, "Value 1.00") _GUIToolTip_SetMargin($hWndTT, -5, -5, -5, -20) _GUIToolTip_SetTipTextColor($hWndTT, 0xFFFFFF) _GUIToolTip_SetTipBkColor($hWndTT, 0x985428) $Dummy = GUICtrlCreateDummy() $BtnMode = GUICtrlCreateButton("Mode", 40, 70, 80, 20, $SS_CENTER) $BtnColour = GUICtrlCreateButton("Colour", 160, 70, 80, 20, $SS_CENTER) $Label1 = GUICtrlCreateLabel("Float", 40, 50, 80, 20) $Label2 = GUICtrlCreateLabel("Custom Colour", 160, 50, 80, 20) GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $Dummy _Slider() Case $BtnMode _Mode() Case $BtnColour _ToolTipColour() EndSwitch Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _ToolTipColour() $iColour = Not $iColour Switch $iColour Case 0 _GUIToolTip_SetTipTextColor($hWndTT, 0xFFFFFF) ; set custom colour for tooltip text _GUIToolTip_SetTipBkColor($hWndTT, 0x985428) ; set custom colour for tooltip background GUICtrlSetData($Label2, "Custom Colour") Case 1 ;$COLOR_INFOTEXT - Restore slider tooltip to system text color for tooltip controls _GUIToolTip_SetTipTextColor($hWndTT, _WinAPI_GetSysColor($COLOR_INFOTEXT)) ;$COLOR_INFOBK - Restore slider tooltip to system background color for tooltip control _GUIToolTip_SetTipBkColor($hWndTT, _WinAPI_GetSysColor($COLOR_INFOBK)) GUICtrlSetData($Label2, "System Colour") EndSwitch EndFunc ;==>_ToolTipColour Func _Mode() $iMode = Not $iMode Switch $iMode Case 0 $iBuffer = "" GUICtrlSetLimit($Slider, 201, 0) ; change min/max value GUICtrlSetData($Slider, 100) ; set slider cursor GUICtrlSetData($Label1, "Float") Case 1 $iBuffer = "" GUICtrlSetLimit($Slider, 26, 1) ; change min/max value GUICtrlSetData($Slider, 1) ; set slider cursor GUICtrlSetData($Label1, "String") EndSwitch EndFunc ;==>_Mode Func _Slider() Local $iValue, $sValue $iValue = GUICtrlRead($Dummy); read dummy control for value of slider ;ConsoleWrite('+$iValue = ' & $iValue & @crlf) ;** If $iBuffer <> $iValue Then ; buffer read slider value to prevent unnecessary updating at end of slider range. ** $iBuffer = $iValue If $iBuffer > 200 then $iBuffer = 200 Switch $iMode Case 0 ; float $iBuffer *= 0.01 $sValue = StringFormat("Value: %.2f", $iBuffer) Case 1 ; string $sValue = "Value: " & Chr($iBuffer + 64) EndSwitch _GUIToolTip_SetTitle($hWndTT, $sValue) ; set slider tooltip title text _GUIToolTip_Update($hWndTT) ; update slider tooltip ConsoleWrite('-Value = ' & $iBuffer & @CRLF) EndIf Return EndFunc ;==>_Slider Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam) ; Slider #forceref $hWnd, $iMsg, $wParam, $lParam Switch $lParam Case $hSlider GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider)) EndSwitch EndFunc ;==>WM_HVSCROLL Edited September 7, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
Andreik Posted September 6, 2008 Share Posted September 6, 2008 (edited) Very nice. Only one thing, I can't set slider on value 1.00. Edited September 6, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rover Posted September 6, 2008 Author Share Posted September 6, 2008 (edited) Very nice. Only one thing, I can't set slider on value 1.00. @Andreik Agreed I was pushing it with trying for more decimal places. probably exceeded the controls range, haven't checked msdn. have scaled the example back down to 1 decimal place. Edit: typo, one decimal place with trailing zero, not two.. 5am here, I'm out.. Edit: Rasim has corrected the _GUIToolTip_Create() function (was missing its struct) my above conclusion was wrong with a closer look at GuiToolTip.au3 Rasim made a working example that combined _GUIToolTip_Create() (a wrapper for _WinAPI_CreateWindowEx) and _GUIToolTip_AddTool() (has the struct) with other tooltip sendmessage commands making it easier to understand. I couldn't initially get the addtool function to work until trying Rasims example. will see what I can change or add to this, I still like using the title with its larger bold font instead of the text. see his example in this thread: here with some control tracking it will make a good replacement for this workaround for slider tooltip customizing. just what I was looking for. perhaps he will post an example here or in his own topic ToolTip UDF if I don't get around to it first. Edited September 7, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
martin Posted September 6, 2008 Share Posted September 6, 2008 @Rover - Thanks for your nice example. The help file could do with this. @Andreik You can get 1.00 if you change GUICtrlSetLimit($Slider, 200, 0) to GUICtrlSetLimit($Slider, 201, 0);<------in 2 places Then, to stop 2.01 being displayed add a limit in _Slider() Func _Slider() Local $sValue,$iValue, ;ConsoleWrite('+$iValue = ' & $iValue & @crlf) ** If $iBuffer <> $iValue Then; buffer read slider value to prevent unnecessary updating at end of slider range. ** $iBuffer = $iValue Switch $iMode Case 0; float If $iBuffer > 200 then $iBuffer = 200;<------------added $iBuffer *= 0.01;<---------------------------------changed $iValue to $iBuffer $sValue = StringFormat("Value: %.2f", $iBuffer);<--changed $iValue to $iBuffer Case 1; string $sValue = "Value: " & Chr($iValue + 64) EndSwitch _GUIToolTip_SetTitle($hWndTT, $sValue); set slider tooltip title text _GUIToolTip_Update($hWndTT); update slider tooltip ConsoleWrite('-Value = ' & $iBuffer & @CRLF) EndIf Return EndFunc ;==>_Slider Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Andreik Posted September 6, 2008 Share Posted September 6, 2008 @Rover - Thanks for your nice example. The help file could do with this. @Andreik You can get 1.00 if you change GUICtrlSetLimit($Slider, 200, 0) to GUICtrlSetLimit($Slider, 201, 0);<------in 2 places Then, to stop 2.01 being displayed add a limit in _Slider() Func _Slider() Local $sValue,$iValue, ;ConsoleWrite('+$iValue = ' & $iValue & @crlf) ** If $iBuffer <> $iValue Then; buffer read slider value to prevent unnecessary updating at end of slider range. ** $iBuffer = $iValue Switch $iMode Case 0; float If $iBuffer > 200 then $iBuffer = 200;<------------added $iBuffer *= 0.01;<---------------------------------changed $iValue to $iBuffer $sValue = StringFormat("Value: %.2f", $iBuffer);<--changed $iValue to $iBuffer Case 1; string $sValue = "Value: " & Chr($iValue + 64) EndSwitch _GUIToolTip_SetTitle($hWndTT, $sValue); set slider tooltip title text _GUIToolTip_Update($hWndTT); update slider tooltip ConsoleWrite('-Value = ' & $iBuffer & @CRLF) EndIf Return EndFunc ;==>_Slider If I change _Slider function with your example then ToolTip will show all times value 1.00 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
martin Posted September 6, 2008 Share Posted September 6, 2008 If I change _Slider function with your example then ToolTip will show all times value 1.00 Here is the original script posted by Rover but changed as I suggested. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GuiSlider.au3> #include <GuiToolTip.au3> Opt('MustDeclareVars', 1) Global $Slider, $hSlider, $hWndTT, $Dummy, $iBuffer, $iMode = 0, $iColour = 0, $Label1, $Label2 Example() Func Example() Local $hGUI, $msg, $BtnMode, $BtnColour $hGUI = GUICreate("Slider Tooltip Modifying Demo", 280, 100) $Slider = GUICtrlCreateSlider(40, 10, 200, 30, BitOR($TBS_AUTOTICKS, $TBS_TOOLTIPS)) $hSlider = GUICtrlGetHandle($Slider) GUICtrlSetLimit(-1, 201, 0); change min/max value GUICtrlSetData($Slider, 10); set cursor GUICtrlSetCursor(-1, 0) $hWndTT = _GUICtrlSlider_GetToolTips($hSlider) _GUICtrlSlider_SetTicFreq($hSlider, 1); set tics divisor _GUICtrlSlider_SetTipSide($hSlider, $TBTS_BOTTOM) _GUIToolTip_SetTitle($hWndTT, "Value 1.00") _GUIToolTip_SetMargin($hWndTT, -5, -5, -5, -20) _GUIToolTip_SetTipTextColor($hWndTT, 0xFFFFFF) _GUIToolTip_SetTipBkColor($hWndTT, 0x985428) $Dummy = GUICtrlCreateDummy() $BtnMode = GUICtrlCreateButton("Mode", 40, 70, 80, 20, $SS_CENTER) $BtnColour = GUICtrlCreateButton("Colour", 160, 70, 80, 20, $SS_CENTER) $Label1 = GUICtrlCreateLabel("Float", 40, 50, 80, 20) $Label2 = GUICtrlCreateLabel("Custom Colour", 160, 50, 80, 20) GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $Dummy _Slider() Case $BtnMode _Mode() Case $BtnColour _ToolTipColour() EndSwitch Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _ToolTipColour() $iColour = Not $iColour Switch $iColour Case 0 _GUIToolTip_SetTipTextColor($hWndTT, 0xFFFFFF); set custom colour for tooltip text _GUIToolTip_SetTipBkColor($hWndTT, 0x985428); set custom colour for tooltip background GUICtrlSetData($Label2, "Custom Colour") Case 1 ;$COLOR_INFOTEXT - Restore slider tooltip to system text color for tooltip controls _GUIToolTip_SetTipTextColor($hWndTT, _WinAPI_GetSysColor($COLOR_INFOTEXT)) ;$COLOR_INFOBK - Restore slider tooltip to system background color for tooltip control _GUIToolTip_SetTipBkColor($hWndTT, _WinAPI_GetSysColor($COLOR_INFOBK)) GUICtrlSetData($Label2, "System Colour") EndSwitch EndFunc ;==>_ToolTipColour Func _Mode() $iMode = Not $iMode Switch $iMode Case 0 $iBuffer = "" GUICtrlSetLimit($Slider, 201, 0); change min/max value GUICtrlSetData($Slider, 10); set slider cursor GUICtrlSetData($Label1, "Float") Case 1 $iBuffer = "" GUICtrlSetLimit($Slider, 26, 1); change min/max value GUICtrlSetData($Slider, 1); set slider cursor GUICtrlSetData($Label1, "String") EndSwitch EndFunc ;==>_Mode Func _Slider() Local $iValue, $sValue $iValue = GUICtrlRead($Dummy); read dummy control for value of slider ;ConsoleWrite('+$iValue = ' & $iValue & @crlf);** If $iBuffer <> $iValue Then; buffer read slider value to prevent unnecessary updating at end of slider range. ** $iBuffer = $iValue If $iBuffer > 200 then $iBuffer = 200 Switch $iMode Case 0; float $iBuffer *= 0.01 $sValue = StringFormat("Value: %.2f", $iBuffer) Case 1; string $sValue = "Value: " & Chr($iBuffer + 64) EndSwitch _GUIToolTip_SetTitle($hWndTT, $sValue); set slider tooltip title text _GUIToolTip_Update($hWndTT); update slider tooltip ConsoleWrite('-Value = ' & $iBuffer & @CRLF) EndIf Return EndFunc ;==>_Slider Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam); Slider #forceref $hWnd, $iMsg, $wParam, $lParam Switch $lParam Case $hSlider GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider)) EndSwitch EndFunc ;==>WM_HVSCROLL Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Andreik Posted September 6, 2008 Share Posted September 6, 2008 Now work fine. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rover Posted September 7, 2008 Author Share Posted September 7, 2008 @Andreik @Martin Thanks Guys! Martin, good call on the buffer and value vars being reversed and adding 1 to the max value. It's easy to miss things, when tired or not. I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now