現在很多視頻共用網站如馬鈴薯等都使用flash控制項作為播放器介面,而利用flash實現全屏非常簡單,只要把fullscreen屬性設定為true即可,其他的播放器如mediaplayer等都有類似實現全屏效果的屬性,但是怎麼在自訂的ActiveX控制項實現這種效果呢?基本的實現其實比較簡單,網上也有不少例子,不過大都有bug。下面是我修改得到的一個實現,效果還算不錯,原理比較簡單,就不廢話了。
if (m_bFullScreen)
{
LockWindowUpdate(TRUE);
::SetParent(m_hWnd, m_OldWndParent);
SetWindowPlacement(&m_OldWndPlacement);
::SetForegroundWindow(m_OldWndParent);
::SetFocus(m_OldWndParent);
::SetFocus(m_hWnd);
LockWindowUpdate(FALSE);
}
else
{
GetWindowPlacement(&m_OldWndPlacement);
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
m_OldWndParent = ::GetParent(m_hWnd);
::SetParent(m_hWnd, GetDesktopWindow());
WINDOWPLACEMENT wp1;
ZeroMemory(&wp1, sizeof(WINDOWPLACEMENT));
wp1.length = sizeof(WINDOWPLACEMENT);
wp1.showCmd = SW_SHOWNORMAL;
wp1.rcNormalPosition.left = 0;
wp1.rcNormalPosition.top = 0;
wp1.rcNormalPosition.right = nScreenWidth;
wp1.rcNormalPosition.bottom = nScreenHeight;
SetWindowPlacement(&wp1);
::SetForegroundWindow(GetDesktopWindow());
::SetForegroundWindow(m_hWnd);
}
m_bFullScreen = !m_bFullScreen;
上面代碼糾正了網上能找到的代碼中一個比較明顯的焦點切換的問題,純粹是我多次實驗的結果,不要問我為什麼這麼寫。
當然,這段代碼也是有問題的,而且相當奇怪,在"ActiveX Control Test Container"中運行一切正常,但是一旦把這個控制項嵌入的網頁後,全屏,切回,改變IE視窗大小,再試圖全屏就不會成功了,而是只有左上方有顯示,結果比較詭異:
沒有什麼頭緒,如果有人知道的話,賜教^_^