Probs With Child & Parent Mouse

Hi,
What i am trying to do is find out if the mouse moves over my button this is my code which is in my WM_MOUSEMOVE event:

case WM_MOUSEMOVE:
{
RECT mrc;
int x, y;
BOOL xin, yin = FALSE;
x = LOWORD(lParam);
y = HIWORD(lParam);

mrc.left = 10;
mrc.top = 10;
mrc.right = 300;
mrc.bottom = 50;

if(x <= mrc.right && x >= mrc.left)
{
xin = TRUE;
}

if(y <= mrc.bottom && y >= mrc.top)
{
yin = TRUE;
}

if(xin == TRUE && yin == TRUE)
{
MessageBox(hWnd, "Mouse Moved In Rect", "Mouse In Rect", MB_ICONINFORMATION);
}
}

Ok now in theroy i thought this would work and in practice it kinda does heres the problem:

If i run that program without placing the button and the mouse moves within
the rectangle there (10,10,300,50), then i get the message. And that is what i want but, as soon as i place the button in in the exact position of that rectangle
10,10,
300, 50
And the mouse moves over it i dont get the message.
Now i think this dosnt work becasue that message is only proccessed on the client and ignoring the child window how do i get this to work?

Thanks
TNT


http://www.plactech.8k.com

Comments

  • : Hi,
    : What i am trying to do is find out if the mouse moves over my button this is my code which is in my WM_MOUSEMOVE event:
    :
    : case WM_MOUSEMOVE:
    : {
    : RECT mrc;
    : int x, y;
    : BOOL xin, yin = FALSE;
    : x = LOWORD(lParam);
    : y = HIWORD(lParam);
    :
    : mrc.left = 10;
    : mrc.top = 10;
    : mrc.right = 300;
    : mrc.bottom = 50;
    :
    : if(x <= mrc.right && x >= mrc.left)
    : {
    : xin = TRUE;
    : }
    :
    : if(y <= mrc.bottom && y >= mrc.top)
    : {
    : yin = TRUE;
    : }
    :
    : if(xin == TRUE && yin == TRUE)
    : {
    : MessageBox(hWnd, "Mouse Moved In Rect", "Mouse In Rect", MB_ICONINFORMATION);
    : }
    : }
    :
    : Ok now in theroy i thought this would work and in practice it kinda does heres the problem:
    :
    : If i run that program without placing the button and the mouse moves within
    : the rectangle there (10,10,300,50), then i get the message. And that is what i want but, as soon as i place the button in in the exact position of that rectangle
    : 10,10,
    : 300, 50
    : And the mouse moves over it i dont get the message.
    : Now i think this dosnt work becasue that message is only proccessed on the client and ignoring the child window how do i get this to work?
    :
    : Thanks
    : TNT
    :
    : http://www.plactech.8k.com
    :

    Tough task, my friend...
    The Windows designed to send messages to the HWND where the mouse hovering right now, unless you use 'SetCapture()'. But if you do that then you, probably, will not be able to click on your button, because mouse messages will be sent to the parent...

    You can do it by the subclassing - intercept WM_MOUSEMOVE for a button and act on it as you wish...

    Subclassing link:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/winprocs_5cdj.asp



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion