../Msgboard/General customization/Another cursor question/requestHome
beaker - 09 May. 2004 - 23:11:

Another cursor question/request

I thought I'd be able to code this one myself in C#, but it's a bit harder than I thought. What I would like is a command-line app that sets the cursor. eg: calling on it with a -working switch sets the cursor to the working state. Calling it with a -default switch would set it back.

.Net doesn't seem to want to set it to 'working', only 'busy' ('app starting' also sets it to 'busy').

VBS doesn't support it (that I've found) and VB6 only works for a form, not all of Windows. I know apps do this when launching/performing a lengthy task. Is there an easy solution that I'm overlooking?
 
11 May. 2004 - 00:17 Red
You got me kinda stumped, not that I can really code well. I can see why you would want it though.

Only make shift-thing I think of would be to change the icon in windows, and then change it back, but that would have nasty side effects.

Anyway to find out what the cursor is and to change it to that one like in kewlpad or winamp?
 
11 May. 2004 - 03:34 beaker
Red, changing the default cursor in the registry is an interesting solution.

[thinking] It could read what's currently in the registry for 'working' and write that to 'default' (which would need to be backed up somewhere). I wonder if the cursor would automatically refresh based on updating the value in the registry.[/thinking]

/me runs off to experiment.
 
11 May. 2004 - 04:13 beaker
Well, no luck in C# (again). Will try VB6 at work tomorrow. Thanks for getting me thinking...
 
11 May. 2004 - 11:27 grigri
I doubt it's going to be easy in VB6. Cursors are defined in 2 ways - by window classes (the hCursor attribute in the WNDCLASS struct - retrieve it by calling GetClassLong(hWnd, GCL_HCURSOR)) and by replying to the WM_SETCURSOR message.

Both of these happen every time the mouse is moved. It's the DefWindowProc() which reads the class cursor and sets it, so you could override by subclassing all the windows, or installing a global WH_CALLWNDPROC hook (so VB6 is not a good solution because it can't make standard dlls), and just ignoring the message (return TRUE).

If that sound a bit too tough, try this idea: Hide the cursor, and display your own. You can easily retrieve the cursor position, then create a 32x32 window, copy the background on it, draw the cursor, then update it continuously. When you need to change the cursor back, just delete the window and show the cursor. This could be done easily in VB6, either with a JournalRecordProc hook (they don't need to be in a standard dll), or even really low-tech: with a timer and calls to GetCursorPos().


 
11 May. 2004 - 15:36 Red
As always, grigri's idea sounds better than mine. ^.^ Let us know if it works. 8)
 
11 May. 2004 - 17:01 grigri
There's a flaw in my first approach - if you're subclassing all the windows it's fine [but that's a bit heavy, really], but if you want to use a global hook you have to install a WH_GETMESSAGE hook, not a WH_CALLWNDPROC, because the latter doesn't allow you to change the message parameters. And you can't just return NULL, you have to change the message member of the MSG struct from WM_SETCURSOR to WM_NULL.

Of course, a really low-tech solution would be to set a relatively fast timer to call SetCursor() repeatedly. SetCursor() is optimized not to do anything [and to return fast] if the cursor is not actually changing. You might have a bit of flicker with this approach though, although it's certainly a lot easier than the others.

*after testing*
forget that idea, it does flicker far too much :(
 
11 May. 2004 - 18:26 grigri
Try this [9KB].

It includes all source, but no comments or readme.

Run the exe once to display the wait cursor, run it again to stop.

The dll is packed as a resource into the exe, it will extract itself on the first execution.
 
11 May. 2004 - 18:32 Red
That flicker method also would kill animations in cursors.

You know, this little app could be used just to drive your friends crazy. >:) Just place it in the startup folder and ... hehehe :D
 
11 May. 2004 - 18:40 Red
Also, don't know if this is a bug or just how the method works, but I notice the cursor doesn't change until you move it. Not a big deal, and should work for what beaker wants to do... and for what I want to do. >:)

Evil thoughts! Evil thoughts! =^.^=
 
11 May. 2004 - 22:32 beaker
What I'd really like to know is how to call the function/procedure/method to display the currently-listed cursor in the registry. Basically mimic what IconPhile or the Mouse Control Panel applet does when you hit apply after changing the mouse cursors. Ideally a C# example... Instead of me creating a band-aid overlaid cursor a la WinAmp, I just let Windows do the work for me. I set the registry entry and tell Windows to refresh the cursor. Theoretically easy if you know what function to call (hence the dilemna).

Is there an app that will notify you of what shell32.dll/explorer.exe/etc functions are being called?
 
12 May. 2004 - 11:31 grigri
You can change the system cursors with the SetSystemCursor() function - is that what you mean?

As for being notified of what functions are being called, check this article, this one and this one.
 
12 May. 2004 - 16:02 beaker
grigri, thanks for all the info. I'll investigate and report back.

[UPDATE] It looks like there is a Windows API in user32.dll to this and the other cursor functions. I think that's what I need. Many thanks. :)
 
13 May. 2004 - 03:36 beaker
Funny...I was just coming to post that I was successful and I wanted to re-read the thread to make sure I had accounted for everything and I just noticed that grigri had already posted something. Now I feel guilty :(

Well, I was successful. It works like I was wanting it to, via command-line switches. -busy -working or -default. -reload saves your current default value in case you change cursor themes (which I haven't done in like 4 years :p ). It's available here http://beaker.virtualplastic.net/download/cursor.zip [9KB also] and contains the executable and the C# source. I plan on recompiling it at work because I notice the exectuables pack better on a NTFS drive, usually reducing filesize. I'll put info up on http://beaker.virtualplastic.net/ tomorrow.
 
13 May. 2004 - 09:55 grigri
Very nice, good one beaker.

I'd point out that although this will work in 90% of cases, what about when apps load a custom cursor? That'll still be shown and there's nothing you can do about it.

Other thing: I'm not a .NET person, but I was told that .NET makes tiny executables. How come yours is 16KB? I mean, there's not that much code in it - my dll has far more and it's only 2.5 KB [Yeah, I know the exe is 24KB but that's VB for you... anyway the dll does all the work].
 
13 May. 2004 - 15:25 beaker
grigri,

Thank you :)

I didn't think of apps that load custom cursors, good point. Luckily I tend to disable them (eg: WinAmp), but I shouldn't assume everyone does.

I think the 16KB is my cluster size at home (FAT32 drive). I compiled the exact same code here at work and it was 6KB. I added better error-checking that increased it to 7KB. I'll upload it when I get home (no upload access from work). I want to say that I've never compiled a C# console app and have it less than 6KB, but I could be wrong.
 
14 May. 2004 - 00:03 beaker
Site updated...

Thank you again grigri for pointing me to the SetSystemCursor() function and creating an app so quickly (so quick I didn't even notice it :) )
 
09 Dec. 2004 - 05:20 beaker
Just blowing the dust off of this one. I got an email saying it didn't work if no cursors were set up in the registry, so it's been updated to address that.

Same link as last time
 
Please log-in to post.
You need to be logged in to post. To log-in, or to register an account go -there.
 
Options
Login | Help | Profile | User list | Display last  
 days 


../Msgboard/General customization/Another cursor question/requestTop

xhtml 1.1