关闭

qt调用vlc响应windows消息

582人阅读 评论(0) 收藏 举报
分类:

调用vlc的时候,vlc将会托管所有鼠标消息,键盘消息(因为vlc内置一个dvd menu功能,将会使用到这些消息),然而我们便不能定制自己的行为了,比如本人需要获取鼠标点击的坐标。
查询资料发现有5种解决方案。如下
1.全局hook,都说能成功。没有尝试过。
2.在事件到达vlc部件之前拦截鼠标消息,按照windows消息传递机制,外部消息是由父到子(顶层窗口,子窗口,部件……),可以在父部件上面设置时间过滤器,取消到子部件事件分发
3.libvlc_video_set_mouse_input(,false);禁用鼠标事件(视频渲染窗口不处理鼠标消息),google上面查询到事件到达视频窗口后会直接传递到父窗口,本人曾经测试成功,后来不知道什么原因cursor直接被吃掉了。(键盘有对应的 libvlc_video_set_key_input)
4.编译vlc源码,收到消息后转发。本人测试成功,但是自己编译的vlc几乎比官方大一半,而且稳定性相对较弱。
5.调用windows API,禁用掉vlc事件处理窗口,这样事件不能够到达vlc。和第二条原理类似。本人最终采用这条方案。
注:vlc接收到传入的窗口句柄后,会派生两个窗口,一个用于渲染视频,一个时间处理
引用自:https://forum.videolan.org/viewtopic.php?f=32&t=92568#
Ok, vlc creates two child windows into window you pass in the libvlc_media_player_set_hwnd function every time you play a video. One of these windows is maked to get mouse events, and the other window is used to output the video.

Windows schema :
1 MyWindow
2 -VlcEnvetWindow
3 –VlcOutputWindow

You need get handle of VlcEventWindow. To get these handle i use a timer when video starts to play and into these timer i use EnumChildWindows passing in the hWnd MyWindow to search the inmediate child. I use a timer because vlc windows take some time to be created.

CODE: SELECT ALL
// First step is start a timer when you play a video,

// Second step : in the timer function i call :
EnumChildWindows(MyWindow_HWND, EnumerateVLC, NULL);

// Third step : if EnumerateVlc get some child window these window is the VlcEventWindow, and need disable it, to reach mouse events on MyWindow
BOOL CALLBACK EnumerateVLC(HWND hWndvlc, LPARAM lParam) {
EnableWindow(hWndvlc, FALSE);
// And kill timer, i only need get this handle one time.
return TRUE;
}

// When EnumerateVLC is called all mouse events are redirected to MyWindow

And remember, when you stop/finish the video vlcwindows are destroyed, and you need to get new handle every time after this ocours on your play function.

Another thing is, when you pause the video, vlcwindows are not destroyed, and its not necesary get VlcEventWindow handle again.

Sorry for my poor english again, and Good luck.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20348次
    • 积分:554
    • 等级:
    • 排名:千里之外
    • 原创:35篇
    • 转载:9篇
    • 译文:0篇
    • 评论:0条