Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

winapi - WPF WIN32 hwndhost WM_MOUSEMOVE WM_MOUSEHOVER

I have a WPF app with a usercontrol that contains a HwndHost. The HwndHost is created as follows:

  hwndHost = CreateWindowEx(0, "static", "",
                            WS_CHILD | WS_VISIBLE,
                            0, 0,
                            hostHeight, hostWidth,
                            hwndParent.Handle,
                            (IntPtr)HOST_ID,
                            IntPtr.Zero,
                            0);

  hwndControl = CreateWindowEx(0, "Static", "",
                                WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN
                                  ,
                                0, 0,
                                hostHeight, hostWidth,
                                hwndHost,
                                (IntPtr)PICTUREBOX_ID,
                                IntPtr.Zero,
                                0);

I then hook into the message pump using HwndSourceHook and loads of messages come through.

Except the ones I want i.e. WM_MOUSEMOVE, WM_MOUSEHOVER, WM_LBUTTONDOWN and WM_LBUTTONUP

Also the OnMouseLeftButtonDown event is not fired in the WPF code on the main window or the control, I assume because windows is trapping it and throwing it away.

Anybody know how I can get these to come through, either with or without using the WIN32 window messages?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to handle WM_NCHITTEST. Until you do, it won't send you mouse messages.

// C++/CLI implementation of HwndHost.WndProc().
virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool% handled) override
{
    switch (msg)
    {
        case WM_NCHITTEST:
        {
            handled = true;
        return IntPtr(HTCLIENT);
        }
    }

    return IntPtr::Zero;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...