forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Setting the cursor

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Aug 09, 2004 5:35 pm    Post subject: Setting the cursor Reply with quote

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
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Aug 09, 2004 5:57 pm    Post subject: Reply with quote

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... Smile):

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
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Mon Aug 09, 2004 6:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Aug 09, 2004 7:30 pm    Post subject: Reply with quote

SnarlingSheep, your code works for about 0.5 seconds here... Confused It seems that when VDS executes the "WAIT 3" line, the cursor is put back to the normal one...
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Mon Aug 09, 2004 7:47 pm    Post subject: Reply with quote

Skit3000 wrote:
SnarlingSheep, your code works for about 0.5 seconds here... Confused 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
View user's profile Send private message Send e-mail
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Mon Aug 09, 2004 8:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Tue Aug 10, 2004 9:07 am    Post subject: Reply with quote

That looks very much like CodeScript's example I downloaded.
_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Aug 10, 2004 10:12 am    Post subject: Reply with quote

Hi SnarlingSheep, this one works great! Smile The only thing indeed is that you have to know the original cursor file, but I think it can be obtained through the registry... Smile
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Tue Aug 10, 2004 3:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Aug 10, 2004 3:13 pm    Post subject: Reply with quote

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),Cool,@diff(@mousepos(x),Cool
until @event()

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Tue Aug 10, 2004 5:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Aug 10, 2004 10:40 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group