Hello,

I am trying to make things move/change, or whatever when the mouse cursor is over a element. I dont know what to search for... I tried "mouse over" "... sensitive: ... no use...

What options I have to do that?

Tnx! :)
Posted on 2002-11-22 13:50:31 by wicr0s0ft
WM_MOUSEMOVE
Posted on 2002-11-22 14:31:53 by tenkey
The ONLY way to do that is tracking the mouse coordinates on my window? I was thinking if I could do something like "onmouseover" for just a few elements of my window (a button, and one or 2 static controls)... so I really have to build the routines to process the values? ... it could be fun too. :)

Ps:
Ok, I dont know what is with this board, but I have looked on that API. I think most people here find it too bad when people ask dumb looking questions or if you want, newbies... I think it is better to give them a good big answer, and maybe some options or things to look for, from their current knowledge, helping them to achieve what they are trying to do... but this discussion coud be on the Heap...
Posted on 2002-11-22 14:46:07 by wicr0s0ft
Any other suggestions?
Posted on 2002-11-22 15:32:27 by wicr0s0ft
I apologize for the extremely brief answer.

For controls (such as buttons), you may need to subclass the controls. See Iczelion's tutorials. What messages to look for with subclassing? Maybe WM_MOUSEMOVE or WM_SETCURSOR.

Hope someone can give you more ideas.
Posted on 2002-11-22 15:57:57 by tenkey
No worries.

Thanks for the ideas. It helped me to search more specifically. :)

... and yeah, I hope more good ideas come. I have to learn what subclassing is, but Im not sure it will be what I want.... better when you know, right? ;)

See ya'round.

Tnx again.
Posted on 2002-11-22 20:11:34 by wicr0s0ft
Code taken from Ewayne's code generator which produce a mouseover button



;---------- [Place in the Resource file (.rc)] ----------
136 BITMAP DISCARDABLE "MouseO4U.bmp"
137 BITMAP DISCARDABLE "MouseO4O.bmp"
138 BITMAP DISCARDABLE "MouseO4D.bmp"
;---------- [End of resource definitions] ----------

;---------- [Place in the Application or Include file] ----------
ControlButt PROTO :DWORD, :DWORD, :DWORD, :DWORD

;---------- [Place in the Application file (.asm)] ----------
.data
ButtClass db 'BUTTON',0
FontName db 'MS Sans Serif',0

.data?
hButt5 dd ?
lpButCtrl dd ?
hFontB dd ?

Butt5D dd ?
Done dd ?

lf LOGFONT <>

.code

start:
.
.
.
.if wMsg == WM_CREATE
;---------- [Create the OwnerDrawn Button Control] ----------
INVOKE CreateWindowEx, 0, addr ButtClass, 0,
WS_CHILD or WS_VISIBLE or BS_OWNERDRAW,
20, 20, 115, 26, hdlg, 187, hInst, 0
mov hButt5, eax

;---------- [Subclass the Control] ----------
INVOKE SetWindowLong, hButt5, GWL_WNDPROC, ControlButt
mov lpButCtrl, eax

;---------- [Create the Button Font] ----------
INVOKE lstrcpy, addr lf.lfFaceName, addr FontName
mov lf.lfHeight, 14
mov lf.lfWeight, 600
INVOKE CreateFontIndirect, ADDR lf
mov hFontB, eax

;---------- [Load the Bitmaps] ----------
INVOKE LoadBitmap, hInst, 136
mov hBmp5U, eax
INVOKE LoadBitmap, hInst, 137
mov hBmp5O, eax
INVOKE LoadBitmap, hInst, 138
mov hBmp5D, eax

;---------- [Delete Objects] ----------
.elseif wmsg == WM_DESTROY
INVOKE DeleteObject, hBmp5U
INVOKE DeleteObject, hBmp5O
INVOKE DeleteObject, hBmp5D
INVOKE DeleteObject, hFontB
.
.
.

;=================================================
; Copies an image to the face of a Button
;=================================================
CopyBitMap PROC hButt:DWORD, hBmp, bWh, bHt
LOCAL hMemDC:DWORD, hDC

INVOKE GetDC, hButt ; Get the dc of the button
mov hDC, eax
INVOKE CreateCompatibleDC, hDC ; Create a compatible dc in memory
mov hMemDC, eax
INVOKE SelectObject, hMemDC, hBmp ; Select the opened bitmap into the dc
INVOKE BitBlt, hDC, 0, 0, bWh, bHt, hMemDC, 0, 0, SRCCOPY ;Copy the bitmap
INVOKE DeleteDC, hMemDC ; Delete the memory dc
INVOKE ReleaseDC, hButt, hDC ; Release the control dc

xor eax, eax
ret
CopyBitMap endp

;=================================================
; Subclass procedure for the Control Buttons
;=================================================
ControlButt PROC hwnd:DWORD, wMsg, wParam, lParam

INVOKE CallWindowProc, lpButCtrl, hwnd, wMsg, wParam, lParam

.if wMsg == WM_PAINT
PaintEM:
mov eax, hwnd
.if eax == hButt5
mov Butt5D, 0
INVOKE CopyBitMap, hwnd, hBmp5U, 115, 26
.endif
mov UpDown, 1

.elseif wMsg == WM_LBUTTONDOWN
mov eax, hwnd
.if eax == hButt5
mov Butt5D, 1
INVOKE CopyBitMap, hButt5, hBmp5D, 115, 26
.else
jmp PaintEM
.endif

.elseif wMsg == WM_MOUSEMOVE
INVOKE GetClientRect, hwnd, addr rect
mov ebx, lParam
mov ecx, ebx
and ebx, 0000ffffh
shr ecx, 16
mov eax, hwnd
.if eax == hButt5
.if ebx >= rect.left && ebx <= rect.right &&\
ecx >= rect.top && ecx <= rect.bottom
INVOKE SetCapture, hButt5
.if Butt5D
INVOKE CopyBitMap, hButt5, hBmp5D, 115, 26
.else
INVOKE CopyBitMap, hButt5, hBmp5O, 115, 26
.endif
.else
INVOKE ReleaseCapture
jmp PaintEM
.endif
jmp Ret1
.endif

.elseif wMsg == WM_LBUTTONUP
mov eax, hwnd
.if eax == hButt5
and Butt5D, 0
INVOKE CopyBitMap, hButt5, hBmp5O, 115, 26
.else
jmp PaintEM
.endif
.endif

Ret1:
mov eax, TRUE
ret
ControlButt ENDP
Posted on 2002-11-23 00:44:43 by roticv
:)

I see that the only way of doing mouse overs is to tracking its coordinates... I'll be fubling 'round these codes for sometime now... :)

Thank you all for the pull!
Posted on 2002-11-24 08:45:11 by wicr0s0ft
Search on "SetCapture", "TrackMouseEvent"(not supported on 95) and super/subclass.
Posted on 2002-11-24 09:36:44 by C.Z.
I have also written a MouseOver routine which changes a window style to make it looked "pressed" instead of swapping bitmaps:

http://www.asmcommunity.net/board/index.php?topic=6142&highlight=mouseover
Posted on 2002-11-24 09:51:40 by bazik
Hello bomb01 :)

I don't think those 2 API's are needed:

- WM_MOUSEMOVE says:
The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.


From what I think: "Mmm!! This means I do NOT have to capture mouse, because I receive its coordinates when it is over my window. :) This is cool!"

And about the second one, I don't want to use it just for portability... and since there is an easy alternative, I don't wanna bother with it...

Don't you agree?? ;)

Well, I'm just trying to understand the reason of your suggestion, because maybe you didn't knew what I explained above....

Superclass and subclassing... means changing default proc and settings of predefined classes (buttons, boxes,...) for what Ive seen 'til now, right? Seems like fun.


S'ya, pal!
Posted on 2002-11-24 10:02:52 by wicr0s0ft
I have found your outlook example before! 8-)

..but it crashes when I run it... it crashes only when I point to the bar. Im using win98se. Do you know why? ... the code was there still... ;-)

Your idea (changing style instead of new bitmaps) was my fisrt one. Jsut didn't see how would get to know when change it.... :)

Ps: crash info in case you want to debug it


OUTLOOK_STYLE causou uma falha de prote??o geral
no m?dulo KERNEL32.DLL em 0167:bff73641.
Registros:
EAX=00000000 CS=0167 EIP=bff73641 EFLGS=00010246
EBX=0063fd2c SS=016f ESP=00000000 EBP=0063fcf8
ECX=00000000 DS=016f ESI=00008d50 FS=4437
EDX=00000000 ES=016f EDI=00000000 GS=0000
Bytes em CS:EIP:
5f 5e c9 c2 0c 00 52 51 33 c0 48 50 50 65 ff 32
Esvaziamento da pilha:
00ca0f9e 00700465 09f20016 00700465 00700465
f000ff54 f000ea79 f000ea21 c8000000 0ac808d2
09f2003a 09f20052 09f2006a 09f20082 09f2009a
00700465
Posted on 2002-11-24 10:31:13 by wicr0s0ft
wicr0s0ft:

Do you mean to just add
WM_MOUSEMOVE: SetCursor(hcursor);
to the window procedure?

i don't think that's good option. imo, it doesn't give good performance calling an api each time the mouse moves, when the cursor shape is already correctly set.

we had better: set the cursor shape the first time it moves in, and restore it when moves out. Windows doesn't tell you when the mouse moves out (no such msg)unless the window has captured the mouse.

TrackMouseEvent is a handy alternative, many windows programs use it for mouse sensitive elements like floating buttons and toolbars. that's why i suggested them.:)
Posted on 2002-11-25 04:20:51 by C.Z.

I have found your outlook example before! 8-)

..but it crashes when I run it... it crashes only when I point to the bar. Im using win98se. Do you know why? ... the code was there still... ;-)

Your idea (changing style instead of new bitmaps) was my fisrt one. Jsut didn't see how would get to know when change it.... :)

Ps: crash info in case you want to debug it


OUTLOOK_STYLE causou uma falha de prote??o geral
no m?dulo KERNEL32.DLL em 0167:bff73641.
Registros:
EAX=00000000 CS=0167 EIP=bff73641 EFLGS=00010246
EBX=0063fd2c SS=016f ESP=00000000 EBP=0063fcf8
ECX=00000000 DS=016f ESI=00008d50 FS=4437
EDX=00000000 ES=016f EDI=00000000 GS=0000
Bytes em CS:EIP:
5f 5e c9 c2 0c 00 52 51 33 c0 48 50 50 65 ff 32
Esvaziamento da pilha:
00ca0f9e 00700465 09f20016 00700465 00700465
f000ff54 f000ea79 f000ea21 c8000000 0ac808d2
09f2003a 09f20052 09f2006a 09f20082 09f2009a
00700465



Why dont you fix it then? :)

You need to push & pop edi...



MouseOver proc hCtl :DWORD
invoke GetWindowLong, hCtl, GWL_EXSTYLE
.if (!(eax & WS_EX_CLIENTEDGE))
push edi ; <---------------------------------------------------------
mov edi, eax
mov eax, WS_EX_CLIENTEDGE
or eax, edi
invoke SetWindowLong, hCtl, GWL_EXSTYLE, eax
invoke SetWindowPos, hCtl, 0, 0, 0, 0, 0, ; redraw window
SWP_NOSIZE or SWP_NOMOVE or \
SWP_NOZORDER or SWP_NOACTIVATE or \
SWP_FRAMECHANGED
pop edi ; <---------------------------------------------------------
.endif
ret
MouseOver endp


.... or upgrade to a real OS because crappy Win9x cares that much about register preversation ;)
Posted on 2002-11-25 04:52:41 by bazik
bomb01,

I still disagree with you, but it seems like yu missed my point.
My idea is not to change the cursor every time mouse moves... maybe I would just cehck if I gotta change or not... but my idea is to change the button's attributes when the mouse is over the button's area in my window.

API ref states:
The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MOUSEMOVE
fwKeys = wParam; // key flags
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor


So, when my procedure proccess the WM_MOUSEMOVE message, it will do a FEW calculations to know where in the window the cursor is. I don't plan to do that using APIs, since I think it is not that hard to be done... ;) ... I'll just compare the each coordinate with 4 or eight values (I have two sensitive buttons).

Further, if I want to change the mouse cursor, I would just have to check another range of value... :) ... and NO, I don't think that is bloat... did you know that all those little animations we have in windoze shell are AVI clips?? Now THAT is bloat! :-d

Got it? :)

Glad to discuss.
Posted on 2002-11-25 12:26:44 by wicr0s0ft
Oh no, bazik!

So you say that the reason it crashes on 98 is "absolved" by later OSes?? :-d ... funny. :-D
So that two lil mnes fix it?

...

About changing OS:
I have so much thigs I hate about MS-OSes above win98 that I could write a whole thread about it. I can't see the minute I get my precious win98 (1st ED) back to me, and install it again. I use to start my whole PC in 13 seconds. Not kidding :( ... now it takes at least 23 seconds. I have had much fun with 98 setings, and new versions of windoze aint fun. They are bloated and have that WEIRD "user friendly" (IMHO much hard to deal with, since its obscure) concept much more cramped inside it. :(

Im thinking about Linux, but it is becoming more and more bloat every day, trying to be a alter-ego of windoze... :**( ... that makes it hard and distant to play with it, until it comes clean...

...
Posted on 2002-11-25 13:22:41 by wicr0s0ft
>So that two lil mnes fix it?

Yes :)

>Im thinking about Linux, but it is becoming more and more bloat every day, trying to be a alter-ego of windoze... :**( ... that
>makes it hard and distant to play with it, until it comes clean...

You didnt try Gentoo yet :grin: (www.gentoo.org)
Posted on 2002-11-25 14:58:21 by bazik