4Eyes Posted April 21, 2010 Posted April 21, 2010 Folks, 1) How can I get events for a slider as it moves (preferably if it's value has changed, rather than just a continuous stream of msg's) instead of just when it's released? 2) How can I set the tooltip text of a slider to something other than its value? I've attached a short example to show what I've tried so far, but without success. Thanks, 4Eyes #include <GUIConstantsEx.au3> #Include <GuiSlider.au3> #Include <GuiToolTip.au3> $gui1 = GUICreate("Slider test", 250, 120, -1, -1) $slider1 = GUICtrlCreateSlider(20, 30, 180, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS)) _GUICtrlSlider_SetRange($slider1, 0, 50) _GUICtrlSlider_SetTicFreq($slider1, 4) _GUICtrlSlider_SetPageSize($slider1, 2) $lbl1 = GUICtrlCreateLabel("Slider value", 100, 80, 100, 20) GUISetState(@SW_SHOW) ; Shows that _GUICtrlSlider_GetToolTips() worked ConsoleWrite("_GUICtrlSlider_GetToolTips($slider1) = " & _GUICtrlSlider_GetToolTips($slider1) & @CRLF) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $slider1 GUICtrlSetData($lbl1, GUICtrlRead($slider1)) _GUIToolTip_SetToolInfo(_GUICtrlSlider_GetToolTips($slider1), "Test") EndSwitch WEnd
smashly Posted April 21, 2010 Posted April 21, 2010 (edited) Hi, as for realtime reading the slider here's one way. #include <GUIConstantsEx.au3> #Include <GuiSlider.au3> Global $hGui, $iSlider, $iLabel, $nMsg Global $iOld = 0, $iCur = 0 $hGui = GUICreate("Slider test", 250, 120, -1, -1) $iSlider = GUICtrlCreateSlider(20, 30, 180, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS)) GUICtrlSetLimit(-1, 50, 0) $iLabel = GUICtrlCreateLabel("Slider value: " & $iOld, 100, 80, 100, 20) GUISetState(@SW_SHOW, $hGui) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $iSlider ;; Do whatever here Case Else $iCur = GUICtrlRead($iSlider) If $iOld <> $iCur Then $iOld = $iCur GUICtrlSetData($iLabel, "Slider value: " & $iOld) EndIf EndSwitch WEnd There's another way using GUIRegistterMsg(), but I can't think of it atm. As for tool tips, depends on what your trying to accomplish. Cheers Edited April 21, 2010 by smashly
AdmiralAlkex Posted April 22, 2010 Posted April 22, 2010 Look at the example AlphaBlend.au3 in \AutoIt3\Examples\GUI\Advanced\As smashly said, you need to tell us what you actually want to do if you want a good answer. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
4Eyes Posted April 22, 2010 Author Posted April 22, 2010 smashly, Thanks for that and while it works it detects any other GUI event. I suppose if I trap everything else that I want and the slider is selected then it's logical to assume that the user is doing something with it. Ultimately what I'd like to do is inspired by the 3rd graphic down on this page: http://www.anandtech.com/show/3640/apples-ipad-the-anandtech-review/11 Notice the VERY sexy slider that selects days of the month? That's AWESOME and I don't intend to try to achieve that, however, I would like to have the sliders tooltip display something other than it's position. The intention is try a slider to select a time. The slider has 48 increments being 15 minute slots in a 12 hour timeframe. While I can compute the relative time and update a label, due to lack of GUI real estate I'd like to have the time in the tooltip. You can now see why I want events for each movement of the slider. You also reminded me that once before I used GUIRegisterMsg(), but without knowing what event to register and handle I'm a little lost. Regards, 4Eyes
therks Posted April 30, 2010 Posted April 30, 2010 (edited) Well I don't know about the second part of your question, but the message you want to hook into looks like WM_NOTIFY to me. *Edit: I should mention the reason I don't know is because your link isn't working for me. #include <GuiConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $gui = GUICreate('', 200, 200) $sl1 = GUICtrlCreateSlider(5, 5, 190, 20) $sl2 = GUICtrlCreateSlider(5, 45, 190, 20) GUISetState() GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') While 1 $gm = GUIGetMsg() Switch $gm Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hwnd, $msg, $wparam, $lparam) $ctrlID = _WinAPI_LoWord($wparam) Switch $ctrlID Case $sl1 $read = GUICtrlRead($ctrlID) ToolTip('Slider 1: ' & $read) Case $sl2 $read = GUICtrlRead($ctrlID) ToolTip('Slider 2: ' & $read) EndSwitch Return $GUI_RUNDEFMSG EndFunc Edited April 30, 2010 by therks My AutoIt Stuff | My Github
Moderators Melba23 Posted April 30, 2010 Moderators Posted April 30, 2010 4Eyes, Is this what you wanted? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) $hSlider = GUICtrlCreateSlider(10, 50, 480, 40) $hSlider_Handle = GUICtrlGetHandle(-1) GUICtrlSetLimit(-1, 48) GUISetState() GUIRegisterMsg($WM_HSCROLL, "WM_H_Slider") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP ToolTip("") EndSwitch WEnd ; React to slider movement Func WM_H_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam If $lParam = $hSlider_Handle Then $iValue = GUICtrlRead($hSlider) $iHour = StringFormat("%02i", Int($iValue / 4)) $iMin = StringFormat("%02i", 15 * Mod($iValue, 4)) ToolTip($iHour & ":" & $iMin) EndIf Return $GUI_RUNDEFMSG EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
4Eyes Posted May 15, 2010 Author Posted May 15, 2010 (edited) Guys, I feel really embarrassed to have left replying for so long. 4 very useful replies.. thank you. Now individually: smashly. Thanks mate. Ah, I thought saying "something other than its value" was enough. I meant text not a graphic. I was just trying to get advice, not asking you guys to write a complete solution. AdmiralAlkex, I've never looked in \AutoIt3\Examples\GUI\Advanced\ and am blown away with the alphablend example. Very nice. I've been thru the help file a million times amd have gleaned much info but don't understand it all. Now I've got some more stuff to go thru. Thanks. Melba23, Sorry for the late reply but wow! That's nice. If I had the real estate.... hmmm. therks, Thanks for your reply too. The link still works for me. I've attached a copy of the graphic in question. Have a look at the slider on the bottom. Really nice! Again guys, sorry for not ack'ing your replies earlier and all are interesting and appreciated. Regards, 4Eyes Edited May 15, 2010 by 4Eyes
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