ATL ActiveX全屏

参考自 http://www.cnblogs.com/leafyoung/archive/2007/10/16/926514.html

 

template <class T>
class CFullScreen
{
public:
    CFullScreen() : fullscreen_(FALSE) {}

    void SetFullScreenImpl(BOOL fullscreen)
    {
        T* pT = static_cast<T*>(this);
        HWND hWnd = pT->m_hWnd;

        if (!fullscreen)
        {
            pT->LockWindowUpdate(TRUE);

            ::SetParent(hWnd, origin_parent_);
            pT->SetWindowPlacement(&origin_placement_);

            ::SetForegroundWindow(origin_parent_);  
            ::SetFocus(origin_parent_);
            ::SetFocus(hWnd);

            pT->LockWindowUpdate(FALSE);

            pT->UpdateWindow();
        }
        else
        {
            pT->GetWindowPlacement(&origin_placement_);

            MONITORINFO monitor_info;
            monitor_info.cbSize = sizeof(monitor_info);
            GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &monitor_info);

            int nScreenWidth = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
            int nScreenHeight = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;

            origin_parent_ = ::GetParent(hWnd);
            ::SetParent(hWnd, GetDesktopWindow());


            WINDOWPLACEMENT wp = {0};
            wp.length = sizeof(WINDOWPLACEMENT);
            wp.showCmd = SW_SHOWNORMAL;
            wp.rcNormalPosition.left = 0;
            wp.rcNormalPosition.top = 0;
            wp.rcNormalPosition.right = nScreenWidth;
            wp.rcNormalPosition.bottom = nScreenHeight;


            pT->SetWindowPlacement(&wp);

            ::SetForegroundWindow(GetDesktopWindow());
            ::SetForegroundWindow(hWnd);

        }

        fullscreen_ = fullscreen;
    }

    BOOL IsFullScreen() { return fullscreen_; }

private:
    BOOL fullscreen_;

    WINDOWPLACEMENT origin_placement_;
    HWND origin_parent_;
};


使控件的子窗体来继承这个功能, 就能解决原文所说的问题

posted @ 2013-05-29 20:13  悟了  阅读(351)  评论(1编辑  收藏  举报