Jump to content

2 slider control questions


4Eyes
 Share

Recommended Posts

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
Link to comment
Share on other sites

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 by smashly
Link to comment
Share on other sites

  • 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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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 by therks
Link to comment
Share on other sites

  • Moderators

4Eyes,

Is this what you wanted? :idea:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

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

post-47302-12738895776768_thumb.jpg

Edited by 4Eyes
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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