Jump to content

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

Changing the mouse cursor


  • Please log in to reply
17 replies to this topic
skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004

:) Here's some code to change the mouse cursor. I've put it into an about box where it canges the cursor to a hand over links.

Hand.gif

Skrommel




ABOUT:
Gui,Destroy
Gui,Add,Text,y-5,`t
Gui,Add,Picture,Icon100,%SystemRoot%\system32\SHELL32.dll
Gui,Font,Bold
Gui,Add,Text,x+10 yp+10,Hand v1.0
Gui,Font
Gui,Add,Text,xm,Changes the cursor to a hand over links.
Gui,Add,Text,y+0,`t
Gui,Add,Picture,Icon47,%SystemRoot%\system32\SHELL32.dll
Gui,Font,Bold
Gui,Add,Text,x+10 yp+10,1 Hour Software by Skrommel
Gui,Font
Gui,Add,Text,xm,For more tools and information, please stop by at
Gui,Font,CBlue Underline
Gui,Add,Text,xm GWWW,http://www.donationcoders.com/skrommel
Gui,Font
Gui,Add,Text,y+0,`t
Gui,Add,Picture,Icon25,%SystemRoot%\system32\SHELL32.dll
Gui,Font,Bold
Gui,Add,Text,x+10 yp+10,AutoHotkey
Gui,Font
Gui,Add,Text,xm,This program is made using AutoHotkey
Gui,Font,CBlue Underline
Gui,Add,Text,xm GAUTOHOTKEY,http://www.autohotkey.com
Gui,Font
Gui,Add,Text,y+0,`t
Gui,Add,Button,GABOUTOK Default w75,&OK
Gui,Show,,%applicationname% About

;Load the cursor and start the "hook"
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return

AUTOHOTKEY:
Run,http://www.autohotkey.com,,UseErrorLevel
Return

WWW:
Run,http://www.donationcoders.com/skrommel,,UseErrorLevel
Return

ABOUTOK:
Gui,Destroy
;Disable the "hook" and destroy the cursor
OnMessage(0x200,"")
DllCall("DestroyCursor","Uint",hCurs)
Return

GuiClose:
ExitApp

;The "hook"
WM_MOUSEMOVE(wParam,lParam)
{
Global hCurs
MouseGetPos,,,,ctrl
;Only change over certain controls, use Windows Spy to find them.
If ctrl in Static9,Static14
DllCall("SetCursor","UInt",hCurs)
Return
}


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Nice script and presentation; thanks for sharing it.

Control over cursor shape is one of those features that's been planned for a long time. It's still a high priority, so hopefully it will get done soon.

Jub Jub
  • Members
  • 1 posts
  • Last active: Apr 29 2006 02:17 PM
  • Joined: 29 Apr 2006
umm, im sorta new to forums. I want to change the mouse cursor for my forum using phpbb2 i think its 2. But anyways, I dont no where to do it and i dont know how. sry for the typing, but im in a hurry

HurryHarry
  • Guests
  • Last active:
  • Joined: --
@ Jub Jub
I guess you request help regarding a phpBB configuration issue. Unfortunately you're at the wrong place, as this is the forum of AHK (Autohotkey) - btw. a nice piece of software. :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear skrommel, :)

I tried this just now.. and it is NICE!!

Thanks for sharing :D

I am trying to do something similar and need a small clarification:

Should not Line 5 in the following subroutine

ABOUTOK:
Gui,Destroy
;Disable the "hook" and destroy the cursor
OnMessage(0x200,"")
DllCall("DestroyCursor","Uint",hCur)
Return


read as

DllCall("DestroyCursor","Uint",hCurs)


Or Am I missing something?

Regards, :)
kWo4Lk1.png

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:O Oh no, now I have to correct all of my programs!

Thanks for noticing!

Skrommel

Whitespliff
  • Members
  • 33 posts
  • Last active: Mar 30 2008 08:43 PM
  • Joined: 09 Feb 2006
Is it possible to have it work in certain GUI's?

I have a 'About' GUI where a gLabel activates a target (is +owner -SysMenu).
When the 'Update' GUI is open the hand appears also although there is no gLabel (there both static1).

Is there a way to let the hand cursor only work in the About GUI?

Tnx
In a world without walls and fences, who needs Windows and Gates?

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
Try changing the following function as follows:
(NOT TESTED) Works in my head though :roll:

WM_MOUSEMOVE(wParam,lParam) 
{ 
  Global hCurs 
  MouseGetPos,,,,ctrl 
  ;Only change over certain controls, use Windows Spy to find them. 
  If ctrl in Static9,Static14 
    DllCall("SetCursor","UInt",hCurs) 
  Return 
}

WM_MOUSEMOVE(wParam,lParam) 
{ 
  GuiTitleToChangeCursorIn:="The exact title shown in the TitleBar" ; edit the text in quotes
  IfWinActive, %GuiTitleToChangeCursorIn% ; only do the following if the correct window is active
    {
  Global hCurs 
  MouseGetPos,,,,ctrl 
  ;Only change over certain controls, use Windows Spy to find them. 
 If ctrl in Static9,Static14 ; you will have to change this to your control id's
    DllCall("SetCursor","UInt",hCurs) 
   }
  Return 
}


Whitespliff
  • Members
  • 33 posts
  • Last active: Mar 30 2008 08:43 PM
  • Joined: 09 Feb 2006
Yep, works perfectly... tnx a lot!
In a world without walls and fences, who needs Windows and Gates?

iason
  • Members
  • 135 posts
  • Last active: Dec 14 2010 04:42 PM
  • Joined: 01 Nov 2005

hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND


Can someone suggest some sort of tutorial about the icons inside that file?
help to be helped

freakkk
  • Members
  • 182 posts
  • Last active: Dec 16 2014 06:23 PM
  • Joined: 29 Jul 2005
I took the 'Display context-senstive help' example in help file.. & mixed it with your example above. It makes it easier for setting the tooltip & custom mouse cursor for specific controls. It also allows you to use a .cur or .ani file not included in user32.dll.
Gui, Add, ListBox, x16 y17 w420 h120  vGui1MyListBox, MyListBox
Gui1MyListBox_Tooltip = Gui1MyListBox hover tip..
Gui1MyListBox_MouseCursor = 32649

Gui, Add, Edit, x16 y137 w420 h90  vGui1MyEdit, MyEdit
Gui1MyEdit_Tooltip = Gui1MyEdit hover tip..
Gui1MyEdit_MouseCursor = 32648

Gui, Add, Button, x286 y237 w90 h20  vGui1MyButton, MyButton
Gui1MyButton_Tooltip = Gui1MyButton hover tip..
Gui1MyButton_MouseCursor = %A_ScriptDir%\grab.cur   ; if not found.. it doesn't do anything..

Gui, Show, w453 h281, Example..
OnMessage(0x200, "GuiHoverControl") ; Start tooltip/mouse cursor routine..
Return
;-----------------
GuiEscape:
GuiClose:
ExitApp

; ///////////////////// Function ///////////////////////
GuiHoverControl()
{
    static CurrControl, PrevControl, _Tooltip, hCurs
    CurrControl := A_GuiControl
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer, GuiDisplayToolTip, 1000
        PrevControl := CurrControl
        DllCall("DestroyCursor","Uint",hCurs)
        hCurs =
    }
    If (%CurrControl%_MouseCursor)
    {
        If ((SubStr(%CurrControl%_MouseCursor, -3, 4)) = ".cur" or (SubStr(%CurrControl%_MouseCursor, -3, 4)) = ".ani")
        {
          If hCurs =
          {
            IfExist, % %CurrControl%_MouseCursor
              hCurs:=DllCall("LoadCursorFromFile","Str",%CurrControl%_MouseCursor)
          }
        }
        Else
        {
          If hCurs =
            hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",%CurrControl%_MouseCursor,"UInt")
        }
        If hCurs <>
         DllCall("SetCursor","UInt",hCurs)
    }
    return

    GuiDisplayToolTip:
    SetTimer, GuiDisplayToolTip, Off
    ToolTip % %CurrControl%_Tooltip
    SetTimer, GuiRemoveToolTip, 3000
    return

    GuiRemoveToolTip:
    SetTimer, GuiRemoveToolTip, Off
    ToolTip
    return
}
Here's another example that shows a bunch of icons in user32.dll..
(make sure you include GuiHoverControl() somewhere on here..)
Column1Buttons =
(
32642   NW to SE - Small
32643   NE to SW - Small
32644   WE - Small
32645   NS - Small
32646   NSEW - Small
32648   IDC_NO  (Slashed circle)
32649   IDC_HAND  (Icon Hand)
32650   IDC_APPSTARTING
32651   IDC_HELP
32652   NS - Big
)

Column2Buttons =
(
32653   WE - Big
32654   NSEW - Big
32655   N - Big
32656   S - Big
32657   W - Big
32658   E - Big
32659   NW - Big
32660   NE - Big
32661   SW - Big
32662   SE - Big
)

y=0
Loop, Parse, Column1Buttons, `n
{
  Gui, Add, Button, x5 y%y% w220 h25 vGui1Button%A_Index% gGui1Button, %A_LoopField%
  Gui1Button%A_Index%_MouseCursor := SubStr(A_LoopField, "1", 5)
  y+=25
}
y=0
Loop, Parse, Column2Buttons, `n
{
  BtnNum := A_Index+10
  Gui, Add, Button, x226 y%y% w220 h25 vGui1Button%BtnNum% gGui1Button, %A_LoopField%
  Gui1Button%BtnNum%_MouseCursor := SubStr(A_LoopField, "1", 5)
  y+=25
}

Gui, Show, w450 ,--Mouse Cursors In user32.dll--
OnMessage(0x200, "GuiHoverControl") ; Start tooltip/mouse cursor routine..
Return
;-----------------
Gui1Button:
GuiControlGet, tmp1,, % A_GuiControl
clipboard := SubStr(tmp1, 1, 5)
tmp1 =
MsgBox, ,--Mouse Cursors In user32.dll--,'%clipboard%' has been copied to the clipboard.., 4
return
;-----------------
GuiEscape:
GuiClose:
ExitApp


  • Guests
  • Last active:
  • Joined: --
how would i change the function so that i could change the curosor with a simple function call? this would help with setting hotkeys to change cursor (like if i am holding the mouse button in.......)

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007
I like the hand over links. But, I wish to hide cursor when mouse not moved for 7 seconds, then reappear on move.

I could write my own park on 2x3 spot then resume on move, but why reinvent the wheele.

Any one did this?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
It would be much simpler if you save the mouse position, and move it to the lower right corner of the screen, for hiding.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

I like the hand over links. But, I wish to hide cursor when mouse not moved for 7 seconds, then reappear on move.

I could write my own park on 2x3 spot then resume on move, but why reinvent the wheele.

Any one did this?

This might come in handy (although requires an additional .exe file ATM). There are likely a few other methods posted on the forum as this has been asked many times. Maybe try a search if you haven't already ;) .