📄 cdxcdynamiccontrolsmanager.h
字号:
// ControlPosition *AddSzControl(CWnd & ctrl, Mode modeX, Mode modeY); ControlPosition *AddSzXControl(CWnd & ctrl, Mode modeX) { return AddSzControl(ctrl,modeX,mdNone); } ControlPosition *AddSzYControl(CWnd & ctrl, Mode modeY) { return AddSzControl(ctrl,mdNone,modeY); } ControlPosition *AddSzControlEx(CWnd & ctrl, BYTE dX1pcnt, BYTE dX2pcnt, BYTE dY1pcnt, BYTE dY2pcnt) { return AddSzControlEx(ctrl,PositionSetup(dX1pcnt,dX2pcnt,dY1pcnt,dY2pcnt)); } ControlPosition *AddSzXControlEx(CWnd & ctrl, BYTE dX1pcnt, BYTE dX2pcnt) { return AddSzControlEx(ctrl,dX1pcnt,dX2pcnt,0,0); } ControlPosition *AddSzYControlEx(CWnd & ctrl, BYTE dY1pcnt, BYTE dY2pcnt) { return AddSzControlEx(ctrl,0,0,dY1pcnt,dY2pcnt); } virtual ControlPosition *AddSzControlEx(CWnd & ctrl, const PositionSetup & rSetup); // // advanced (new to V1.3) // ControlPosition *FindSzControl(CWnd & ctrl); const ControlPosition *FindSzControl(CWnd & ctrl) const; bool RemSzControl(CWnd & ctrl, bool bAutoDeleteUnusedControlPos = true); // // advanced (new to V1,4) // virtual bool Enable(bool bForce = false) { if(!bForce) { --m_iDisabledCnt; ASSERT(m_iDisabledCnt >= 0); } else m_iDisabledCnt = 0; return m_iDisabledCnt == 0; } virtual void Disable() { ++m_iDisabledCnt; } virtual bool IsDisabled() const { return m_iDisabledCnt > 0; } // // these must be called by the appropiate message handlers of the window // class you're deriving from //public: void DoInitWindow(CWnd & rWnd, Freedom fd = fdAll, bool bSizeIcon = false, const CSize * pBaseClientSize = NULL); void DoOnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); void DoOnSize(UINT nType, int cx, int cy); void DoDestroyWindow(); // // some helpers // void ReorganizeControls(bool bRedraw = true); void ReorganizeControlsAdvanced(const CRect & rectWin, CRect rectClient, bool bRedraw = true); bool StretchWindow(const CSize & szDelta) { ASSERT(IsReady()); return StretchWindow(*m_pWnd,szDelta); } bool StretchWindow(int iAddPcnt) { ASSERT(IsReady()); return StretchWindow(*m_pWnd,iAddPcnt); } CSize GetWindowSize() { ASSERT(IsReady()); return GetWindowSize(*m_pWnd); } bool RestoreWindowPosition(LPCTSTR lpszProfile, UINT restoreFlags = rflg_none) { ASSERT(IsReady()); return RestoreWindowPosition(*m_pWnd,lpszProfile,restoreFlags); } bool StoreWindowPosition(LPCTSTR lpszProfile) { ASSERT(IsReady()); return StoreWindowPosition(*m_pWnd,lpszProfile); } // // helpers; static //public: static bool StretchWindow(CWnd & rWnd, const CSize & szDelta); static bool StretchWindow(CWnd & rWnd, int iAddPcnt); static CSize GetWindowSize(CWnd & rWnd); static bool RestoreWindowPosition(CWnd & rWnd, LPCTSTR lpszProfile, UINT restoreFlags = rflg_none); static bool StoreWindowPosition(CWnd & rWnd, LPCTSTR lpszProfile); // // some virtuals //protected: virtual void OnDeleteControlPosition(ControlPosition & rWillBeDeleted) {} virtual CRect GetRealClientRect() const; // // misc //public: /* removed */ //static CBitmap & GetSizeIconBitmap(CSize * pSzBmp = NULL); static CImageList & GetSizeIconImageList(CSize * pSzBmp = NULL) { if(pSzBmp) *pSzBmp = cdxCSizeIconCtrl::M_ilImage.Size(); return cdxCSizeIconCtrl::M_ilImage; }};/* * cdxCSizeCtrl * ============ * Is now a typedef to cdxCSizeIconCtrl - see above. *//////////////////////////////////////////////////////////////////////////////// cdxCDynamicControlsManager::PositionSetup inlines//////////////////////////////////////////////////////////////////////////////* * this function transforms a control's original position (rectOriginal) into * its new rectangle by taking the the difference between the original window's * size (szDelta). */inline CRect cdxCDynamicControlsManager::PositionSetup::Transform(const CRect & rectOriginal, const CSize & szDelta) const{ CRect rectNew; rectNew.left = rectOriginal.left + (szDelta.cx * (int)m_dX1pcnt) / 100; rectNew.right = rectOriginal.right + (szDelta.cx * (int)m_dX2pcnt) / 100; rectNew.top = rectOriginal.top + (szDelta.cy * (int)m_dY1pcnt) / 100; rectNew.bottom = rectOriginal.bottom + (szDelta.cy * (int)m_dY2pcnt) / 100; return rectNew;}/////////////////////////////////////////////////////////////////////////////// cdxCDynamicControlsManager::ControlData::ControlEntry inlines//////////////////////////////////////////////////////////////////////////////* * add a control that has the same coordinates as the * control embedded in the ControlData object. * The coordinates are needed to immediately place the * control to the original control's position. */inline void cdxCDynamicControlsManager::ControlData::ControlEntry::Add(CWnd & ctrl, int x, int y, int wid, int hi){ VERIFY( m_pNext = new ControlEntry(ctrl,m_rMaster) ); m_pNext->Position(NULL,x,y,wid,hi,false);}/* * apply new position to all "ControlEntry" controls * we don't change the z-order here ! */inline void cdxCDynamicControlsManager::ControlData::ControlEntry::Position(AFX_SIZEPARENTPARAMS *lpSz, int x, int y, int wid, int hi, bool bAll){ if(::IsWindow(m_rCtrl.m_hWnd)) // those window don't need to exist :) { if (lpSz != NULL) AfxRepositionWindow(lpSz, m_rCtrl.m_hWnd, CRect(CPoint(x,y),CSize(wid,hi))); else { VERIFY( m_rCtrl.SetWindowPos(&CWnd::wndBottom,x,y,wid,hi, SWP_NOCOPYBITS|SWP_NOOWNERZORDER| SWP_NOACTIVATE|SWP_NOZORDER) ); } } if(m_pNext && bAll) m_pNext->Position(lpSz, x,y,wid,hi,true);}/////////////////////////////////////////////////////////////////////////////// cdxCDynamicControlsManager::ControlData inlines//////////////////////////////////////////////////////////////////////////////* * called by cdxCDynamicControlsManager::ReorganizeControls() if the size of the window has been changed. * repositions all controls applied to this ControlData */inline void cdxCDynamicControlsManager::ControlData::OnSize(const CSize & szDelta, AFX_SIZEPARENTPARAMS *lpSz, const CPoint *pOffset){ if(m_pCtrl) { CRect rectNew = m_posSetup(m_rectOriginal,szDelta); if(pOffset) rectNew += *pOffset; m_pCtrl->Position(lpSz, rectNew.left,rectNew.top,rectNew.Width(),rectNew.Height(),true); }}/////////////////////////////////////////////////////////////////////////////// cdxCDynamicControlsManager inlines//////////////////////////////////////////////////////////////////////////////* * add a control - we leave that work * to the embedded ControlData class */inline cdxCDynamicControlsManager::ControlPosition *cdxCDynamicControlsManager::AddSzControlEx(CWnd & ctrl, const PositionSetup & rSetup){ ASSERT(IsReady()); // don't called DoInitWindow() before ? ASSERT(rSetup.IsValid()); ControlData *si = new ControlData(*this, ctrl, rSetup); ASSERT(si != NULL); // if you don't throw exceptions :) return si;}/* * find a control's ControlPosition */inline const cdxCDynamicControlsManager::ControlPosition *cdxCDynamicControlsManager::FindSzControl(CWnd & ctrl) const{ ASSERT(::IsWindow(ctrl.m_hWnd)); // will work for exiting windows only ! for(const ControlData *si = m_pFirst; si; si = si->GetNext()) if(si->IsMember(ctrl)) return si; return NULL;}inline cdxCDynamicControlsManager::ControlPosition *cdxCDynamicControlsManager::FindSzControl(CWnd & ctrl){ ASSERT(::IsWindow(ctrl.m_hWnd)); // will work for exiting windows only ! for(ControlData *si = m_pFirst; si; si = si->GetNext()) if(si->IsMember(ctrl)) return si; return NULL;}/* * delete an entry for a control * ctrl - the control * bAutoDeleteUnusedControlPos - if true, and unused ControlPosition (no more * CWnds are bound to it) will be deleted. * Note that you can use OnDeleteControlPosition() * to find out which one will be deleted if any. * * returns true of the control has been found and deleted */inline bool cdxCDynamicControlsManager::RemSzControl(CWnd & ctrl, bool bAutoDeleteUnusedControlPos){ for(ControlData *si = m_pFirst; si; si = si->GetNext()) if(si->Rem(ctrl)) { if(!si->IsUsed() && bAutoDeleteUnusedControlPos) { OnDeleteControlPosition(*si); delete si; } return true; } return false;}/* * adding controls by my nice constants */inline cdxCDynamicControlsManager::ControlPosition *cdxCDynamicControlsManager::AddSzControl(CWnd & ctrl, Mode modeX, Mode modeY){ BYTE dX1pcnt = 0, dX2pcnt = 0, dY1pcnt = 0, dY2pcnt = 0; switch(modeX) { default : ASSERT(false); // unknown value for modeX case mdNone : break; case mdRepos : dX1pcnt = dX2pcnt = 100; break; case mdResize : dX2pcnt = 100; break; case mdRelative: dX1pcnt = dX2pcnt = 100 / 2; break; } switch(modeY) { default : ASSERT(false); // unknown value for modeY case mdNone : break; case mdRepos : dY1pcnt = dY2pcnt = 100; break; case mdResize : dY2pcnt = 100; break; case mdRelative: dY1pcnt = dY2pcnt = 100 / 2; break; } return AddSzControlEx(ctrl,dX1pcnt,dX2pcnt,dY1pcnt,dY2pcnt);}//////////////////////////////////////////////////////////////////////////////* * Reposition */inline void cdxCDynamicControlsManager::ReorganizeControls(bool bRedraw){ ASSERT(IsReady()); CRect clrect,winrect; m_pWnd->GetClientRect(clrect); m_pWnd->GetWindowRect(&winrect); if(m_bApplyScrollPosition) { if(m_pWnd->IsKindOf(RUNTIME_CLASS(CScrollView))) { clrect += ((CScrollView *)m_pWnd)->GetDeviceScrollPosition(); } else clrect += CPoint(m_pWnd->GetScrollPos(SB_HORZ),m_pWnd->GetScrollPos(SB_VERT)); } ReorganizeControlsAdvanced(winrect,clrect,bRedraw);}/* * get client rect */inline CRect cdxCDynamicControlsManager::GetRealClientRect() const{ ASSERT(IsReady()); CRect r; return r;}#endif // !defined(AFX_CDXCDYNAMICCONTROLSMANAGER_H__6517AE13_5D12_11D2_BE4C_000000000000__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -