News:

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

Which control?

Started by Nordwind64, January 25, 2006, 09:57:24 PM

Previous topic - Next topic

Nordwind64

Hi,

I have a window with some controls. Now I want to detect, which control is under the mouse pointer. Using WM_MOUSEMOVE / GetCursorPos / WindowFromPoint seems not to be work.
Is there a solution without subclassing all the controls?

Best regards,
Nordwind64
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

gabor

Hi!

I found 2 things worthy to discuss:
1. The WM_MOUSEMOVE message gives the x,y coordinates that can be converted into a POINT structure. Why do you need the GetCursorPos function?
2. Since the controls are child windows I would try the ChildWindowFromPoint or ChildWindowFromPointEx procedures to determine the needed window handle.

I suspect that your problem could be caused by the difference between the client coordinates and the screen (absolute) coordinates.
The WM_MOUSEMOVE and the ChildWindowFromPoint uses coordinates in the client area.

Greets, Gábor

Nordwind64

Hi,

I know, Garbor. I tried this and I tried that.

    .if uMsg==WM_MOUSEMOVE

      lea ebx,rect2
     
      mov eax,lParam
      and eax,00000000000000001111111111111111b
      mov [ebx],eax
     
      mov eax,lParam
      and eax,11111111111111110000000000000000b
      sar eax,16
      mov [ebx+4],eax

      lea ebx,rect2
      mov eax,[ebx]
      mov ebx,[ebx+4]

;      PrintDec eax
;      PrintDec ebx
;      PrintText "---"

      invoke WindowFromPoint,eax,ebx
      mov erg,eax

      .if eax!=0
        invoke ScreenToClient,erg,addr rect2

        lea ebx,rect2
        mov eax,[ebx]
        mov ebx,[ebx+4]
        invoke ChildWindowFromPoint,erg,eax,ebx
        mov erg,eax
      .endif
     
      mov eax,erg
      invoke dwtoa,eax,addr unwichtig
      invoke SendMessage,editcontrol,WM_SETTEXT,0,addr unwichtig
    .endif


The big problem is, that WM_MOUSEMOVE only works, if mousecursor is over hwnd. If the cursor is over a child control, WM_MOUSEMOVE is not send...
Is there another way (without WM_TIMER!)?

Best regards,
Nordwind64 
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

MichaelW

I think you can do that with a mouse hook similar to Iczelion's Tutorial 24, but all you would need is a local hook, so you could avoid the overhead of a global hook.

eschew obfuscation

Nordwind64

Thank you MichaelW,

I think, that is what I was looking for  :U

Best regards,
Nordwind64
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

zooba

Quote from: Nordwind64 on January 25, 2006, 09:57:24 PM
I want to detect, which control is under the mouse pointer.

When?

This is an important question. If you want to have a textbox updating the current control then a mouse hook or timer is probably the best way to go. If you're drawing custom buttons (ie. highlight when the mouse is over) it's simply a matter of slotting the API calls in there.

Nordwind64

Hi,

yes, I wanted to update a textbox to build a global tooltip-control.
I got it now without mouse hook, because I've build my own WM_MOUSEMOVE via GetCursorPos and variables. Works fine.

Best regards,
Nordwind64
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink