WPF mouse events update performance

I have a 3D rendering application using WPF for UI. The rendering itself is done in native code, but the interaction is from WPF.

Now, I've seen that the mouse events from WPF are fired at extremely irregular intervals, and in some cases I never get any events at all. This seems to be tied to how much cpu the application is using.

By using low-level Win32 GetCursorPos and similar methods I can get better response, but this messes with the WPF UI elements interaction.

Is there a way to control the priority of the WPF message handling loop, or by other means ensure that I get the mouse events I need?

Alternatively, could I make a low-level mouse handler using Win32 calls that inject events into WPF somehow?


I ended up with flushing the windows message queue from the native rendering layer, once per frame. Basically I call the following native code once per frame, before rendering:

    MSG msg;
    while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

This solved my problem as I now get all the mouse events that were previously dropped.

链接地址: http://www.djcxy.com/p/39548.html

上一篇: WPF CallMethodAction在Drop,DragOver和DragEnter事件中不起作用

下一篇: WPF鼠标事件更新性能