Jump to content

Recommended Posts

Posted

Every code example I can find with tooltip being used has a sleep right after it.

How does one display a tool tip for x seconds (or forever until a tooltip("") is called) while also continuing on with the script?

Posted (edited)

  On 2/23/2011 at 3:01 AM, 'kor said:

Every code example I can find with tooltip being used has a sleep right after it.

How does one display a tool tip for x seconds (or forever until a tooltip("") is called) while also continuing on with the script?

Under help for Hotkeyset:

Global $Paused
HotKeySet("{PAUSE}", "TogglePause");<< To switch Tooltip on or off
While 1
    Sleep(33)
WEnd
Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(11)
        ToolTip("Paused Script", MouseGetPos(0) + 25, MouseGetPos(1) + 10, "-----Title-----", 1)
;Can do some other stuff for example here!
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause
Edited by JoHanatCent
  • Moderators
Posted

kor,

Tooltips stay active until you close them and the script continues while they are shown as this demonstrates: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton1 = GUICtrlCreateButton("Show", 10, 10, 80, 30)
$hButton2 = GUICtrlCreateButton("Hide", 10, 50, 80, 30)

$hLabel = GUICtrlCreateLabel("0", 10, 100, 80, 40)
GUICtrlSetFont(-1, 18)

GUISetState()

$iBegin = TimerInit()
$iCount = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton1
            $aPos = WinGetPos($hGUI)
            Tooltip("Testing!", $aPos[0] + 100, $aPos[1] + 100)
        Case $hButton2
            ToolTip("")
    EndSwitch

    If TimerDiff($iBegin) > 1000 Then
        $iCount += 1
        GUICtrlSetData($hLabel, $iCount)
        $iBegin = TimerInit()
    EndIf

WEnd

All clear? :)

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:

  Reveal hidden contents

 

Posted

Here is an OnEvent mode, cross between JoHanatCent and Melba23 examples, script.

HotKeySet("{PAUSE}", "TogglePause");<< To switch Tooltip on or off

Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled

Global $Paused = True
Local $hGUI, $iLabel, $iBegin, $iCount

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent(-3, "Terminate")

$iLabel = GUICtrlCreateLabel("0", 10, 50, 280, 80)
GUICtrlSetFont(-1, 36, 800)
$iButton1 = GUICtrlCreateButton("Toggle ToolTip", 10, 10, 80, 30)
GUICtrlSetOnEvent($iButton1, "TogglePause")

GUISetState()

$iBegin = TimerInit()
$iCount = 0

While 1
    Sleep(10) ; Sleep within loop to reduce CPU usage.
    If $Paused = True Then ToolTip("Press Paused to toggle Tooltip", _
            MouseGetPos(0) + 25, MouseGetPos(1) + 10, "-----Title-----", 1)

    ;Can do some other stuff for example here!

    If TimerDiff($iBegin) > 1000 Then
        $iCount += 1
        GUICtrlSetData($iLabel, $iCount)
        $iBegin = TimerInit()
    EndIf
WEnd


Func TogglePause()
    $Paused = Not $Paused
    If $Paused = False Then ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

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
  • Recently Browsing   0 members

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