| View previous topic :: View next topic |
| Author |
Message |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Mon Aug 09, 2004 5:35 pm Post subject: Setting the cursor |
|
|
Has anyone found a way to change the cursor so that it stays changed even when the pointer isn't over your window? For an example, think of the Windows Spy, and imagine if when you click on Spy, the cursor changes to a crosshair, and stays a crosshair until you click on something else. Other spy software that some of you may have tried, works like that.
You could do this using CodeScript's Custom Global Cursor, but I'm reluctant to do anything that makes global changes, it doesn't seem quite right for this application, as the changed cursor should only show while my app is the active window. Anyone any thoughts? _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Mon Aug 09, 2004 5:57 pm Post subject: |
|
|
Maybe you should look into this MSDN article:
http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/loadcursorfromfile.asp
As far as I understand, this should work (but it doesn't for now... ):
| Code: | DIALOG CREATE,New Dialog,-1,0,240,160
DIALOG SHOW
loadlib user32
%z = @lib(user32,LoadCursorFromFileA,INT:,STR:@windir()\Cursors\lns.cur)
%x = @lib(user32,SetCursor,INT:,INT:%z)
wait event
freelib user32 |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Mon Aug 09, 2004 6:47 pm Post subject: |
|
|
Here ya go:
| Code: |
LOADLIB user32.dll
%%IMAGE_CURSOR = 2
%%LR_LOADFROMFILE = $010
%%LR_DEFAULTSIZE = $040
%%IDC_ARROW = 32512
%%CursorFile = @WINDIR()\Cursors\3dgno.cur
%%cursor = @LIB(user32,LoadImageA,INT:,INT:0,STR:%%CursorFile,INT:%%IMAGE_CURSOR,INT:0,INT:0,INT:@SUM(%%LR_LOADFROMFILE,%%LR_DEFAULTSIZE))
if @UNEQUAL(%%cursor,0)
%%ret = @LIB(user32,SetCursor,INT:,INT:%%cursor)
else
INFO Unable to load custom cursor!
end
WAIT 3
%%cursor = @LIB(user32,LoadCursorA,INT:,INT:0,INT:%%IDC_ARROW)
if @UNEQUAL(%%cursor,0)
%%ret = @LIB(user32,SetCursor,INT:,INT:%%cursor)
else
INFO Unable to load standard cursor!
end
|
BTW Skits problem may have been:
"The cursor must have been created by the CreateCursor function or loaded by the LoadCursor or LoadImage function." _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Mon Aug 09, 2004 7:47 pm Post subject: |
|
|
| Skit3000 wrote: | SnarlingSheep, your code works for about 0.5 seconds here... It seems that when VDS executes the "WAIT 3" line, the cursor is put back to the normal one... |
I had tested using F9 to run the script, where it worked.. I see that it changes back to normal once moved.
Obviously it's not as easy as just using SetCursor, in XP at least.. _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Mon Aug 09, 2004 8:53 pm Post subject: |
|
|
This will work, the only problem is knowing which cursor to reload at the end.
| Code: |
LOADLIB user32
%%OCR_NORMAL = 32512
%%OldCursor = @windir()\Cursors\arrow_m.cur
%%NewCursor = @windir()\Cursors\lns.cur
%%cursor = @lib(user32,LoadCursorFromFileA,INT:,STR:%%NewCursor)
%%ret = @lib(user32,SetSystemCursor,INT:,INT:%%cursor,INT:%%OCR_NORMAL)
WAIT 3
%%cursor = @lib(user32,LoadCursorFromFileA,INT:,STR:%%OldCursor)
%%ret = @LIB(user32,SetSystemCursor,INT:,INT:%%cursor,INT:%%OCR_NORMAL)
FREELIB user32
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Tue Aug 10, 2004 9:07 am Post subject: |
|
|
That looks very much like CodeScript's example I downloaded. _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Tue Aug 10, 2004 3:05 pm Post subject: |
|
|
I thought it would be possible to do this using SetCapture / ReleaseCapture. I wanted to keep the cursor the same wherever I moved it, instead of changing a system cursor (which will still change to an I cursor over a text field, or a double-arrow over a window boundary.) But this didn't work for some reason I couldn't fathom.
Unless someone comes up with something better, I've based my solution on the one developed by CodeScript, but I amended it so it tries to read the cursor from the program resources if present, so you don't have to use a separate file. I thought some people might find this useful, so here it is:
| Code: | #define command,setcursor
:setcursor
# setcursor <name> ( <name> is blank to reset default cursor )
if %1
LOADLIB user32.dll
%H = @LIB(user32,GetCursor,INT:)
%%def_cursor = @LIB(user32,CopyImage,INT:,%H,2,0,0,$4000)
%H = 0
if @equal(@substr(%1,1),#)
# try to load from resource
%1 = @strdel(%1,1,1)
%R = @name(%1)
LOADLIB kernel32.dll
%H = @lib(user32,LoadImageA,INT:,@lib(kernel32,GetModuleHandleA,INT:,0),%R,2,0,0,0)
FREELIB kernel32.dll
end
if @zero(%H)
# try to load from a file
%H = @lib(user32,LoadImageA,INT:,0,%1,2,0,0,$10)
end
if @zero(%H)
%%def_cursor =
else
%R = @lib(user32,SetSystemCursor,INT:,%H,32512)
end
FREELIB user32.dll
else
if %%def_cursor
LOADLIB user32.dll
%R = @lib(user32,SetSystemCursor,INT:,%%def_cursor,32512)
%R = @lib(user32,DestroyCursor,BOOL:,%%def_cursor)
%%def_cursor =
FREELIB user32.dll
end
end
exit |
_________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Tue Aug 10, 2004 3:13 pm Post subject: |
|
|
I may have a workaround for you: hide the cursor, and display a little dialog which acts like a mouse:
| Code: | DIALOG CREATE,MOUSE,10,10,16,16,ONTOP,NOTITLE,INVISIBLE
DIALOG ADD,SHAPE,SHAPE1,8,1,16,1,WHITE,BLACK,,RECTANGLE,CLICK
DIALOG ADD,SHAPE,SHAPE2,1,8,1,16,WHITE,BLACK,,RECTANGLE,CLICK
DIALOG SHOW
repeat
dialog setpos,,@diff(@mousepos(y), ,@diff(@mousepos(x),
until @event() |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Tue Aug 10, 2004 5:13 pm Post subject: |
|
|
Thanks. Neat idea, but the movement is a bit jerky on my slow old PC. _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Tue Aug 10, 2004 10:40 pm Post subject: |
|
|
| jules wrote: | | I thought it would be possible to do this using SetCapture / ReleaseCapture. I wanted to keep the cursor the same wherever I moved it, instead of changing a system cursor (which will still change to an I cursor over a text field, or a double-arrow over a window boundary.) But this didn't work for some reason I couldn't fathom. |
SetCapture is only for mouse events..nothing to do with the cursor look. Would need it to get the mouse click though.(Or wait until your app loses focus and then check mouse position)
At the moment I'm not sure of any way to do what you want without replacing all the cursors with SetSystemCursor and then changing them back after you receive the click message. _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|