AutoHotkey Community

It is currently May 27th, 2012, 5:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Gui & Hyperlink
PostPosted: November 10th, 2005, 4:22 pm 
Offline

Joined: February 12th, 2005, 8:31 pm
Posts: 82
Thx to shimanov there is a workaround for displaying URLs in a gui.
I thought it's better to post here again so that it doesn't get lost in the "Ask for Help" section.

Important point is, the associated variable of the control must start with URL in order to work.

Code:
  Gui, Margin, 5, 5
  Gui, Add, Text, xm ym, Multiple URLs in one GUI
  Gui, Add, Text, xp+8 yp+25 cBlue gLink1 vURL_Link1, www.autohotkey.com
  Gui, Add, Text, xp   yp+20 cBlue gLink2 vURL_Link2, de.autohotkey.com
  Gui, Add, Text, xp   yp+20 cBlue gLink3 vURL_Link3, www.google.com
  Gui, Add, Text, xp   yp+20 cBlue gLink4 vURL_Link4, www.msdn.com
  Gui, Font, norm
  Gui, Show,, URL
 
  ; Retrieve scripts PID
  Process, Exist
  pid_this := ErrorLevel
 
  ; Retrieve unique ID number (HWND/handle)
  WinGet, hw_gui, ID, ahk_class AutoHotkeyGUI ahk_pid %pid_this%
 
  ; Call "HandleMessage" when script receives WM_SETCURSOR message
  WM_SETCURSOR = 0x20
  OnMessage(WM_SETCURSOR, "HandleMessage")
 
  ; Call "HandleMessage" when script receives WM_MOUSEMOVE message
  WM_MOUSEMOVE = 0x200
  OnMessage(WM_MOUSEMOVE, "HandleMessage")
Return

GuiClose:
  ExitApp
;######## End of GUI ###########################################################


;######## GUI glabels ##########################################################
Link1:
  Run, http://www.autohotkey.com/forum
Return

Link2:
  Run, http://de.autohotkey.com
Return

Link3:
  Run, http://www.google.com
Return

Link4:
  Run, http://www.msdn.com
Return
;######## End Of GUI glabels ###################################################


;######## Function #############################################################
HandleMessage(p_w, p_l, p_m, p_hw)
  {
    global   WM_SETCURSOR, WM_MOUSEMOVE,
    static   URL_hover, h_cursor_hand, h_old_cursor, CtrlIsURL, LastCtrl
   
    If (p_m = WM_SETCURSOR)
      {
        If URL_hover
          Return, true
      }
    Else If (p_m = WM_MOUSEMOVE)
      {
        ; Mouse cursor hovers URL text control
        StringLeft, CtrlIsURL, A_GuiControl, 3
        If (CtrlIsURL = "URL")
          {
            If URL_hover=
              {
                Gui, Font, cBlue underline
                GuiControl, Font, %A_GuiControl%
                LastCtrl = %A_GuiControl%
               
                h_cursor_hand := DllCall("LoadCursor", "uint", 0, "uint", 32649)
               
                URL_hover := true
              }                 
              h_old_cursor := DllCall("SetCursor", "uint", h_cursor_hand)
          }
        ; Mouse cursor doesn't hover URL text control
        Else
          {
            If URL_hover
              {
                Gui, Font, norm cBlue
                GuiControl, Font, %LastCtrl%
               
                DllCall("SetCursor", "uint", h_old_cursor)
               
                URL_hover=
              }
          }
      }
  }
;######## End Of Functions #####################################################


26.02.2007
+ Added support for more than one URL.

_________________
Cheers
BBCodeWriterToDo-ListCopyPassage


Last edited by AGermanUser on February 26th, 2007, 2:40 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 5:20 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
NICE! Do you know, why 0x2A1 = WM_MOUSEHOVER does not work?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 5:48 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Laszlo wrote:
NICE! Do you know, why 0x2A1 = WM_MOUSEHOVER does not work?


It doesn't offer any advantages over monitoring WM_MOUSEMOVE. It would also needlessly complicate the program.

MSDN wrote:
The WM_MOUSEHOVER message is posted to a window when the cursor hovers over the client area of the window for the period of time specified in a prior call to TrackMouseEvent.
...
Hover tracking stops when WM_MOUSEHOVER is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.


Most important. It does not implement the desired behavior of changing the cursor and underlining the text while the cursor remains within the context of the Text control (i.e., hover).

I would say the name WM_MOUSEHOVER is somewhat of a misnomer, since the behavior it implements is more and less than its name implies. It should be a specialized WM_MOUSEMOVE message, that acts as a filter given a specified context.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 8:40 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
You are my hero!
Image (means Thanks)

I have a program now where I want to add a link into the about-box and I didn't know how to do :)

Thx,
Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 9:46 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Thalon wrote:
You are my hero!
Image (means Thanks)

Thx,
Thalon


I am assuming you are referring to me, since you wouldn't otherwise need to translate for AGermanUser.

Quote:
I have a program now where I want to add a link into the about-box and I didn't know how to do :)


Can you explain what you don't know or where there is a problem? You should be able to use the code, as is, with some adjustments for your particular program.

You could also post the relevant code in the "Ask for Help" forum.

Oh, and one more thing. I am watching you too.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 11:43 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
Yes, I referred to you :)

I did not know, but you solved my problem with this piece of code 8)

It showed me also the advantage of the OnMessage-function, where I did never had a real look at. I will study it now with your example-code and maybe I can post a great script sometime in future... (but my normal programms are too special for sharing them (like my new gameserver-manager for the game "Sacred")...)

Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 6:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
How did you translate the neudeutsch sentence "No, I am a meat popsicle" to "Hi! How do you do"? :lol:
(I have not noticed that the last line on the sign constantly changes. Cool! How do you do that?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2005, 10:58 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Laszlo wrote:
How did you translate the neudeutsch sentence "No, I am a meat popsicle" to "Hi! How do you do"? :lol:
(I have not noticed that the last line on the sign constantly changes. Cool! How do you do that?)


I don't. But they do.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2007, 2:11 am 
Offline

Joined: February 12th, 2005, 8:31 pm
Posts: 82
As 'MiamiGuy' asked for a way to format more than one URL in a GUI, I spent some time with the problem and this is the solution I came up with.
This script supports more than one URL to be formatted underlined when hovered.

Important point is, the associated variable of the control must start with URL in order to work.

Code:
  Gui, Margin, 5, 5
  Gui, Add, Text, xm ym, Multiple URLs in one GUI
  Gui, Add, Text, xp+8 yp+25 cBlue gLink1 vURL_Link1, www.autohotkey.com
  Gui, Add, Text, xp   yp+20 cBlue gLink2 vURL_Link2, de.autohotkey.com
  Gui, Add, Text, xp   yp+20 cBlue gLink3 vURL_Link3, www.google.com
  Gui, Add, Text, xp   yp+20 cBlue gLink4 vURL_Link4, www.msdn.com
  Gui, Font, norm
  Gui, Show,, URL
 
  ; Retrieve scripts PID
  Process, Exist
  pid_this := ErrorLevel
 
  ; Retrieve unique ID number (HWND/handle)
  WinGet, hw_gui, ID, ahk_class AutoHotkeyGUI ahk_pid %pid_this%
 
  ; Call "HandleMessage" when script receives WM_SETCURSOR message
  WM_SETCURSOR = 0x20
  OnMessage(WM_SETCURSOR, "HandleMessage")
 
  ; Call "HandleMessage" when script receives WM_MOUSEMOVE message
  WM_MOUSEMOVE = 0x200
  OnMessage(WM_MOUSEMOVE, "HandleMessage")
Return

GuiClose:
  ExitApp
;######## End of GUI ###########################################################


;######## GUI glabels ##########################################################
Link1:
  Run, http://www.autohotkey.com/forum
Return

Link2:
  Run, http://de.autohotkey.com
Return

Link3:
  Run, http://www.google.com
Return

Link4:
  Run, http://www.msdn.com
Return
;######## End Of GUI glabels ###################################################


;######## Function #############################################################
HandleMessage(p_w, p_l, p_m, p_hw)
  {
    global   WM_SETCURSOR, WM_MOUSEMOVE,
    static   URL_hover, h_cursor_hand, h_old_cursor, CtrlIsURL, LastCtrl
   
    If (p_m = WM_SETCURSOR)
      {
        If URL_hover
          Return, true
      }
    Else If (p_m = WM_MOUSEMOVE)
      {
        ; Mouse cursor hovers URL text control
        StringLeft, CtrlIsURL, A_GuiControl, 3
        If (CtrlIsURL = "URL")
          {
            If URL_hover=
              {
                Gui, Font, cBlue underline
                GuiControl, Font, %A_GuiControl%
                LastCtrl = %A_GuiControl%
               
                h_cursor_hand := DllCall("LoadCursor", "uint", 0, "uint", 32649)
               
                URL_hover := true
              }                 
              h_old_cursor := DllCall("SetCursor", "uint", h_cursor_hand)
          }
        ; Mouse cursor doesn't hover URL text control
        Else
          {
            If URL_hover
              {
                Gui, Font, norm cBlue
                GuiControl, Font, %LastCtrl%
               
                DllCall("SetCursor", "uint", h_old_cursor)
               
                URL_hover=
              }
          }
      }
  }
;######## End Of Functions #####################################################


Please check if you find a better solution and if yes, post it. :D

_________________
Cheers
BBCodeWriterToDo-ListCopyPassage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2007, 4:49 am 
Offline

Joined: November 3rd, 2006, 11:45 pm
Posts: 61
Location: Miami
Holly Molly,
(I can actually hear a chorus of HALLELUJA) oh boy do I need help.

You dont know how much I've experimented with that, to no avail.
THANNNNK YOUUUUUU! Thats exactly what I was looking for.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2007, 9:57 pm 
Offline

Joined: February 17th, 2006, 2:29 pm
Posts: 37
Very good.
Well done.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2007, 7:13 am 
Offline

Joined: November 3rd, 2006, 11:45 pm
Posts: 61
Location: Miami
AGU, I have a question...
I'm using the code you posted with the function Handlemessage.
Basically, what I'm doing is a Gui, with 4 links. Thanks to you, now they become underlined when the mouse hovers. :D What those links do is open other gui windows in the same program. (Kind of reminiscent to the Control Panels window in Windows XP when you use the classic view.)
Anyway, I also have a button, which I was working on, which is basically a little arrow that when you click it, it minimizes the window. I asked SKA and he gave me an idea of where to start, but its another function, using the same WM_MOUSEMOVE, and I couldn't figure out how to make two different functions work with the same message. I started playing with your function again, and I got it to work, so that when you hover over a certain picture control, (bmp_Picture.bmp for example), I use GuiControl to change it to a lighter pic so it looks highlighted. However, the problem I"m having now is that no matter where I move the mouse on the gui, the picture of the arrow flickers. Is there something I'm doing wrong?
Look at your code and see where I added code for the arrow button, is there something I missed that would keep the image from flikering?

Code:
HandleMessage(p_w, p_l, p_m, p_hw)
  {
    global   WM_SETCURSOR, WM_MOUSEMOVE,
    static   URL_hover, h_cursor_hand, h_old_cursor, CtrlIsURL, LastCtrl, CtrlIsbmp
   
    If (p_m = WM_SETCURSOR)
      {
        If URL_hover
          Return, true
      }
    Else If (p_m = WM_MOUSEMOVE)
      {
;Mouse cursor hovers BMP picture control
        StringLeft, CtrlIsbmp, A_GuiControl, 3
        If (CtrlIsbmp = "bmp")
          {
           GuiControl,, bmp_RBU, RedButtonH.bmp
           LastCtrl = %A_GuiControl%
          }
;Mouse cursor doesn't hover BMP picture control
        Else
          {
            GuiControl,, bmp_RBU, RedButtonU.bmp
          }

;Mouse cursor hovers URL text control
        StringLeft, CtrlIsURL, A_GuiControl, 3
        If (CtrlIsURL = "URL")
          {
            If URL_hover=
              {
                Gui, Font, bold underline
                GuiControl, Font, %A_GuiControl%
                LastCtrl = %A_GuiControl%
               
                h_cursor_hand := DllCall("LoadCursor", "uint", 0, "uint", 32649)
               
                URL_hover := true
              }                 
              h_old_cursor := DllCall("SetCursor", "uint", h_cursor_hand)
          }
; Mouse cursor doesn't hover URL  text control 
      Else
          {

           If URL_hover
              {
                Gui, Font, norm cWhite bold
                GuiControl, Font, %LastCtrl%
               
                DllCall("SetCursor", "uint", h_old_cursor)
               
                URL_hover=
              }

          }

      }
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2007, 10:23 am 
The problem with your current code is, that you're assigning a picture by GuiControl all the time you're moving the mouse. That's what is causing the flickering.

The problem is within this section:
Code:
;Mouse cursor doesn't hover BMP picture control
        Else
          {
            GuiControl,, bmp_RBU, RedButtonU.bmp
          }


As you see, everytime you're moving the mouse, it sends a WM_MOUSEMOVE message. So it's assigning your unhovered button all the time. When you study the URL code of HandleMessage you can see this URL_hover variable. It's there because of this issue.

If you check the code, you'll see that URL_hover will be assigned "true" as long the mouse hovers the URL control. If it doesn't hover the URL anymore, the code jumps to the else block.
Within the else block is it checked if URL_hover is true. If so, it's doing some cleanup work and finally assigns URL_hover= (empty string).
Next MouseMove it doesn't hover the URL control, the check for URL_hover within the Else block fails. In this way, the function doesn't do anything.

So, you have to introduce a BMP_hover variable within your function to do the same thing for your BMP control. As you haven't posted your full code, I played a little bit with it. Therefore it's untested and more of a wild guess.

Code:
HandleMessage(p_w, p_l, p_m, p_hw)
  {
    global   WM_SETCURSOR, WM_MOUSEMOVE,
    static   URL_hover, BMP_hover, h_cursor_hand, h_old_cursor, CtrlType, LastCtrl
   
    If (p_m = WM_SETCURSOR)
      {
        If URL_hover
          Return, true
      }
    Else If (p_m = WM_MOUSEMOVE)
      {
        ;Mouse cursor hovers BMP picture control
        StringLeft, CtrlType, A_GuiControl, 3
        If (CtrlType = "bmp")
          {
            GuiControl,, bmp_RBU, RedButtonH.bmp
                       
            BMP_hover := true
          }
        ;Mouse cursor hovers URL text control
        StringLeft, CtrlType, A_GuiControl, 3
        If (CtrlType = "URL")
          {
            If URL_hover=
              {
                Gui, Font, bold underline
                GuiControl, Font, %A_GuiControl%
                LastCtrl = %A_GuiControl%
               
                h_cursor_hand := DllCall("LoadCursor", "uint", 0, "uint", 32649)
               
                URL_hover := true
              }                 
              h_old_cursor := DllCall("SetCursor", "uint", h_cursor_hand)
          }
        Else If (CtrlType = "bmp")
          {
           GuiControl,, bmp_RBU, RedButtonH.bmp
          }

        ; Mouse cursor doesn't hover URL or BMP control
        Else
            {
              If URL_hover
                {
                  Gui, Font, norm cWhite bold
                  GuiControl, Font, %LastCtrl%
                 
                  DllCall("SetCursor", "uint", h_old_cursor)
                 
                  URL_hover=
                }
              If BMP_Hover
                {
                  GuiControl,, bmp_RBU, RedButtonU.bmp
                 
                  BMP_hover=
                }

            }
      }
  }

________________________
Cheers AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2009, 8:14 pm 
Offline

Joined: February 20th, 2008, 5:08 pm
Posts: 111
Any chance you can make this script to work on laptops?
After installing my touchpad driver I received an error:

Line Text: HandleMessage(p_w, p_l, p_m, p_hw)
Error: Functions cannot contain functions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 2:31 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You probably screwed up some barces or had problems with spaces between function names and their parameters, or If's and their conditions.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, HotkeyStick, JamixZol and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group