views:

119

answers:

1

The described setup with 2nd monitor to left of primary causes WM_NCHITTEST to send negative values which is apparently not supported according to this post.

I have a custom control written in win32 that is like a Group control. It has a small clickable area. No MOUSE events are coming to my control when the window containing the custom control lies on a second monitor to the left of the primary monitor. SPY++ shows WM_NCHITTEST messages but no Mouse messages. When window is moved to primary monitor or secondary monitor is positioned to right of primary (all points are positive) then everything works fine. Below is how the WM_NCHITTEST is handled in my custom control. In general I need it to return HTTRANSPARENT so as not to obscure other controls placed inside of it. Anybody have any suggestions what funky coordinate translation I need to do and what to return in response to WM_NCHITTEST to get Mouse messages translated and sent to my control in the case where it is on a 2nd monitor placed to the left of the primary monitor?

case WM_NCHITTEST:
    {
        POINT Pt = {LOWORD(lP), HIWORD(lP)};
        int i;
        ScreenToClient (hWnd, &Pt);
        if (PtInRect (&rClickableArea, Pt))
        {
            return(DefWindowProc( hWnd, Msg, wP, lP ));
        }
    }
    lReturn = HTTRANSPARENT;
    break;
+1  A: 

You must use GET_X_LPARAM and GET_Y_LPARAM macros to extract mouse coordinates. They will correctly return negative values, unlike LOWORD et al. which return unsigned values.

POINT Pt = { GET_X_LPARAM(lP), GET_Y_LPARAM(lP) };

The rest of the code should be fine.

avakar
Awesome. I like those easy fixes! Thanks!
AlanKley