📄 cdxcdynamicwnd.h
字号:
protected: void DoInitWindow(CWnd & rWnd, const CSize & szInitial); void DoInitWindow(CWnd & rWnd); // short-cut void DoOnDestroy(); void DoOnParentNotify(UINT message, LPARAM lParam); void DoOnTimer(UINT nIDEvent); void DoOnSize(UINT nType, int cx, int cy); void DoOnSizing(UINT fwSide, LPRECT pRect); void DoOnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); // // some advanced virtuals //protected: virtual bool DoMoveCtrl(HWND hwnd, UINT id, CRect & rectNewPos, const cdxCDynamicLayoutInfo & li); virtual void DoDestroyCtrl(HWND hwnd); virtual void OnInitialized() {} virtual void OnDestroying() {} virtual cdxCDynamicLayoutInfo *DoCreateLayoutInfo() { return new cdxCDynamicLayoutInfo(this); } // // misc utility functions //public: virtual void StartAntiFlickering(bool bIsBotRight); HWND GetSafeChildHWND(UINT nID); // // some operators //public: operator CWnd * () const { return m_pWnd; } // // private members (hidden from classview) //private: // DON'T USE DECLARE_CDX_HIDDENFUNC( cdxCDynamicWnd(const cdxCDynamicWnd & w) ) { ASSERT(false); } void DECLARE_CDX_HIDDENFUNC( operator=(const cdxCDynamicWnd & w) ) { ASSERT(false); } // helpers void DECLARE_CDX_HIDDENFUNC( _translate(Mode md, SBYTE & b1, SBYTE & b2) ); // // DYNAMIC_MAPping //public: DECLARE_CDX_HIDDENENUM( __dynEntryType ) { __end, __bytes, __modes }; DECLARE_CDX_HIDDENSTRUCT( __dynEntry ) { __dynEntryType type; UINT id; SBYTE b1,b2,b3,b4; };protected: virtual const __dynEntry * DECLARE_CDX_HIDDENFUNC( __getDynMap(const __dynEntry *pLast) ) const { return NULL; }public: static const CSize M_szNull; // for the "Config" class static const SBYTES TopLeft, TopRight, BotLeft, BotRight;};/////////////////////////////////////////////////////////////////////////////// cdxCDynamicLayoutInfo DYNAMIC MAP macros//////////////////////////////////////////////////////////////////////////////* * Macros that can be used to implement an automatic setup * for any dynamic window. * If you use these, you don't need to use AddSzControl(): */// declare map#ifndef DECLARE_DYNAMIC_MAP#define DECLARE_DYNAMIC_MAP() \protected: \ virtual const __dynEntry *__getDynMap(const __dynEntry *pLast) const; \private: \ static const __dynEntry __M_dynEntry[];#endif// begin the map and set freedom/size icon flags#ifdef _CDX_SIMPLE_DYNAMIC_MAPS#ifndef BEGIN_DYNAMIC_MAP#define BEGIN_DYNAMIC_MAP(CLASS) \ const cdxCDynamicWnd::__dynEntry *CLASS::__getDynMap(const __dynEntry *pLast) const { return __M_dynEntry; } \ const cdxCDynamicWnd::__dynEntry CLASS::__M_dynEntry[] = {#endif#else// begin a dynamic map that even takes care of maps defined for base-class versions#ifndef BEGIN_DYNAMIC_MAP#define BEGIN_DYNAMIC_MAP(CLASS,BASECLASS) \ const cdxCDynamicWnd::__dynEntry *CLASS::__getDynMap(const __dynEntry *pLast) const\ { \ if(pLast == __M_dynEntry) \ return NULL; \ return (pLast = BASECLASS::__getDynMap(pLast)) ? pLast : __M_dynEntry; \ } \ const cdxCDynamicWnd::__dynEntry CLASS::__M_dynEntry[] = {#endif#endif// end up map#ifndef END_DYNAMIC_MAP#define END_DYNAMIC_MAP() { cdxCDynamicWnd::__end } };#endif// declare operations#ifndef DYNAMIC_MAP_ENTRY_EX#define DYNAMIC_MAP_ENTRY_EX(ID,X1,Y1,X2,Y2) { cdxCDynamicWnd::__bytes, ID, X1,Y1,X2,Y2 },#define DYNAMIC_MAP_XENTRY_EX(ID,X1,X2) DYNAMIC_MAP_ENTRY_EX(ID,X1,0,X2,0)#define DYNAMIC_MAP_YENTRY_EX(ID,Y1,Y2) DYNAMIC_MAP_ENTRY_EX(ID,0,Y1,0,Y2)#define DYNAMIC_MAP_ENTRY(ID,MODEX,MODEY) { cdxCDynamicWnd::__modes, ID, cdxCDynamicWnd::##MODEX,cdxCDynamicWnd::##MODEY },#define DYNAMIC_MAP_XENTRY(ID,MODEX) DYNAMIC_MAP_XENTRY(ID,MODEX,mdNone)#define DYNAMIC_MAP_YENTRY(ID,MODEY) DYNAMIC_MAP_YENTRY(ID,mdNone,MODEY)#endif// use this ID for the default position at the head of your map#ifndef DYNAMIC_MAP_DEFAULT_ID#define DYNAMIC_MAP_DEFAULT_ID 0#endif/////////////////////////////////////////////////////////////////////////////// cdxCDynamicLayoutInfo inlines//////////////////////////////////////////////////////////////////////////////* * auto-fill in struct */inline bool cdxCDynamicLayoutInfo::operator=(cdxCDynamicWnd *pWnd){ if(!pWnd || !pWnd->IsUp()) return false; m_szCurrent = pWnd->GetCurrentClientSize(); m_szInitial = pWnd->m_szInitial; m_szDelta = m_szCurrent - m_szInitial; m_nCtrlCnt = pWnd->GetCtrlCount(); if(m_bUseScrollPos == pWnd->m_bUseScrollPos) { m_pntScrollPos.x = pWnd->Window()->GetScrollPos(SB_HORZ); m_pntScrollPos.y = pWnd->Window()->GetScrollPos(SB_VERT); } return true;}/////////////////////////////////////////////////////////////////////////////// cdxCDynamicWnd inlines//////////////////////////////////////////////////////////////////////////////* * Add a control */inline bool cdxCDynamicWnd::AddSzControl(HWND hwnd, const SBYTES & bytes, const CSize & szMin, bool bReposNow){ if(!::IsWindow(hwnd)) { // Note that this might happen if you call TRACE(_T("*** NOTE[cdxCDynamicWnd::AddSzControl(HWND,const SBYTES &,const CSize &,bool)]: Handle 0x%lx is not a valid window.\n"),(DWORD)hwnd); return false; } WINDOWPLACEMENT wpl; wpl.length = sizeof(WINDOWPLACEMENT); VERIFY( ::GetWindowPlacement(hwnd,&wpl) ); return AddSzControl(hwnd,Position(wpl.rcNormalPosition,bytes,szMin),bReposNow);}/* * Add control that behaves like another */inline bool cdxCDynamicWnd::AddSzControl(HWND hwnd, HWND hLikeThis, bool bReposNow){ if(!::IsWindow(hwnd)) { TRACE(_T("*** NOTE[cdxCDynamicWnd::AddSzControl(HWND,HWND,bool)]: Handle 0x%lx is not a valid window.\n"),(DWORD)hwnd); return false; } Position pos; if(!m_Map.Lookup(hLikeThis,pos)) { TRACE(_T("*** NOTE[cdxCDynamicWnd::AddSzControl(HWND,HWND,bool)]: For the 'hLikeThis' handle 0x%lx there hasn't been made an entry for yet.\n"),(DWORD)hLikeThis); return false; } return AddSzControl(hwnd,pos);}/* * old */inline bool cdxCDynamicWnd::AddSzControl(HWND hwnd, Mode mdX, Mode mdY, const CSize & szMin, bool bReposNow){ SBYTES b; _translate(mdX,b[X1],b[X2]); _translate(mdY,b[Y1],b[Y2]); return AddSzControl(hwnd,b,szMin,bReposNow);}/* * old */inline bool cdxCDynamicWnd::AddSzControl(HWND hwnd, SBYTE x1, SBYTE y1, SBYTE x2, SBYTE y2, const CSize & szMin, bool bReposNow){ SBYTES b; b[X1] = x1, b[X2] = x2, b[Y1] = y1, b[Y2] = y2; return AddSzControl(hwnd,b,szMin,bReposNow);}//////////////////////////////////////////////////////////////////////////////* * short-cut */inline void cdxCDynamicWnd::AllControls(Mode mdX, Mode mdY, bool bOverwrite, bool bReposNow){ SBYTES b; _translate(mdX,b[X1],b[X2]); _translate(mdY,b[Y1],b[Y2]); AllControls(b,bOverwrite,bReposNow);}/* * short-cut */inline void cdxCDynamicWnd::AllControls(SBYTE x1, SBYTE y1, SBYTE x2, SBYTE y2, bool bOverwrite, bool bReposNow){ SBYTES b; b[X1] = x1, b[X2] = x2, b[Y1] = y1, b[Y2] = y2; AllControls(b,bOverwrite,bReposNow);}//////////////////////////////////////////////////////////////////////////////* * get size of current client area */inline CSize cdxCDynamicWnd::GetCurrentClientSize() const{ if(!IsWindow()) { ASSERT(false); return M_szNull; } CRect rect; m_pWnd->GetClientRect(rect); return rect.Size();}/* * get difference between window and client size */inline CSize cdxCDynamicWnd::GetBorderSize() const{ if(!IsUp()) { ASSERT(false); return M_szNull; } CRect r1,r2; m_pWnd->GetWindowRect(r1); m_pWnd->GetClientRect(r2); return r1.Size() - r2.Size();}//////////////////////////////////////////////////////////////////////////////* * translates a "mode" into percentage */inline void cdxCDynamicWnd::_translate(Mode md, SBYTE & b1, SBYTE & b2){ switch(md) { default : ASSERT(false); case mdNone : b1 = 0; b2 = 0; break; case mdResize : b1 = 0; b2 = 100; break; case mdRepos : b1 = 100; b2 = 100; break; case mdRelative : b1 = 50; b2 = 50; break; }}/* * gets HWND of a child given by ID */inline HWND cdxCDynamicWnd::GetSafeChildHWND(UINT nID){ if(!IsWindow()) { ASSERT(false); return 0; } HWND h = ::GetDlgItem(m_pWnd->m_hWnd,nID); ASSERT(h!=0); return h;} #pragma warning(default: 4100)#pragma warning(default: 4706)#endif // !defined(AFX_CDXCDYNAMICWND_H__1FEFDD69_5C1C_11D3_800D_000000000000__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -