Qt呼叫vlc的sdk時播放視窗不能響應滑鼠事件
最近在用vlc的sdk時發現Vlc在Qt中以sdk方式呼叫時,會出現播放的控制元件滑鼠事件失效。解決的辦法:
// 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
這是參考自:https://forum.videolan.org/viewtopic.php?f=32&t=92568#
在Qt中的具體程式如下:
在標頭檔案中:
Private:
QTimer *timer; //定義定時器
HWND parentwnd; //準備視窗的控制代碼
Private slots:
void timerproc(); //定義定時器的槽函式
在cpp中:
parentwnd=(HWND)this->winId(); //獲取父視窗控制代碼
timer=new QTimer
connect(timer,SIGNAL(timeout()),this,SLOT(timerproc()));
然後在視訊開啟後呼叫timer:timer->start();
void frmMain::timerproc()
{
EnumChildWindows(parentwnd, EnumerateVLC, NULL);
}
BOOL CALLBACK EnumerateVLC(HWND hWndvlc, LPARAM lParam) {
EnableWindow(hWndvlc, FALSE);
// And kill timer, i only need get this handle one time.
timer->stop();
return TRUE;
}