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 


Change any system(global) cursor to a custom cursor

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code
View previous topic :: View next topic  
Author Message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Wed Jul 23, 2003 2:42 am    Post subject: Change any system(global) cursor to a custom cursor Reply with quote

Change any system(global) cursor to a custom cursor :
This script shows U how to change system or global cursors.
This can be helpful if U are working across two applications linked to each other in some way and inform end user that the current status - busy/waiting etc.

For simple applications within your dialog U can use "Dialog cursor" command in VDS; Don't use this Smile
You should note that this changes the system cursor and if your app crashes in middle then the changed cursor remains. This can severely annoy the user.
To avoid that you can store the copied cursor handle to a safe place - registry/ini and restore it when your app is restarted.
Else the user has to go to contol panel ->mouse->pointers and restore it.
This has been explained in the comments of this sample but I have not implemented it in my current script.

This is just a primer as to what U can do with cursors using API.
U can do many more simpler things with cursors !! e.g change arrow to appstarting etc.
I just wrote this example as i needed this for my VDS tray helper project.

I have added constants for various system cursors in the script comments.
And if any one needs rainbow.ani used in the example it is in second box.
Just copy the code to notepad, Save as rainbow.uue and extract the cursor using winzip.
Tested on XP. Should work on 9x also.

So Enjoy.

AS USUAL THIS SCRIPT USES NON VDS DLL AND API
SAVE YOUR WORK AND RUN THE SCRIPT AT YOUR OWN RISK.

Code:

  Title Change System Cursor by CodeScript
  DIALOG CREATE,Change System Cursor by CodeScript,-1,0,356,119,CLASS MYWIN,NOMIN
  DIALOG ADD,STYLE,STYLE1,,11,B,,
  DIALOG ADD,GROUP,GROUP1,1,-1,361,128,,,SIZE
  DIALOG ADD,BITBTN,ChangeCursor,39,110,123,35,,Change Cursor,,STYLE1
  DIALOG ADD,BITBTN,Reset,39,110,123,35,,Reset Cursor,,STYLE1
  DIALOG SHOW
  DIALOG HIDE,Reset
  LOADLIB USER32

:RESIZE
 goto EVLOOP

:Evloop
  wait event
  goto @event()

:ChangeCursorBUTTON
DIALOG HIDE,ChangeCursor
DIALOG SHOW,Reset
#LOAD A CUROR FROM FILE AND GET ITS HANDLE
#U can replace rainbow,ani by a cursor name you have placed
#in the app directory
%A = @lib(user32,LoadImageA,INT:,0,rainbow.ani,2,0,0,$10)
%H = @strdel(@WINEXISTS(#MYWIN),1,1)
 IF %H
    %I = @LIB(user32,GetCursor,INT:,)
#"Make a copy of your current cursor
#so that U can restore it :-)"
    %J = @LIB(user32,CopyImage,INT:,%I,2,0,0,$4000)
#If U R concerned "what if my application crashes?"
#write the value of %J to a INI file/registry
#so that if there is an entry in the ini then
#your application restores the system cursor from that handle value
#when the application is restarted
#this can prevent annoyance to the end user
#otherwise the user has to go to control panel->mouse->pointers
#and reset the cursor. Not easy for a newbie to computers   
    %K = @lib(user32,SetSystemCursor,INT:,%A,32512)
#"Now change the system cursor "32512" i.e.OCR_NORMAL or Standard arrow
#to %A your custom cursor".
REM You can change other system cursors too:
REM Their constants are as follows:
REM 32650 - OCR_APPSTARTING Standard arrow and small hourglass
REM 32512 - OCR_NORMAL Standard arrow
REM 32515 - OCR_CROSS Crosshair
REM 32649 - OCR_HAND Windows 2000: Hand
REM 32513 - OCR_HELP Arrow and question mark
REM 32513 - OCR_IBEAM I-beam
REM 32648 - OCR_NO Slashed circle
REM 32646 - OCR_SIZEALL Four-pointed arrow pointing north, south, east, and west
REM 32643 - OCR_SIZENESW Double-pointed arrow pointing northeast and southwest
REM 32645 - OCR_SIZENS Double-pointed arrow pointing north and south
REM 32642 - OCR_SIZENWSE Double-pointed arrow pointing northwest and southeast
REM 32644 - OCR_SIZEWE Double-pointed arrow pointing west and east
REM 32516 - OCR_UP Vertical arrow
REM 32514 - OCR_WAIT Hourglass
    ELSE
   ERROR -1
  end
  goto EVLOOP

:ResetBUTTON
DIALOG HIDE,Reset
DIALOG SHOW,ChangeCursor
%K = @lib(user32,SetSystemCursor,INT:,%J,32512)
%K = @lib(user32,DestroyCursor,BOOL:,%J)
goto EVLOOP
 
:Close
REM "You SHOULD add these lines above the close label
REM so that the system cursor is restored back to original one at EXIT"
%K = @lib(user32,SetSystemCursor,INT:,%J,32512)
REM Once you have restored the cursor you can
REM destroy the CURSOR copy U made and replenish the memory.
%K = @lib(user32,DestroyCursor,BOOL:,%J)
FREELIB USER32
  exit

Code:

_=_ Part 001 of 001 of file Rainbow.cab
_=_

begin 666 Rainbow.cab
M35-#1@````"N`@```````"P``````````P$!``$`````````2`````$``Q4.
M)0``````````X2[Y;2``<F%I;F)O=RYA;FD`B:LP=%X"#B5;@("-`A#A4```
M`P!`-```#C!"MO].^_X3A=$*022(!.`2TEFEE):VZUQ9(DMX9=40(JF=W_CY
MA8$?7OF9'_/C[+R!21'Z@&@``)H!`B@B@+P'^8-_X27]!;)HQD0F4`@)N@DM
M:T**+J+;%82<!`E$G:8[\?[]+/\`0```1@"*!F`*91$/1!8\^[VF(_D[H(/%
M.9WYDYV0D5;?2J7Y^)FY/5G^_$GU<_(S,NI]??GK'4([G\;/@NF;YZOU9]:W
MCUVM#BV?'9U,;#I[E[H:>BS6]NF]-SY/CZV7'NT)XF+J]FEHTMAQZL`'L]?.
M<P66N\N%G';Q5WYK/\ZO7QGH<8_QS,DPO_CZN#SDP2:VX">MGM+YKZ?!?;1[
M<>"Z=P[7K5[?7MU:.&_\+7M;8O/[]G5CX+S[M]^?K]HFK0U@G]^J;M*J+EV.
M\HY:A3A<7#8WM=T'53X,POM\OPS?M@I9?[4Y-U7`'HWY7W/B#^_UBEZ>>_J9
M<71GOXP*,3K[J`HLU#DH]*/"E0__M$"@//H=0@57GM:-4=1&&T/:FX>M+.X8
M9KI'AZY!6(>PP%48Y5?4&TMS_OVE>?@$!A`74&0Z0&D=M05@/-`M^H(H#*`N
MF\H-0B)T8YRW&PM*&,E<$)%!)08$!+6AMA"8YX<%,)*ZH"J#:0P@MD+9S"F'
M,4&I(H$,XC&(VR!`4!M&Q78[L2S@D<`&=1A49M"!3<8&31&,\4K!B0L0&4%B
M@K:"\F`">-@S6P/"Q%6HC*`Q@LQL^C:(BF"#<,IE9!#$2&V#Y`44&`\0S(9_
+`1'%D2*@2%6DP"\`
`
end

_______________________________________________________________________________

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Mon Oct 25, 2004 3:46 am    Post subject: Reply with quote

Hi Codescript,

Is there a way to change the edit cursor (i.e. the edit caret) globally?

Thanks,

- Boo
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 Oct 25, 2004 9:57 pm    Post subject: Reply with quote

Might check out CreateCaret and ShowCaret:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/carets/caretreference/caretfunctions/createcaret.asp
Quote:

The CreateCaret function creates a new shape for the system caret and assigns ownership of the caret to the specified window. The caret shape can be a line, a block, or a bitmap.

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Tue Oct 26, 2004 4:19 am    Post subject: Reply with quote

Thanks Sheep. Any chance of an example in VDS? Wink
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Oct 26, 2004 4:21 am    Post subject: Reply with quote

Maybe tomorrow Wink
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Tue Oct 26, 2004 4:24 am    Post subject: Reply with quote

You rule! Wink
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Oct 26, 2004 10:55 pm    Post subject: Reply with quote

Not global, but hopefully you can do something with it:
http://forum.vdsworld.com/viewtopic.php?p=23107#23107

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Tue Oct 26, 2004 11:01 pm    Post subject: Reply with quote

Cool. Thanks. Smile

No way to do it globally?

Cheers,

- Boo
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Oct 26, 2004 11:38 pm    Post subject: Reply with quote

Not that I know of.
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Wed Oct 27, 2004 2:46 am    Post subject: Reply with quote

Hi Sheep,

Thanks again.

By the way... This may be a dumb question, but is there a way to set the IBeam cursor (i.e. the little cursor that displays in an edit box and over text that can be copied) to a custom cursor using API?

Thanks,

- Boo
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Oct 27, 2004 7:53 pm    Post subject: Reply with quote

Yes, in CodeScripts code, where it says:
%K = @lib(user32,SetSystemCursor,INT:,%J,32512)
replace 32512(OCR_NORMAL) with 32513(OCR_IBEAM)
That's why he put in the remarks:
Quote:
REM You can change other system cursors too:
REM Their constants are as follows:

Wink

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Wed Oct 27, 2004 10:47 pm    Post subject: Reply with quote

Ah, duhhh! Thanks Sheep.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code 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