用c#写windows程序的时候,我们可以注意到里面有个很有意思并且很有用的东东“anchor”.它可以被指定为“top, bottom, left, right”的组合.这个东西可以简化我们的界面上的很多工作,很多时候都可以不用对布局写代码.以下是我在vc6里给出的模拟解决方案:
#include <map> 【程序编程相关:MFC中PretranslateMess】#pragma warning(disable: 4786) 【推荐阅读:工作线程中调用UI线程创建的窗口的Upd】 ar_none = 0, 【扩展信息:在VC中做一个选择文件夹的对话框 】typedef enum anchor{ 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<cwnd*, uint> anchormap;typedef std::map<uint, uint> 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 (iter != anchors.end()) anchors.erase(iter);}void basedlg::registeranchorbyid(uint itemid, uint anchor /* = ar_none */)
{ anchorsbyid[itemid] = anchor;}... 下一页