PDA

Click to See Complete Forum and Search --> : Shaded mouse cursor like Win2K


Mad Compie
Jan 30th, 2001, 12:48 PM
Oops.
How can we simulate the shaded mouse cursor like in Windows 2K?
I think it is done use Alphablending? Correct?

jovton
Jan 31st, 2001, 03:25 PM
What you mean?

kedaman
Jan 31st, 2001, 05:23 PM
in your game or in windows environment?

Mad Compie
Feb 1st, 2001, 01:43 PM
I mean through a Windows environment, like a personal app. I don't think Microsoft used DX to accomplish this, not?

parksie
Feb 1st, 2001, 02:07 PM
I think it's just a modification to the windows internals, so that when it draws the cursor it automatically does the alpha-blending on it.

I don't think it's the sort of thing that it's possible to change.

Mad Compie
Feb 1st, 2001, 02:15 PM
I don't want to change it, I want to reproduce it! Come on Parksie, you're smart, give me the algorithm...

parksie
Feb 1st, 2001, 02:20 PM
You wouldn't be able to properly reproduce it in Windows, but you could do it in your own programs by blitting a 32-bit image with alpha as the pointer.

Mad Compie
Feb 1st, 2001, 02:32 PM
That's what I had also in mind. But it has to be a transparent Blt too. So, this could be a nice exercise for me using this new Alphablend API, combined with the familiar Blt operations.

kedaman
Feb 1st, 2001, 05:25 PM
ALphablendin effects in win2k are done with a certain api that is dependent on the system i think, the cursor is also pretty deep into the system since it's the last thing that moves when i crash. But the algoritm isn't that hard, split up all color components, multiply by alpha component for source and 1-alpha for target and add them up. On the cursor thing, a fullscreen app would be ideal but blitting outside wouldn't.

Jotaf98
Feb 2nd, 2001, 08:24 AM
If it's in Windows, you could hide the real cursor and use a small window with the effect in its position.

But in that case the alpha blending routine would have to be very fast... there's an API that automatically alpha-blends a window; by modifying the form's shape so it looks like a regular cursor and using that, you should get a different cursor ;)

/\/\isanThr0p
Feb 2nd, 2001, 10:02 AM
Hey Jotaf

Do you have any code for the window alphablending?? I had one some time ago, but it didn't work, so I didn't work further on it.

Mad Compie
Feb 11th, 2001, 04:49 AM
Hi kids, I'm back again in my thread.
I developed some code to simulate the a-blended (shaded ) mouse cursor.
See the attached ZIP, it also includes the source code.
Unfortunately, there's some flicker (guess the for-next loop 32x32 getpixel and setpixelv) but I did not had the time yet to solve this.
I also think that I should use another mask (a coloured one) for the shadow effect.

Ph34R
Feb 14th, 2001, 04:50 PM
Why dont you just get a cursor makin proggie, and make your own cursor with a shadow? Their is a program called Microangelo, available on http://www.downloads.com/

It might not look as beutiful as muh lil win2k cursor, :P but it will look better then using vb to make a fake shadow.

The shading is Win2k specific, cant be done without it, unless you make a program that fakes it :P

Jotaf98
Feb 16th, 2001, 12:08 PM
Ph34R: I'm sure he worked very hard on this, so you shouldn't make it look like a joke now.

All he has to do is make that effect appear in a shaped (notice the "P" in "shaPed", it's not a "D" :) ) form, and voila! ;)

Mad Compie
Feb 16th, 2001, 01:46 PM
Thanks Jotaf98!
And Ph34R or something, my goal was to fake it, so I don't need this stupid MicroAngelo soft.
By the way, the flicker is almost gone by using a look-up table.
See the attached ZIP.

Ph34R
Feb 16th, 2001, 02:12 PM
hey, thats prety cool :)

but i still prefer my win2k shaded cursor

;)

djhayman2k+1
Aug 13th, 2001, 10:55 PM
Sorry people, but the transparent shadow uses a widely documented API known as 'Layered Windows' (Win2K or above, not Windows Me).


TO MAKE A WINDOW LAYERED:


public const WS_EX_LAYERED = &H80000

SetWindowLong hWnd, GetWindowLong(hWnd, GWL_EXSTYLE) or WS_EX_LAYERED)


TO MAKE A WINDOW TRANSLUCENT:

public const LWA_COLORKEY = 1
public const LWA_ALPHA = 2

public declare function SetLayeredWindowAttributes(ByVal hWnd as long, byval crKey as long, byval bAlpha as byte, byval dwFlags as long) as long

SetLayeredWindowAttributes hWnd, 0, 128, LWA_ALPHA


If you set the second argument, crKey, and put 'or LWA_COLORKEY' at the end, this will make whatever color crKey is completely invisible (i.e. if you set crKey to 0 which is black, all black parts of the form will be invisible). By invisible it means two things: not drawn on screen, and not able to be clicked on (if you click on an invisible bit, the focus goes through to the window underneath).

Enjoy!

djhayman2k+1
Aug 13th, 2001, 11:03 PM
Oops! I stuffed up. Should be:


public declare function SetLayeredWindowAttributes lib "User32" (ByVal hWnd as Long, ByVal crKey as Long, ByVal bAlpha as Byte, ByVal dwFlags as Long) as Long

public declare function SetWindowLong lib "User32" (ByVal hWnd as Long, ByVal Index as Long, ByVal NewValue as Long) as Long

public const WS_EX_LAYERED = &H80000
public const LWA_COLORKEY = &H1
public const LWA_ALPHA = &H2
public const GWL_EXSTYLE = ? (Get from Api Text Viewer)

private sub Form_Load()
SetWindowLong hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) or WS_EX_LAYERED

SetLayeredWindowAttributes hWnd, 0, 128, LWA_ALPHA

end sub


That's better.

Jotaf98
Aug 14th, 2001, 11:10 AM
Heh, cool! (Both of you :p )

Mad Compie, you should probably use the layering technique to allow us to use your cursor with other programs ;)

Sastraxi
Aug 14th, 2001, 11:52 AM
In Win2k, ASM was used for everything, I think. Therefore you will have to use some MOV statements and see what you get ;)

Jotaf98
Aug 14th, 2001, 12:11 PM
Heh, I think I saw a "in-line ASM for VB" demo at Planet Source Code ;)

Mad Compie
Aug 24th, 2001, 04:08 PM
This layering API is only for WIN2K, not for Win9x.

Jotaf98
Aug 24th, 2001, 07:42 PM
Ok, then he could use just the old "shaped form" APIs :)

Mad Compie
Aug 26th, 2001, 01:36 PM
Meaning: using a transparent form of let's say 32x32 as the screen cursor?
Why not, let's give it a try...

Jotaf98
Aug 26th, 2001, 02:31 PM
When it's done, don't forget to reply here ;)

Mad Compie
Aug 27th, 2001, 02:37 PM
It won't be for the next couple of hours.

Jotaf98
Aug 28th, 2001, 10:15 AM
Ok, no problem :)

Mad Compie
Sep 1st, 2001, 04:40 AM
Well here it is!

Some considerations:
* it's not really a cursor: clicks and mouse events should be programmed too (perhaps with WaitAsyncKeyState)
* i hide the system mouse cursor, but when you move the mouse fastly, it appears again for some ms

Jotaf98
Sep 1st, 2001, 06:17 PM
Hey, that's easy to solve, just make it so that the pixel where the mouse pointer is a "hole" (with the shaped form functions). It only has to be the size of a pixel :)

Jotaf98
Sep 1st, 2001, 06:32 PM
Oh, and that's a nice effect you have there ;)

And the HideCursor API doesn't work well because it only works inside your form, and when the user moves it too quickly the form is not always there. And it will stop working after you do what I told you above :eek:
Try passing it 0 as the handle, or get the handle of the desktop... something like that :)

Sastraxi
Sep 1st, 2001, 08:59 PM
Yes, the desktop DC is GetDC(GetDesktopWindow)

Mad Compie
Sep 2nd, 2001, 03:20 AM
What a nice remark, Jotaf98!
That works, but then i can't use the ShowCursor API anymore and the form won't have the focus anymore. I think I'll have to use an empty cursor shape as the default cursor shape.
Also: when loading my app, I grap a copy of the desktop, but when the desktop changes (like some selection with the mouse), the memory DC does not change!
Any suggestions?

Jotaf98
Sep 2nd, 2001, 07:09 PM
The form doesn't need the focus to move! Aren't you using an API to get the mouse's position? If you take out that pixel and give ShowCursor the desktop's handle or 0, it should work and with no cursor flickering :)

Easy, just bitblt directly from the DC you just got from the desktop instead of using a copy :D

Mad Compie
Sep 3rd, 2001, 01:47 PM
ShowCursor's parameter is not a hWnd or hDC!
Besides, I also lose a pixel (upper left corner) from my arrow if I use this method, I can't redraw a dot because it is not part of the form.

Jotaf98
Sep 5th, 2001, 05:22 PM
With the right cursor, you won't have any problem with that pixel ;)

Oh sorry, I thought that ShowCursor would take a handle and hide the cursor there :) How the hell does it find out it's that form's handle? :eek:

Sastraxi
Sep 5th, 2001, 08:39 PM
In the call back procedures that VB takes care of you it accesses it's hWnd of the thing that called it, quite complicated really (if you think about it too hard!) but a bit simple at the same time...

Anyways, you need to fix the problem in your cursor, how that it takes the DC but it doesnt refresh, so that I had a winzip open, it's titlebar was green. I clicked elsewhere and the titlebar turned gray (that's the colour scheme for my computer ;)) and when I put the mouse over it, the titlebar showed through green.

Ah, "Also: when loading my app, I grap a copy of the desktop, but when the desktop changes (like some selection with the mouse), the memory DC does not change! Any suggestions?"

I see you've already spotted this problem ;).

Mad Compie
Sep 6th, 2001, 11:22 AM
That's correct Sastraxi!
That's why I implemented only a single GetDC(0) to obtain the desktop once (=most simple way of programming). If it changes, the changes won't affect my cursor app.
So, anybody knows how to grab permanently only some segment of the desktop?
Or does there exists some API to control/create a real global user-defined cursor?

A consideration: the same effect should be acchieved when U drag a desktop icon (full coloured) around the desktop => also in Win98! ...

Jotaf98
Sep 6th, 2001, 07:09 PM
Hum, you're right, if you grab the screen again you'll get the screen + your cursor :)

Maybe you could hide it, grab the screen and show it again. If you don't do it too often (every second should be enough) it won't flicker ;)

Sastraxi
Sep 6th, 2001, 07:25 PM
You're right about the icon thing.

Jotaf98
Sep 7th, 2001, 01:20 PM
Yeah, but it's probably hard-coded into windows :(

Jotaf98
Sep 7th, 2001, 06:46 PM
So?... :D

Sastraxi
Sep 7th, 2001, 07:29 PM
I was kind of just thinking out loud, if a problem was with the cursor showing on the desktop DC :p

Mad Compie
Sep 8th, 2001, 02:03 PM
Overlaying windows in Win9x? It should be possible in VB, not?
Question is: how?
Any guru around?

Jotaf98
Sep 8th, 2001, 02:10 PM
Look, our problem here is grabbing the desktop's dc WITHOUT a window, not overlaying or anything :D

Sastraxi
Sep 8th, 2001, 11:23 PM
I think I have a quick fix BRB