Sign in to follow this  
Followers 0
Kip

Custom Cursor

19 posts in this topic

hi

is there a way to set my own cursor for a Gui?

for example: i wanna set My Documents/cursor.gif to the cursor of my GUI (or a single object)

Kip :)

Share this post


Link to post
Share on other sites



Straight from help

#include <GUIConstants.au3>

$IDC = -1
$newIDC = 0

HotkeySet("{Esc}", "Increment")

GUICreate("Press Esc to Increment", 400, 400,0,0,0x04CF0000, 0x00000110)

GUISetState ()

While GUIGetMsg()<> $GUI_EVENT_CLOSE
     If $newIDC <> $IDC Then
         $IDC = $newIDC
         GUISetCursor($IDC)
     EndIf
     ToolTip("GUI Cursor #" & $IDC)
WEnd
Exit

Func Increment()
     $newIDC = $IDC + 1
     If $newIDC > 15 Then $newIDC = 0
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Maybe...

Global Const $OCR_APPSTARTING = 32650
Global Const $OCR_NORMAL = 32512
Global Const $OCR_CROSS = 32515
Global Const $OCR_HAND = 32649
Global Const $OCR_IBEAM = 32513
Global Const $OCR_NO = 32648
Global Const $OCR_SIZEALL = 32646
Global Const $OCR_SIZENESW = 32643
Global Const $OCR_SIZENS = 32645
Global Const $OCR_SIZENWSE = 32642
Global Const $OCR_SIZEWE = 32644
Global Const $OCR_UP = 32516
Global Const $OCR_WAIT = 32514

;~ _SetCursor(@WindowsDir & "\cursors\3dgarro.cur", $OCR_NORMAL)
;~ _SetCursor(@WindowsDir & "\cursors\3dwarro.cur", $OCR_NORMAL)
_SetCursor(@WindowsDir & "\cursors\banana.ani", $OCR_NORMAL)

;==================================================================
; $s_file - file to load cursor from
; $i_cursor - system cursor to change
;==================================================================
Func _SetCursor($s_file, $i_cursor)
   Local $newhcurs, $lResult
   $newhcurs = DllCall("user32.dll", "int", "LoadCursorFromFile", "str", $s_file)
   If Not @error Then
      $lResult = DllCall("user32.dll", "int", "SetSystemCursor", "int", $newhcurs[0], "int", $i_cursor)
      If Not @error Then
         $lResult = DllCall("user32.dll", "int", "DestroyCursor", "int", $newhcurs[0])
      Else
         MsgBox(0, "Error", "Failed SetSystemCursor")
      EndIf
   Else
      MsgBox(0, "Error", "Failed LoadCursorFromFile")
   EndIf
EndFunc  ;==>_SetCursor

... to be helpful

by gafrost

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Also: A .gif file cannot be a proper cursor. It will need to be a .cur or .ani.

Share this post


Link to post
Share on other sites

Maybe...

: Script

... to be helpful

by gafrost

8)

thnx, but thats not for 1 window :)

Also: A .gif file cannot be a proper cursor. It will need to be a .cur or .ani.

lets quote something: 'FOR EXAMPLE: image.gif'

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thnx, but thats not for 1 window :)

lets quote something: 'FOR EXAMPLE: image.gif'

Yes and Saunders clearly stated that it cannot be a .gif image. For that matter, it cannot be a .bmp, .jpg, or .png image either. It must be a .cur or .ani file in order to work as a cursor. That is because the cursor has specific points that are mapped for where the active clicking point is and where transparancies are located. If you want, convert the .gif image to a .cur and set the active clicking point that way. I don't know of any programs that do this off the top of my head. A google search should be adequate to find some programs to do this though.

- The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

please, im not a expert with all those external functions (dll, com)

if it can be done with the Cursor API functions, please tell me wich one?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

ok, I've got this.

but this will set the cursor for both GUIs.

MSDN doesnt say anything about a Gui Handle.

#include <GuiConstants.au3>

$Gui = GuiCreate("Test", 300, 200)

GUISetState()

$Gui2 = GuiCreate("Test", 300, 200,750)

GUISetState()

$Cur = DllCall("user32.dll", "int", "LoadCursorFromFile", "str","pen_m.cur")

if @error Then MsgBox(0,"dd","whoopsie!")

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $GUI_EVENT_CLOSE

Exit

EndSelect

DllCall("user32.dll", "int", "SetCursor", "int", $Cur[0])

WEnd

Edited by kip

Share this post


Link to post
Share on other sites

Using what you provided, I was able to come up with this:

#include <GuiConstants.au3>

$Gui = GuiCreate("Test", 300, 200)
GUISetState()

$Gui2 = GuiCreate("Test", 300, 200,750)
GUISetState()

GUIRegisterMsg($WM_SETCURSOR, 'WM_SETCURSOR')

$Cur = DllCall("user32.dll", "int", "LoadCursorFromFile", "str","C:\windows\cursors\pen_m.cur")
if @error Then MsgBox(0,"dd","whoopsie!")


While 1
    $Msg = GUIGetMsg(1)
    Select
        Case $Msg[0] = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $Gui Then
        DllCall("user32.dll", "int", "SetCursor", "int", $Cur[0])
        Return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Using what you provided, I was able to come up with this:

#include <GuiConstants.au3>

$Gui = GuiCreate("Test", 300, 200)
GUISetState()

$Gui2 = GuiCreate("Test", 300, 200,750)
GUISetState()

GUIRegisterMsg($WM_SETCURSOR, 'WM_SETCURSOR')

$Cur = DllCall("user32.dll", "int", "LoadCursorFromFile", "str","C:\windows\cursors\pen_m.cur")
if @error Then MsgBox(0,"dd","whoopsie!")


While 1
    $Msg = GUIGetMsg(1)
    Select
        Case $Msg[0] = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $Gui Then
        DllCall("user32.dll", "int", "SetCursor", "int", $Cur[0])
        Return 0
    EndIf
EndFunc
Nice one... added to Autoit wrappers

thx

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

$GUI = GUICreate("OSdesign",@DesktopWidth/2,@DesktopHeight/2,-1,-1,$WS_POPUP)
GUISetBkColor(0xeeeeee)
GuiCtrlCreateGraphic(220, 10)
GUICtrlSetGraphic(-1, 0, 0x000000)
GUISetCursor(16,1)
$MOUSE_GRAPHIC = GUICtrlCreateGraphic(0,0,12,12)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_COLOR,0x000000)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,0)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,1,0)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,1)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,2)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,3)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,4)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,5)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,6)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,8)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,0,9)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,1,9)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,2,8)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,3,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,4,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,5,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,6,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,7,7)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,7,6)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,6,5)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,5,4)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,4,3)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,3,2)
GUICtrlSetGraphic($MOUSE_GRAPHIC,$GUI_GR_PIXEL,2,1)
GUISetState(@SW_SHOW)

While 1
    $MousePos = GUIGetCursorInfo($GUI)
    GUICtrlSetPos($MOUSE_GRAPHIC,$MousePos[0],$MousePos[1])
    Sleep(10)
WEnd

or

#include <GUIConstants.au3>

$GUI = GUICreate("OSdesign",@DesktopWidth/2,@DesktopHeight/2,-1,-1,$WS_POPUP)
GUISetBkColor(0xeeeeee)
GuiCtrlCreateGraphic(220, 10)
GUICtrlSetGraphic(-1, 0, 0x000000)
GUISetCursor(16,1)
$MOUSE_GRAPHIC = GUICtrlCreatePic("image.bmp",0,0,100,100)
GUISetState(@SW_SHOW)

While 1
    $MousePos = GUIGetCursorInfo($GUI)
    GUICtrlSetPos($MOUSE_GRAPHIC,$MousePos[0],$MousePos[1])
    Sleep(10)
WEnd

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0