News:

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

WM_MOUSEMOVE message in static control?

Started by RHL, April 17, 2012, 01:14:55 AM

Previous topic - Next topic

RHL

Hello guys :)
how to capture a WM_MOUSEMOVE but for a static control?
I try so (WNDPROC):


.elseif eax==WM_CREATE
invoke CreateWindowEx,NULL,addr myclass,addr namet,WS_VISIBLE or WS_CHILD or SS_NOTIFY, \
0h,0h,50h,50h,hWnd,NULL,hInstance,NULL
mov handlestatic,eax

.elseif eax==WM_MOUSEMOVE
mov edx,hWnd
.if edx==hanldestatic    ; handle to static control
                      ....
.endif
mov eax,NULL
ret


but, it cannot work :| why guys ?

dedndave

addr myclass
i hope that points to a string that looks like this   :P
myclass db 'Static',0

the SS_NOTIFY flag probably isn't going to help
it only affects certain messages, and WM_MOUSEMOVE isn't one of them

WM_MOUSEMOVE is sent to the window that contains the cursor, unless the mouse is captured
so - the WndProc for the static control receives that message

other than that - we need to see more code
it is easier if you post an example program with the problem code in it

MichaelW

Per the Microsoft documentation:
Quote
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.

So to receive WM_MOUSEMOVE for the static control you can subclass the static control and handle WM_MOUSEMOVE in the subclass procedure.
eschew obfuscation

dedndave

i think he already has it subclassed - so that's the way to go
otherwise, he could capture the mouse - i never liked doing that - it seems messy   :P

RHL

oh yeah im sorry , my code ( modified template ):
I want hide the static control when it is in control area


.386
.model flat,stdcall
option casemap:none

include    \masm32\include\masm32rt.inc
WinMain proto :DWORD,:DWORD


.data
    ClassName db "mypaint",0
    AppName  db "paint program",0

myclass db "Static",0
sname db "statictohide",0
hstatic dd 0


.data?
    hInstance HINSTANCE ?

.code

start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke WinMain, hInstance,NULL
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_BTNFACE+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax

invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL,addr myclass,addr sname, WS_VISIBLE or WS_CHILD or SS_NOTIFY, \
0h,0h,50h,50h,hWnd,NULL,hInstance,NULL

mov hstatic,eax ; save hanlde static control

;.ELSEIF uMsg==WM_MESSAGE? ;when the cursor is moved in static control area
; i want hide the static control
;invoke ShowWindow,hstatic,NULL


.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp


end start



MichaelW, you mean something like this: ( but I cannot assembler,I do not know bcz... lol  )

.386
.model flat,stdcall
option casemap:none

include    \masm32\include\masm32rt.inc

myWNDPROC proto :HWND,:UINT,:WPARAM,:LPARAM
WinMain proto :DWORD,:DWORD

.data
    ClassName db "mypaint",0
    AppName  db "paint program",0

myclass db "Static",0
sname db "statictohide",0
hstatic dd 0

mysubclass dd 0
.data?
    hInstance HINSTANCE ?

.code

start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke WinMain, hInstance,NULL
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_BTNFACE+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax

invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM


.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
invoke SetWindowLong,mysubclass,GWL_WNDPROC,myWNDPROC
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL,addr myclass,addr sname,SS_BITMAP or WS_VISIBLE or WS_CHILD or SS_NOTIFY, \
0h,0h,50h,50h,hWnd,NULL,hInstance,NULL

mov hstatic,eax ; save hanlde static control

invoke SetWindowLong,hstatic,GWL_WNDPROC,myWNDPROC
mov mysubclass,eax

;.ELSEIF uMsg==WM_MESSAGE? ;when the cursor is moved in static control area
; i want hide the static control
;invoke ShowWindow,hstatic,NULL


.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp


end start


myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_MOUSEMOVE
invoke ShowWindow,hWnd,SW_HIDE
.endif
ret
myWNDPROC endp




RHL

hey guys, I could  :bg

.386
.model flat,stdcall
option casemap:none

include    \masm32\include\masm32rt.inc

myWNDPROC proto :HWND,:UINT,:WPARAM,:LPARAM
WinMain proto :DWORD,:DWORD

.data
    ClassName db "mypaint",0
    AppName  db "paint program",0

myclass db "Static",0
sname db "statictohide",0
hstatic dd 0

mysubclass dd 0
.data?
    hInstance HINSTANCE ?

.code

start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke WinMain, hInstance,NULL
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_BTNFACE+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax

invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov     eax,msg.wParam
ret
WinMain endp

myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_MOUSEMOVE
invoke ShowWindow,hWnd,SW_HIDE
xor eax,eax
ret

.else
invoke CallWindowProc,mysubclass,hWnd,uMsg,wParam,lParam
ret
.endif
myWNDPROC endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM


.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
invoke SetWindowLong,mysubclass,GWL_WNDPROC,myWNDPROC
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL,addr myclass,addr sname,WS_VISIBLE or WS_CHILD or SS_NOTIFY, \
0h,0h,50h,50h,hWnd,NULL,hInstance,NULL

mov hstatic,eax ; save hanlde static control

invoke SetWindowLong,hstatic,GWL_WNDPROC,myWNDPROC
mov mysubclass,eax

;.ELSEIF uMsg==WM_MESSAGE? ;when the cursor is moved in static control area
; i want hide the static control
;invoke ShowWindow,hstatic,NULL
xor eax,eax
ret
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp


end start



dedndave

myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

        .if uMsg==WM_MOUSEMOVE
            invoke  ShowWindow,hWnd,SW_HIDE
        .endif
        invoke  CallWindowProc,mysubclass,hWnd,uMsg,wParam,lParam
        ret

myWNDPROC endp

dedndave

in this case, it probably won't make much difference if the static control sees the WM_MOUSEMOVE message or not
but - the other messages that you do not handle need to go to the original WndProc for the static

now - you have to figure out how to unhide it   :P
you may want to use TrackMouseEvent
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646265%28v=vs.85%29.aspx

RHL

yeah! lol, i thinking do it with handle of main windows, capturing the WM_MOUSEMOVE but, now that u say.. :D
i try :/


myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL LEAVEAREA:TRACKMOUSEEVENT

.if uMsg==WM_MOUSEMOVE
invoke ShowWindow,hWnd,SW_HIDE

mov edx,hWnd
mov LEAVEAREA.cbSize,sizeof TRACKMOUSEEVENT
mov LEAVEAREA.dwFlags,TME_NONCLIENT
mov LEAVEAREA.hwndTrack,edx
mov LEAVEAREA.dwHoverTime,HOVER_DEFAULT
invoke TrackMouseEvent,addr LEAVEAREA
xor eax,eax
ret

.elseif uMsg==WM_MOUSELEAVE
invoke ShowWindow,hWnd,SW_SHOW
xor eax,eax
ret
.else
invoke CallWindowProc,mysubclass,hWnd,uMsg,wParam,lParam
ret
.endif
myWNDPROC endp

RHL

also, this, i would have do it ( subclassed the constrols ) with all controls?...
make a proc per each control? :S :P

dedndave

code looks pretty good   :U

you may be able to use the same WndProc for all of them
if all you want to do is show and hide them

to do the subclassing - make a loop   :P

RHL

Quote from: dedndave on April 17, 2012, 03:44:39 AM
code looks pretty good   :U

you may be able to use the same WndProc for all of them
if all you want to do is show and hide them

to do the subclassing - make a loop   :P

perfect then...
thanks u dave, MichaelW  :bg

RHL

fixed:

myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL LEAVEAREA:TRACKMOUSEEVENT

.if uMsg==WM_MOUSEMOVE
invoke ShowWindow,hWnd,SW_HIDE

mov edx,hWnd
mov LEAVEAREA.cbSize,sizeof(TRACKMOUSEEVENT)
mov LEAVEAREA.dwFlags,TME_HOVER or TME_LEAVE
mov LEAVEAREA.dwHoverTime,1000
mov LEAVEAREA.hwndTrack,edx
invoke TrackMouseEvent,addr LEAVEAREA
xor eax,eax
ret

.elseif uMsg==WM_MOUSELEAVE
invoke ShowWindow,hWnd,SW_SHOW
xor eax,eax
ret
.else
invoke CallWindowProc,mysubclass,hWnd,uMsg,wParam,lParam
ret
.endif
myWNDPROC endp



verifing each second  :bg

dedndave

myWNDPROC proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

        LOCAL     LEAVEAREA:TRACKMOUSEEVENT

        mov     eax,uMsg
        .if eax==WM_MOUSEMOVE
            invoke  ShowWindow,hWnd,SW_HIDE
        .elseif eax==WM_MOUSELEAVE
            invoke  ShowWindow,hWnd,SW_SHOW
        .elseif eax==WM_CREATE
            mov     edx,hWnd
            mov     LEAVEAREA.cbSize,sizeof(TRACKMOUSEEVENT)
            mov     LEAVEAREA.dwFlags,TME_HOVER or TME_LEAVE
            mov     LEAVEAREA.dwHoverTime,1000
            mov     LEAVEAREA.hwndTrack,edx
            invoke  TrackMouseEvent,addr LEAVEAREA
        .endif
        invoke  CallWindowProc,mysubclass,hWnd,uMsg,wParam,lParam
        ret

myWNDPROC endp

RHL

right!!! the code is executed each time in WM_MOUSEMOVE message! :S
dave, but your code not work me, is not redisplay me the static control :P

EDIT: aparently, the WM_CREATE message, never is executed :P