Dynamic interface easily!

xiaoxiao2021-03-06  99

Perhaps we will often have such a need, that is, when changing the main window, you also want to change some of the child controls, of course, if the number is less or the hierarchy is not complicated, then several getWindowRect, MoveWindow positioning can solve The problem, but if you want to handle a large number of controls, that is, a control group changes, or, it is more troublesome when it belongs to a different level (ie, multiple parent-dependent relationships). The above work: The interface function provided by CLAYOUTBASE has Void AddwinItem (CWND * INPARENTWND = NULL); / INPARENTWND is empty when the default main window pointer // addwinitem sequence is related, should be registered first The parent one-level window, then in the registered sub-level window //, the back refresh will first brush the new sub-window, then brush the new parent window, do not achieve a good change effect void RemovewinItem (CWND * inwinitem); // Logout Window Sub-control BOOL REFRESHALLITEM (); // is triggered by the WM_SIZE, which is responsible for refreshing all registered controls under the change window. Structure Struct WinItemInfo {CWND * m_parentWnd; CWND * m_Wnd; Float Xrate; // Left upper corner X coordinate and total interface width ratio float yRate; // Left upper corner point y coordinates and total interface heights FLOAT HRATE; // Element height and total interface height ratio float wrate; // element width The ratio of the total interface width} * m_inwinitem; storage sub-window queue uses COBJECTLIST M_WINGROUP; where cobjectList can do the following simple features of the subclass of CPTRARRAY INT GetIndex (Void * InpointER); int Add (void * Inpoint); int Add (Void * Inpointer, Int InIndex); Void Remove (Void * Inpoc);

void * GetPrevious (void * inPointer); void * GetNext (void * inPointer); Next is described the details of the interface functions void CLayoutBase :: AddWinItem (CWnd * inWinItem, CWnd * inParentWnd) {m_inWinItem = new WinItemInfo; if ( inParentWnd == NULL) m_inWinItem-> m_ParentWnd = :: AfxGetMainWnd (); else m_inWinItem-> m_ParentWnd = inParentWnd; RECT m_ItemRect; m_inWinItem-> m_Wnd = inWinItem; m_inWinItem-> m_ParentWnd-> GetWindowRect (& m_MainRect); :: GetWindowRect (m_inWinItem -> m_Wnd-> GetSafeHwnd (), & m_ItemRect); m_inWinItem-> m_ParentWnd-> ScreenToClient (& m_ItemRect); m_inWinItem-> Xrate = (float) (m_ItemRect.left) / (float) (m_MainRect.right-m_MainRect.left); m_inwinitem-> yRate = (m_itemRect.top) / (float) (m_mainRect.bottom-m_mainRect.top); m_inwinitem-> hRATE = (m_itemrect.bottom-m_itemRect.top) / (float) (m_mainRect) .bottom-m_MainRect.top); m_inWinItem-> Wrate = (float) (m_ItemRect.right-m_ItemRect.left) / (float) (m_MainRect.right-m_MainRect.left); m_WinGroup.Add (m_inWinItem);} void CLayoutBase: : RemovewinItem (CWND * Inwinite) m) {m_wingroup.remove (m_inwinitem);} Bool CLAYOUTBASE :: RefreshallItem () {for (int i = 0; i <= m_wingroup.getsize () - 1; i ) {WinItemInfo * Receiver = (WinItemInfo *) M_WINGROUP.GETAT (I); if (receiver) {receiver-> m_parentWnd-> getWindowRect (& M_MAINRECT); // Mobile Background Size :: MoveWindow (Receiver-> M_Wnd-> GetsafeHWnd (), (int) ((m_mainRect.right) -m_mainRect.Left) * Receiver-> xrate, (int) ((m_mainRect.bottom -m_mainRect.top) * Receiver-> yRate), (INT) ((m_mainRect.right -m_mainRect.Left) * Receiver-> WRATE ), (Int) (m_mainRect.bottom -m_mainRect.top) * Receiver-> hRate), true);

转载请注明原文地址:https://www.9cbs.com/read-104521.html

New Post(0)