AutoHotkey Community

It is currently May 27th, 2012, 3:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 6th, 2005, 3:08 pm 
Took this code from a posting in "Wish List"

Code:
Gui, Font, underline
Gui, Add, Text, cBlue gMyLink, www.google.com
Gui, Font, norm

Gui, Font, underline
Gui, Add, Text, cBlue gMyMail, someone@place.com
Gui, Font, norm

Gui, Show
return

MyLink:
Run, www.google.com
return

MyMail:
Run, mailto: someone@place.com
return

Do you see a way to let the mouse cursor change to the "hand" cursor during hovering the URL?
I searched the forum but didn't find a solution. Am I blind? ;)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2005, 4:02 pm 
Searched Google. ;)

Thought about a combination of SetCursor and
Code:
MouseGetPos,,,, ACtrl

When ACtrl holds the name of the correct control the mouse cursor should change to the hand symbol.
Am I completely wrong? I'm not sure 'bout the function and how to eventually implement it via DllCall.

Or is there a way to change mouse cursor within AHK I have overlooked?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2005, 9:27 pm 
Found this thread: http://www.autohotkey.com/forum/viewtopic.php?t=4570

Code:
  NULL=
  IDC_HAND := 32649
  IDC_ARROW := 32512

!0::Gosub, CursorTest
Return


CursorTest:
  ;// Load a cursor. If the 1st arg is NULL, specify one of the Constants above
  ;// as the second arg to load a system cursor
  result1 := DllCall("LoadCursor", "Uint", NULL, "Int", IDC_HAND, "Uint")

  ;// Changes a system cursor.
  result2 := DllCall("SetSystemCursor", "Uint", result1, "Int", IDC_ARROW, "Uint")
Return


Pressing Alt+0 changes arrow mouse cursor to hand cursor. Pressing it again restores arrow cursor. Don't know why.
Is this of any help for solving my problem?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2005, 12:15 pm 
Offline

Joined: February 12th, 2005, 8:31 pm
Posts: 82
I'm still looking for a solution. :roll: No one here with an idea?

This is how far I came:
Code:
ScriptName = CursorURLTest

NULL=
IDC_HAND := 32649
IDC_ARROW := 32512
GoSub, CreateTestGui
Return

CreateTestGui:
  Gui, Font, underline
  Gui, Add, Text, cBlue gMyLink, www.google.com
  Gui, Font, norm
  Gui, Show, w200 h100, %ScriptName%
 
  SetTimer, ShowCursor, 100
Return

GuiClose:
  ExitApp
Return

MyLink:
Run, www.google.com
Return

ShowCursor:
IfWinNotActive, %ScriptName%
  {
    Return
  }
 
  MouseGetPos,,,, ACtrl
 
  If ACtrl = Static1
    {
      GoSub, CursorURL
      SetTimer, ShowCursor, Off
    }
 
  If ACtrl <> Static1
    {
      Return
    }
Return

CursorURL:
  ;// Load a cursor. If the 1st arg is NULL, specify one of the Constants above
  ;// as the second arg to load a system cursor
  result1 := DllCall("LoadCursor"
                    , "Uint"
                    , NULL
                    , "Int"
                    , IDC_HAND
                    , "Uint")

  ;// Changes a system cursor.
  result2 := DllCall("SetSystemCursor"
                    , "Uint"
                    , result1
                    , "Int"
                    , IDC_ARROW
                    , "Uint")
Return

It works once, but cursor stays to be a hand. Fix it by closing gui, running script again and hover the URL again.

_________________
Cheers
BBCodeWriterToDo-ListCopyPassage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2005, 6:39 pm 
Image Image
I'm still here looking for a solution. Nobody here with a possible solution?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2005, 9:29 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
AGU wrote:
Image Image
I'm still here looking for a solution. Nobody here with a possible solution?


It would be useful if you provide some additional information.

* Will this behavior only be active for a Text control?
* Will the URL be the only text within that control?
* Will the URL text always have a specific color?
* Would you like any other behaviors or characteristics?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2005, 10:50 pm 
Hello shimanov:),

concerning your questions / additional informations:

Quote:
* Will this behavior only be active for a Text control?
As Chris proposed it in this thread you can accomplish a hyperlink by using a text control. That's why I used a text control. Don't know if it must be a text control, but I would say a text control is perfect for this purpose.
Quote:
* Will the URL be the only text within that control?
I would say yes. All I want to accomplish is an URL with the known mouse cursor behaviour.
Quote:
* Will the URL text always have a specific color?
Hmm, good question. I would say, it must have a different color than normal text to indicate it's a hyperlink. As blue is the IE standard color for (unvisited) hyperlinks I took this one. But I can't tell you if it has to be blue at all. If you think a specific color is the best, I would vote for blue. Otherwise maybe configurable?
Quote:
* Would you like any other behaviors or characteristics?
Hmm, maybe the text gets underlined during hovering it? Just as you would expect from a hyperlink. If this is to complicated all I want is the mouse cursor to change to the "hand" cursor during hovering the URL (text control, or whatever ;))

Thanks for any help.
Cheers AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2005, 4:57 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
The code below seems to fulfill your request. If it works for you, I will help you complete it.

Known limitations:

    * Underline is not removed if the mouse "jumps" (e.g., via MouseMove)

    To observe this limitation, press F10 while hovering over the underlined text. Under normal use, this limitation should not be an issue. If it is, there is a solution which requires addition of a timer.

Usage:

    * Hover behavior requires (for convenience) an associated variable with a "URL_" prefix.
    * Move the cursor and observe the ensuing effects. Have fun.


Code:
Gui, Add, Picture,, c:\windows\winnt.bmp

Gui, Add, Text,, www.test.com

Gui, Add, Text, cBlue gMyLink vURL_MyLink, www.google.com
Gui, Font, norm

Gui, Add, Text, cGreen gMyMail, someone@place.com
Gui, Font, norm

Gui, Add, Text, cRed, www.hello.com

Gui, Show, x50 y50

Process, Exist
pid_this := ErrorLevel

WinGet, hw_gui, ID, ahk_class AutoHotkeyGUI ahk_pid %pid_this%

WM_SETCURSOR = 0x20
OnMessage( WM_SETCURSOR, "HandleMessage" )

WM_MOUSEMOVE = 0x200
OnMessage( WM_MOUSEMOVE, "HandleMessage" )
return

F10::
   CoordMode, Mouse, Screen
   MouseMove, 5, 5, 0
return

F11::
   Reload
return

F12::
ExitApp

HandleMessage( p_w, p_l, p_m, p_hw )
{
   global   WM_SETCURSOR, WM_MOUSEMOVE
   static   URL_hover, h_old_cursor
   
   if ( p_m = WM_SETCURSOR )
   {
      return, true
   }
   else if ( p_m = WM_MOUSEMOVE )
   {
      if ( A_GuiControl = "URL_MyLink" )
      {
         if URL_hover=
         {
            Gui, Font, cBlue underline
            GuiControl, Font, URL_MyLink
            
            h_cursor_hand := DllCall( "LoadCursor", "uint", 0, "uint", 32649 )
            
            h_old_cursor := DllCall( "SetCursor", "uint", h_cursor_hand )
            
            URL_hover := true
         }
      }
      else
      {
         if ( URL_hover )
         {
            Gui, Font, norm cBlue
            GuiControl, Font, URL_MyLink
            
            DllCall( "SetCursor", "uint", h_old_cursor )
            
            URL_hover=
         }
      }
   }
}

GuiClose:
ExitApp

MyLink:
   MsgBox, MyLink
return

MyMail:
   MsgBox, MyMail
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2005, 3:11 pm 
Hello shimanov,

works great. But I found a strange behaviour. When the GUI is created and the mouse cursor is not within the new window at startup, the mouse cursor is an hourglass (IDC_WAIT?) when entering the GUI.
Another thing I recognized. Sometimes the mousecursor changes back to the arrow cursor when moving over the URL text control. But that's no problem.

The limitation (mouse jumps) is negligible I think.

I made some slight modifications to your script for my personal use. :D
(comments, indentation, ...)

Code:
  Gui, Add, Picture,, %A_WinDir%\winnt.bmp
  Gui, Add, Text,, www.test.com
  Gui, Add, Text, cBlue gMyLink vURL_MyLink, www.google.com
  Gui, Font, norm
  Gui, Add, Text, cGreen gMyMail, someone@place.com
  Gui, Font, norm
  Gui, Add, Text, cRed, www.hello.com
  Gui, Show,, URL Workaround
 
  ; 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 ##########################################################
;###############################################################################
MyLink:
   MsgBox, MyLink
return

MyMail:
   MsgBox, MyMail
return
;###############################################################################
;######## End Of GUI glabels ###################################################
;###############################################################################


;###############################################################################
;######## Hotkeys ###############################################################
;###############################################################################
F10::
  CoordMode, Mouse, Screen
  MouseMove, 5, 5, 0
Return

F11::
  Reload
Return

F12::
  ExitApp
;###############################################################################
;######## End of Hotkeys ######################################################
;###############################################################################


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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2005, 9:23 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
AGU wrote:
works great.


Nearly so.

AGU wrote:
When the GUI is created and the mouse cursor is not within the new window at startup, the mouse cursor is an hourglass (IDC_WAIT?) when entering the GUI.
...
Another thing I recognized. Sometimes the mousecursor changes back to the arrow cursor when moving over the URL text control.
...
The limitation (mouse jumps) is negligible I think.


This modified HandleMessage should overcome all the issues and limitations mentioned:

Code:
HandleMessage( p_w, p_l, p_m, p_hw )
{
   global   WM_SETCURSOR, WM_MOUSEMOVE
   static   URL_hover, h_cursor_hand, h_old_cursor
   
   if ( p_m = WM_SETCURSOR )
   {
      if ( URL_hover)
         return, true
   }
   else if ( p_m = WM_MOUSEMOVE )
   {
      if ( A_GuiControl = "URL_MyLink" )
      {
         if URL_hover=
         {
            Gui, Font, cBlue underline
            GuiControl, Font, URL_MyLink
            
            h_cursor_hand := DllCall( "LoadCursor", "uint", 0, "uint", 32649 )
            
            URL_hover := true
         }
         
         h_old_cursor := DllCall( "SetCursor", "uint", h_cursor_hand )
      }
      else
      {
         if ( URL_hover )
         {
            Gui, Font, norm cBlue
            GuiControl, Font, URL_MyLink
            
            DllCall( "SetCursor", "uint", h_old_cursor )
            
            URL_hover=
         }
      }
   }
}


AGU wrote:
I made some slight modifications to your script for my personal use. :D
(comments, indentation, ...)


Well, it seems you understand the code. I am sure you will be able to adjust it to suit your needs.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2005, 2:02 am 
Works perfect now. Thanks a lot for your help with this problem.
But also a big "thank you" for your work in this forum. Your code examples and solutions, tips, ... are a big benefit to this community. :D

Wanted to say this quite some times now.

Quote:
Well, it seems you understand the code.
I would say "nearly". One thing I don't understand are these four parameters of "HandleMessage"
Where do they come from. I just see p_m is used within the function. I assume it means p = parameter m = message. But what about the other ones (p_w, p_l and p_hw)? What is done with these or where have they been passed to "HandleMessage?
Is this complicated windows inner life? ;)

Nevertheless your code and many of your similar examples made me understand that Message thing a little bit better. Thx for this too.

Cheers
AGU a.k.a AGermanUser


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2005, 4:14 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Anonymous wrote:
Works perfect now. Thanks a lot for your help with this problem.
But also a big "thank you" for your work in this forum. Your code examples and solutions, tips, ... are a big benefit to this community. :D

Wanted to say this quite some times now.


Another happy customer... I am glad I was able to help.

Anonymous wrote:
One thing I don't understand are these four parameters of "HandleMessage"


Start by reviewing OnMessage and SendMessage (which is complementary) in the help file..

Anonymous wrote:
Is this complicated windows inner life? ;)


Absolutely. But only because you're unfamiliar with it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2007, 6:08 am 
How about multiple hyperlinks in a GUI? I am creating an autorun app for a CD-ROM. Is it possible to modify the function so that it can be reused without modifying the code?

Also as I place the hyperlinks over an image, the hover effect works but when it hovers it has a black border around the hover text (The hover color is red).

Code:
#NoTrayIcon
#NoEnv
#SingleInstance force

BackColor = 000000
TextColor = 0000FF
HoverColor = FF0000

FontSize = 18
isBold = Bold
FontFace = Tahoma

WindowTitle = Window Title
CmdCount = 8

Link1 = File 1
Cmd1 = 001.avi
Link2 = File 2
Cmd2 = 002.avi
Link3 =
Cmd3 =
Link4 =
Cmd4 =
Link5 =
Cmd5 =
Link6 =
Cmd6 =
Link7 = Install Video Decoder
Cmd7 = ffdshow.exe

Link8 = Exit

OnExit, GuiClose

Gui, Margin, 0, 0
Gui, Color, %BackColor%, %BackColor%
Gui, Font, s%FontSize% %isBold% c%TextColor% BackgroundTrans, %FontFace%
Gui, Add, Pic, w550 h60 guiMove, title.bmp
Gui, Add, Pic, w550 h340, bg.bmp
;Gui, -MaximizeBox
Gui, -Caption
Gosub Labelinit
Gui, Show,, %WindowTitle%

Gosub HoverInit

return

cmmd1:
if %Cmd1%
Run %Cmd1%
return
cmmd2:
if %Cmd2%
Run %Cmd2%
return
cmmd3:
if %Cmd3%
Run %Cmd3%
return
cmmd4:
if %Cmd4%
Run %Cmd4%
return
cmmd5:
if %Cmd5%
Run %Cmd5%
return
cmmd6:
if %Cmd6%
Run %Cmd6%
return
cmmd7:
if %Cmd7%
Run %Cmd7%
return
cmmd8:
ExitApp
return

Labelinit:
Loop %CmdCount%
{
LabelText := Link%A_Index%
LabelTop := 55 + A_Index * 35
if LabelText <>
Gui, Add, Text, x20 y%LabelTop% vLink%A_Index% gcmmd%A_Index% BackgroundTrans, %LabelText%
}
return

GuiClose:
ExitApp

uiMove:
PostMessage, 0xA1, 2,,, A
return

HoverInit:
  ; 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

;######## Function #############################################################
HandleMessage(p_w, p_l, p_m, p_hw)
  {
    global   WM_SETCURSOR, WM_MOUSEMOVE, TextColor, HoverColor, CmdCount
    static   URL_hover, h_cursor_hand, h_old_cursor, PrevLinkNum
   
    If (p_m = WM_SETCURSOR)
      {
        If URL_hover
          Return, true
      }
    Else If (p_m = WM_MOUSEMOVE)
      {
        ; Mouse cursor hovers URL text control
        If RegExMatch(A_GuiControl, "Link")
          {
            StringRight, LinkNum, A_GuiControl, 1

            If URL_hover=
              {
                Gui, Font, c%HoverColor% %isBold%
                GuiControl, Font, Link%LinkNum%
                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, c%TextColor% %isBold% BackgroundTrans
                Loop %CmdCount%
                {
                GuiControl, Font, Link%A_Index%
                }
                DllCall("SetCursor", "uint", h_old_cursor)
               
                URL_hover=
              }
          }
      }
  }
;######## End Of Functions #####################################################


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2007, 6:55 am 
I come up with a method to solve the problem of broken text after hover:

Code:
;hide the text
                GuiControl, Hide, Link%LinkNum%
;change the text color
                Gui, Font, c%HoverColor% %isBold%
;apply the format to the text
                GuiControl, Font, Link%LinkNum%
;show the text control again (so it will force it to redraw the control) and it is so quick that the hide-show sequence cannot be noticed :)
                GuiControl, Show, Link%LinkNum%



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2007, 3:11 am 
Offline

Joined: November 3rd, 2006, 11:45 pm
Posts: 61
Location: Miami
This post is great.

As froz mentioned "How about multiple hyperlinks in a GUI?"

I was wondering how I would go about doing that?

In my case, I am working on a simple GUI, with 4 links. The links rather than take you to a web site actualy launch 4 different programs. Using the code mentioned above I can have one of the lines become underlined and the cursor to change to the hand when you hover over it, but I cant figure out for the life of me how to get the other 3 to do the same.

Any Suggestions?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon, Yahoo [Bot] 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