Load Cursor...

BlitzPlus Forums/BlitzPlus Programming/Load Cursor...

MrCredo(Posted 2004) [#1]
how can i load a cursor from file and change mouse pointer?

i tested some api-functions (yes with userlibs) - but i have no luck :-( nothing work. Have someone code?


Eikon(Posted 2004) [#2]
Just worked this out:

Userlib:
.lib "user32.dll"
SetSystemCursor%(hcur%, id%)
LoadCursor%(hInstance%, lpCursorName%):"LoadCursorA"
DestroyCursor%(hCursor%)
LoadCursorFromFile%(filename$):"LoadCursorFromFileA"
GetCursor%()

B+ Code:
Graphics 640, 480, 16, 2

Const OCR_NORMAL   = 32512 ; Normal
Const IDC_SIZEALL  = 32646 ; Size all

oldCur% = GetCursor() ; Save Default Cursor

; Load New Cursor
;hCur% = LoadCursor(0, IDC_SIZEALL)      ; Size All System Cursor
hCur% = LoadCursorFromFile("target.cur") ; Custom Cursor
SetSystemCursor hCur%, OCR_NORMAL
DestroyCursor hCur%

Repeat: Until KeyDown(1)

; Restore 
hCur% = LoadCursor(0, oldCur%)  
SetSystemCursor hCur%, OCR_NORMAL
DestroyCursor hCur%
End

I can't seem to get it to restore the original cursor correctly, though im sure that code should work. Hopefully someone can spot the problem.


Binary_Moon(Posted 2004) [#3]
It's a lot easier than that :)

userlib needed is

.lib "user32.dll"
LoadCursor%( ID, Cursor ):"LoadCursorA"
SetCursor%( ID ):"SetCursor" 


You can also use these for the different cursors

; Mouse Pointers
Const IDC_ARROW			= 32512
Const IDC_IBEAM			= 32513
Const IDC_WAIT			= 32514
Const IDC_CROSS 		= 32515 
Const IDC_UPARROW 		= 32516
Const IDC_SIZENWSE 		= 32642
Const IDC_SIZENESW 		= 32643
Const IDC_SIZEWE 		= 32644 
Const IDC_SIZENS 		= 32645 
Const IDC_SIZEALL 		= 32646 
Const IDC_NO 			= 32648 
Const IDC_HAND 			= 32649
Const IDC_APPSTARTING 	= 32650
Const IDC_HELP 			= 32651
Const IDC_ICON 			= 32641
Const IDC_SIZE 			= 32640

And then you just use

cursor = loadcursor(0,cursor_constant)

And setting the cursor is as simple as

setcursor cursor

If you don't use setcursor in a loop then Blitz automatically resets the cursor to the default arrow.


Eikon(Posted 2004) [#4]
We're talking about loading the cursor from file, does SetCursor restore the default correctly when used with LoadCursorFromFile?


Binary_Moon(Posted 2004) [#5]
Heres a demo

You'll have to change it to load a cursor since I don't have any to hand.

Just click the black square (canvas) to change the cursor.

window = CreateWindow("Cursor Test",200,200,200,200,0,1)
canvas = CreateCanvas(0,0,200,200,window)

quit = False

; Mouse Pointers
Const IDC_ARROW			= 32512
Const IDC_IBEAM			= 32513
Const IDC_WAIT			= 32514
Const IDC_CROSS 		= 32515 
Const IDC_UPARROW 		= 32516
Const IDC_SIZENWSE 		= 32642
Const IDC_SIZENESW 		= 32643
Const IDC_SIZEWE 		= 32644 
Const IDC_SIZENS 		= 32645 
Const IDC_SIZEALL 		= 32646 
Const IDC_NO 			= 32648 
Const IDC_HAND 			= 32649
Const IDC_APPSTARTING 	= 32650
Const IDC_HELP 			= 32651
Const IDC_ICON 			= 32641
Const IDC_SIZE 			= 32640

cursor = LoadCursor(0,IDC_IBEAM)

Repeat

	Select WaitEvent()

	Case $201 ;mouse down
	
		SetCursor cursor
	
	Case $803 ; window close
	
		quit = True
	
	End Select

Until quit = True

End