Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

(SOLVED) OnMessage gui tooltips issues


  • Please log in to reply
9 replies to this topic
dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
I have a fairly complicated script with multiple guis. I use OnMessage to display on-hover tooltips for the various controls. What I have now works, but there are a couple of quirks I have not been able to work out. First, if the cursor is over a control and another window appears over the gui the tooltip stays above the new window. This is a minor annoyance but I would like to eliminate it if possible. I have tried adding an empty ToolTip command in strategic places but that does not work. The second issue is a small matter of preference and does not affect the script function. It is just that OnMessage displays the tooltips the instant the cursor touches a control, and I would prefer it if there were a slight delay. I suspect that a ridiculously complicated arrangement of timers and flags could fix both issues, but every time I try to think out the steps my brain hurts. I am hoping someone has some better ideas. Here is the actual OnMessage function:
help(wparam, lparam, msg)

 {

   mousegetpos, , , win, control

   wingettitle, title, ahk_id %win%

   global folder



   if (title = "mittere")

    {

      if (control = "button2")

       {

         description := "Select application"

       }

      else if (control = "button3")

       {

         description := "Select folder"

       }

      else  if (control = "button4")

       {

         description := "Add selection"

       }

      else if (control = "button5")

       {

         description := "Add Mittere to the`nSend To menu"

       }

      else if (control = "button6")

       {

         description := "Open the Send To`nfolder in Explorer"

       }

      else if (control = "button7")

       {

         description := "Done"

       }

    }

   else if instr(title, "options for")

    {

      if (folder = 1)

       {

         if (control = "button2")

          {

            description := "Set name`nto default"

          }

         else if (control = "button3")

          {

            description := "Skip item"

          }

         else if (control = "button4")

          {

            description := "Submit"

          }

       }

      else

       {

         if (control = "button2")

          {

            description := "Select a starting directory"

          }

         else if (control = "button3")

          {

            description := "Set all fields to`ndefault values"

          }

         else if (control = "button4")

          {

            description := "Skip item"

          }

         else if (control = "button5")

          {

            description := "Submit"

          }

       }

    }

   tooltip, %description%

 }

return
Thanks for any help. :?
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Hi, dmg!

I solved the tooltip problem adding Tooltip right after Gui, Show of each new window, don't know why it's not working for you.
As for the delay and time adjustments, this example from the Gui help page worked fine for me:
; Example: Display context-senstive help (via ToolTip) whenever the user moves the mouse over a particular control:

Gui, Add, Edit, vMyEdit
MyEdit_TT := "This is a tooltip for the control whose variable is MyEdit."
Gui, Add, DropDownList, vMyDDL, Red|Green|Blue
MyDDL_TT := "Choose a color from the drop-down list."
Gui, Add, Checkbox, vMyCheck, This control has no tooltip.
Gui, Show
OnMessage(0x200, "WM_MOUSEMOVE")
return

WM_MOUSEMOVE()
{
    static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
    CurrControl := A_GuiControl
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer, DisplayToolTip, 1000
        PrevControl := CurrControl
    }
    return

    DisplayToolTip:
    SetTimer, DisplayToolTip, Off
    ToolTip % %CurrControl%_TT  ; The leading percent sign tell it to use an expression.
    SetTimer, RemoveToolTip, 3000
    return

    RemoveToolTip:
    SetTimer, RemoveToolTip, Off
    ToolTip
    return
}


GuiClose:
ExitApp

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
Greetings Pulover!

I solved the tooltip problem adding Tooltip right after Gui, Show of each new window, don't know why it's not working for you.

Hmmm... Since you got it to work I will keep fiddling with it and see what comes.

As for the delay and time adjustments, this example from the Gui help page worked fine for me:

Yes, it appears to work much better than my current method! I will see if it can be adapted to my more complicated script. Thank you again Pulover. You are a positive oracle of scripting wisdom. :D
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

Thank you again Pulover. You are a positive oracle of scripting wisdom.

:lol:
You made me laugh now, dmg... I don't have such a large experience scripting but I like to help whenever I can.
Count on me when you need! :D

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
I have been examining the tooltip script example you kindly provided and I think I can see how it works, but I do have two questions.

The line CurrControl := A_GuiControl indicates that A_GuiControl contains the var name of the control under the cursor, but I don't see anything in the script to show how it knows which control it is. Normally something like MouseGetPos would be needed, and the A_GuiControl description in the docs is not very helpful.

The line If (CurrControl <> PrevControl and not InStr(CurrControl, " ")) prevents the tooltip from activating more than once while hovering over a single control, but why does it check for spaces?

I think it is a little like feeding stray animals... You answer some of my questions and I keep coming back to ask more. It never ends! :lol:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Let's see if I can fill your hunger today! :lol:

When I started using this example I didn't understand half of it... So this is the first time I actually try. ^^

but I don't see anything in the script to show how it knows which control it is.

A_GuiControl is launched with every mouse movement, so for what I could understand OnMessage thread is launched by the gui and therefore the variable contains the control that launched it. Besides I wouldn't be surprised if MouseGetPos internally used the same 0x200 message.

but why does it check for spaces?

I think this was supposed to check if the control has no associated variable (because variable names does not accept spaces) thus avoiding showing an error message, but it doesn't work for some reason. The documentation says:

If that control lacks an associated variable, A_GuiControl instead contains the first 63 characters of the control's text/caption

So if there's no variable it shows the text, and if the text has a space it should not show the tooltip but I still get an error message... Strange.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010

I think this was supposed to check if the control has no associated variable (because variable names does not accept spaces) thus avoiding showing an error message, but it doesn't work for some reason...So if there's no variable it shows the text, and if the text has a space it should not show the tooltip but I still get an error message... Strange.

OK. That makes sense.

A_GuiControl is launched with every mouse movement, so for what I could understand OnMessage thread is launched by the gui and therefore the variable contains the control that launched it. Besides I wouldn't be surprised if MouseGetPos internally used the same 0x200 message.

That makes sense based on what I can observe the script doing, but that does not seem like what the A_GuiControl documentation says. Hmm... I may ask Lexikos about this behavior at some point.

Thank you again for your kind assistance. 8-)
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

The name of the variable associated with the GUI control that launched the current thread.

That's it. If a message is posted to the control and that message is being monitored, A_GuiControl is set and a new thread is launched to call the function.

Besides I wouldn't be surprised if MouseGetPos internally used the same 0x200 message.

MouseGetPos doesn't use any messages; it calls GetCursorPos. How could it use a message?

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
Thanks for responding Lexikos.

I am still having some trouble wrapping my head around this (it is thick, and does not bend easily).

The name of the variable associated with the GUI control that launched the current thread.

I guess I just don't understand how in a mousemove OnMessage situation it is the control under the cursor that is considered to have launched the thread. I am assuming I just don't have a clue about how the OnMessage system actually works. Isn't it the mouse moving that launched the thread? How does the control under the cursor come into it? :?

Sorry to cause trouble. :(
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

MouseGetPos doesn't use any messages; it calls GetCursorPos . How could it use a message?

I didn't say it did, was just wondering... I didn't stop to think much about it. Thanks for explaining.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!