参考自 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_; };
使控件的子窗体来继承这个功能, 就能解决原文所说的问题