VC6 anchor anchor

xiaoxiao2021-03-06  43

This article is a spanzhang original, its blog address is: http://blog.9cbs.net/spanzhang. Please indicate the source, thank you! ! When writing a Windows program with C #, we can notice that there is a very interesting and useful Dongdong "Anchor". It can be designated as a combination of "TOP, BOTTOM, LEFT, RIGHT". This thing can simplify a lot of work on our interface, and you can write code for layout. The following is an analog solution I have given in VC6: #pragma Warning (Disable: 4786) #include typedef enum Anchor {ar_none = 0, ar_left = 1, ar_top = 2, ar_right = 4, ar_bottom = 8, AR_FILL = AR_LEFT | AR_TOP | AR_RIGHT | AR_BOTTOM, AR_LEFTTOP = AR_LEFT | AR_TOP, AR_RIGHTTOP = AR_RIGHT | AR_TOP, AR_LEFTBOTTOM = AR_LEFT | AR_BOTTOM, AR_RIGHTBOTTOM = AR_RIGHT | AR_BOTTOM} anchor; typedef std :: map anchorMap; typedef Std :: Map anchormapbyid ;. . . . . . void baseDlg :: registerAnchor (CWnd * child, UINT anchor / * = AR_NONE * /) {anchors [child] = anchor;} void baseDlg :: unRegisterAnchor (CWnd * child) {anchorMap :: iterator iter = anchors.find (child ); If (ore! = Anchors.end ()) Anchors.ed (iter);

Void Basedlg :: Registeranchorbyid (uint itemid, uint anchor / * = ar_none * /) {anchorsbyid [itemid] = anchor;

void baseDlg :: unRegisterAnchorById (UINT itemId) {anchorMapById :: iterator iter = anchorsById.find (itemId); if (! iter = anchorsById.end ()) anchorsById.erase (iter);} void baseDlg :: OnSize (UINT nType , int CX, int CY) {cdialog :: Onsize (NTYPE, CX, CY);

If (! iswindowvisible ()) return; crect RTClientnew; getClientRect (& RTCLIENTNEW); int dx = rtclientnew.right - OldClient.right; int Dy = rtclientnew.bottom - OldClient.bottom;

IF (RTClientnew.width () <2 || RTClientnew.height () <2) Return;

For (Anchormap :: item.begin (); it! = Anchors.end (); iter) {cwnd * child = i = = = = i (== null ||! iswindow (child- > m_hwnd)) Continue; uint anchor = t = >-; child-> getwindowRect (& RTORIGN); ScreenToClient (& RTORIN);

Static CRECT RTNEW; RTNEW = RTORIGN; if (Anchor & Ar_left) {r rw.left = r r..f;} else {r rW.LEFT = DX / 2;

IF (Anchor & Ar_top) {RTNEW.TOP = RTORIGN.TOP;} else {r rW.top = DY / 2;

IF (Anchor & Ar_right) {r; (! (! (! (! (anchor & ar_left)) RTNEW.LEFT = rRIGN.LEFT DX;} else {r rww (}) = DX / 2; if (Anchor & Ar_left Rtnew.right = RTNew.LEFT RTORIGN.WIDTH ();

IF (Anchor & Ar_bottom) {RTNEW.BOTTOM = (DY); if (! (Anchor & Ar_top)) RTNew.top = r riin;}} else {r}} Else {RTNEW.BOTTOM = DY / 2; IF (Anchor & Ar_top) rtnew.bottom = rtnew.top rtORIGN.HEIGHT ();

Child-> MoveWindow (& RTNEW);

for (anchorMapById :: iterator iterById = anchorsById.begin (); iterById = anchorsById.end ();! iterById) {CWnd * child = GetDlgItem (iterById-> first);! if (child == NULL || IsWindow (child-> m_hwnd))))

Uint Anchor = neyId-> second; static create rtRect; Child-> getWindowRect (& RTORIGN); ScreenToClient (& RTORIGN);

Static CRECT RTNEW; RTNEW = RTORIGN; if (Anchor & Ar_left) {r rw.left = r r..f;} else {r rW.LEFT = DX / 2;

IF (Anchor & Ar_top) {rTNew.top = RTORIGN.TOP;} else {RTNew.top = DY / 2;} if (anchor & ar_right) {r rww.. = DX; if (! (! (! (! (! & ar_left) Rtnew.LEFT = RTORIGN.LEFT DX;} else {RTNew.right = DX / 2; if (anchor & ar_left) rlew.right = rtnew.LTNEW.Right = RTNew.LEFT RTORIGN.WIDTH ();}

IF (Anchor & Ar_bottom) {RTNEW.BOTTOM = (DY); if (! (Anchor & Ar_top)) RTNew.top = r riin;}} else {r}} Else {RTNEW.BOTTOM = DY / 2; IF (Anchor & Ar_top) rtnew.bottom = rtnew.top rtORIGN.HEIGHT ();

Child-> MoveWindow (& RTNEW);

OldClient = RTClientNew;

INVALIDATE ();

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

New Post(0)