[ATL/ActiveX]全螢幕顯示ActiveX控制項

來源:互聯網
上載者:User
現在很多視頻共用網站如馬鈴薯等都使用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視窗大小,再試圖全屏就不會成功了,而是只有左上方有顯示,結果比較詭異:

沒有什麼頭緒,如果有人知道的話,賜教^_^

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.