News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using windows Cursors & Custom cursors

Started by timertik, March 25, 2007, 03:13:15 AM

Previous topic - Next topic

timertik

Ok I figured this one would be simple but i have been trying all day to get my cursor set in my dialog
here is the code im using:

.data?
hCursor     dd ?
.ELSEIF uMsg==WM_INITDIALOG
invoke LoadCursor,hInstance,500
mov          hCursor,eax

.ELSEIF uMsg==WM_SETCURSOR
invoke SetCursor,hCursor


it doesnt change it but if i do this:
         .elseif uMsg==WM_LBUTTONDOWN
                            invoke LoadCursor,hInstance,500
            mov hCursor,eax
            invoke SetCursor,hCursor

it will cyhange it when i click on the dialog I dont want this
I want to know how to load my custom cursor on startup

im using windows vista for all this in case it makes a difference
I have searched the forum and everything i try fails ive tried copying from examples and it fails
maybe theres something wrong with my WM_INITDIALOG I am not sure
I have lots of things loading at startup under WM_INITDIALOG I try moving it around but it doesnt work

I also tried:
invoke LoadCursor,hInstance,500
mov hCursor,eax
invoke SendMessage, hWin, WM_SETCURSOR, 1, hCursor

it didnt work either

and i tried ading a cursor to a skeleton app and i get the same results

u

[quick reply]
Visit the 5 results on
http://blogs.msdn.com/oldnewthing/search.aspx?q=WM_SETCURSOR&p=1
The author (a coder from Microsoft) explains how to set cursors correctly, and why things seem so unintuitive.
Please use a smaller graphic in your signature.

timertik

I read through it and identified what was happening (flicker between custom cursor and arrow)
but i still could not resolve how to fix the error.
perhaps someone could explain it to me or show me an example of how they would do it
I really can not make out the examples from Microsoft I understand masm32 and can pick out and translate parts but for the most part its foreign to me
I found this http://www.oldboard.assemblercode.com/index.php?topic=3941.0  but it doesnt work for me either

MichaelW

Assuming the cursor was properly specified in a CURSOR resource statement, then the only possible problem I can see would be if you are not returning true from the WM_SETCURSOR handler.

I don't know if it's possible to specify a class cursor (when the dialog is created) for a dialog that uses the system-defined dialog box class, but you can use SetClassLong to set the class cursor by passing it the handle you got back from LoadCursor. By setting the class cursor to your custom cursor, you can skip the call to SetCursor. Although the documentation states that SetCursor will work correctly only if there is no class cursor, in a dialog with the class cursor set by SetClassLong, it does not seem to matter.

There is a working example that uses SetCursor among the GeneSys examples in the CursorExample directory.

BTW, this all seems to also work with an animated (.ani) cursor.

eschew obfuscation

timertik

the example in the Genesys package doesnt work either when I move the mouse it will flash from ARROW  CROSS
when still it remains an arrow
I will see what i can do with SetClassLong  :thumbu

EDIT:
I get nothing from SetClassLong
invoke LoadCursor,0,IDC_CROSS
mov hCursor,eax
invoke SetClassLong,hCursor,GCL_HCURSOR,eax

maybe I used it wrong although I read it over and over and tried various ways it doesn't change

this method makes the cursor flicker but it doesnt hold a solid cursor
I am placing it right after WM_INITDIALOG
.ELSEIF uMsg==WM_SETCURSOR
invoke SetCursor,hCursor


an example of how I do it included for reference it includes a compiled .exe which has the flicker effect

[attachment deleted by admin]

MichaelW

For me, under Windows 2000 the GeneSys example works just as it should, no flashing at all. Were you running the EXE just as it was provided, and if so what version of Windows are you running?

For SetClassLong the first parameter should be the handle to the window.

Edit:

I just tried your example, and the cursor does not change from the default. I corrected the problem by returning true from the WM_SETCURSOR handler, as was done in my example and the GeneSys example.


[attachment deleted by admin]
eschew obfuscation

timertik

 :clap: your example works for me
I cant believe it took me this long to get it working  :lol
and i thought i was improving
thanks  :U



EDIT:
I  think i figured out why  WM_SETCURSOR wouldnt work
I had a .if statement right after WM_INITDIALOG it was in lowercase and not very visible
I was placing this after the .if statement everytime when i place it before it it works!   :cheekygreen:
now im gonna organize my code.
also...
using this method the original cursor shows up when the mouse is over a dialog item or the caption bar
is there any way to solve this?
I will start searching now

PS: the genesys example .exe worked fine (of course after I found the source of my errors)

MichaelW

Good. Sometimes it can take a long time to find and correct small problems, that in the end you realize should have been obvious.

I think setting the class cursor is a better method, because WM_SETCURSOR seems to be sent whenever the mouse is moved.
eschew obfuscation

CoR

I had similar problem few seconds ago... If anyone want to take a look at:
http://www.masm32.com/board/index.php?topic=6960.0
It works now  :bg And I have no idea why  ::)