News:

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

WM_MOUSEMOVE message and Combobox

Started by Teloboy, November 17, 2010, 11:45:18 PM

Previous topic - Next topic

Teloboy

Ok, I need to detect when the mouse moves over a Static and also over a ComboBox, so I thought using the MOUSEMOVE message would be a fair enough way, but it appears not to be. Whats more, to make things confussing to me anyway)... if I put a PrintText or PrintHex in the message loop the detection of the ComboBox happens more times than not !

So I have created a little test app, just to double check it was not anything else, and I get the same results.

I presumed that it had something to do with sending messages to another window or something, so I replaced the PrintText with StdIo and that did not detect the ComboBox, so I am a little confused.

Here's the test app.

Any thoughts would be appreciated

Thanks

donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Teloboy

Thanks donkey, but I have not because (as I understand it ) the TrackMouseEvent can only be put on to one window at a time, and my protect has a number of Combo & Static controls that I need to detect the mouse over.

donkey

Yeah, you're probably right. It wouldn't work anyway as there is no WM_MOUSEENTER message (though there should be). I will have to think on this one...

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Coma

Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

Teloboy

Coma,   subclassing.... not sure how to subclass without seeming to get the message in the first place of the mouse over the combo

..... or am I missing something (and I think 'yes' may well be the answer right !)

Ghandi

Probably sounds clumsy, but couldn't you use TrackMouseEvent on the main window and then use the message to gain the mouse position within it. Use the X and Y to test whether or not the cursor is hovering over a particular control? I've seen it used for custom windows where the controls are simply painted onto the main window. It was used to determine/set the control state and appearance, which was simply 'hovered', 'not hovered' and 'pressed/clicked'.

HR,
Ghandi

donkey

Hi Coma,

A lot of subclassing here since a combobox consists of 3 windows (the static is easy enough), I would think capturing the mouse when it moved over the parent window might work but I'm still trying to work it out.

Hi Ghandi,

As I said, TrackMouseEvent has no message to indicate that the mouse has entered a windows rectangle, only that it is hovering and has left. You could just set the hover time to a very small value but since this is a global setting I wouldn't recommend it.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Teloboy

I have managed to 'bodge' it somewhat ... hope none of you guys see my code ... luk.....

Basically, I have created a hidden static behind the ComboBox which is slightly larger than the ComboBox and then with the MOUSEMOVE, if it get's into the region of the static, I can display the corresponding text etc...

Not nice, because I am using more controls etc., but it's a way out for the moment.... until inspiration strikes  :(

ToutEnMasm

subclass is the soluce
Quote
; EventProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
;
;.data
; pEventProc  dd 0
;
invoke SetWindowLongPtr,xHcontrole,GWL_WNDPROC,EventProc
mov pEventProc, eax

;Another messageloop for the control loop
EventProc proc hCtl:DWORD,uMsg:DWORD,wParam :DWORD,lParam :DWORD

   .if uMsg ==WM_MOUSEMOVE   
      ;WM_MOUSEMOVE 
      ;fwKeys = wParam;        // key flags
      ;xPos = LOWORD(lParam);  // horizontal position of cursor
      ;yPos = HIWORD(lParam);  // vertical position of cursor    
   .endif
      
   ;return to the normal control loop
   invoke CallWindowProc,pEventProc,hCtl,uMsg,wParam,lParam

   ret

EventProc endp   
You can put any messages in the loop

donkey

Yup, ToutEnMasm is right, though I am not sure that the combobox drop down will be affected by the subclassing. I would create a single subclass procedure for all windows then just relay a message to the main window procedure. That way you have only one handler no matter how many different types of controls you subclass. To do this the control itself has to hold the old window proc address...

; Subclass the control
invoke GetWindowLong,[hControl],GWL_WNDPROC
invoke SetWindowLong,[hControl],GWL_USERDATA,eax
invoke SetWindowLong,[hControl],GWL_WNDPROC,offset SubClass


; The subclassing procedure (translated to MASM)
SubClass PROC hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
cmp [uMsg],WM_MOUSEMOVE
jne DEFPROC
; Relay a message to the main Window
; might as well send lParam as well, it contains the cursor coordinates
invoke PostMessage,[hMainWindow],WM_USER,[hwnd],[lParam]
DEFPROC:
invoke GetWindowLong,[hwnd],GWL_USERDATA
invoke CallWindowProc,eax,[hwnd],[uMsg],[wParam],[lParam]
ret
SubClass endp
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Teloboy

OK, thanks, I'll have a go tomorrow... shattered now after recreating the project due to resource file corruption !!!!

oh joy...   one step forwards... countless backwards.

I'll let you guys know if it works etc.

Thanks again.

Teloboy

Donkey, your a star !!!

your Subclass worked a treat...!!

Thanks

donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable