转的,vc保持对话框布局的方法.

 

#define FIX_LAYOUT_DATA int  m_ow, m_oh;  std::map<HWND, CRect> m_OriginLayout;

 

#define FIX_LAYOUT_INIT { \

    m_OriginLayout.clear();\

    CRect rect;\

    GetClientRect( rect);\

    m_ow = rect.Width();\

    m_oh = rect.Height();\

    HWND item = NULL;\

    RECT r;\

    while( NULL != (item = ::FindWindowEx(GetSafeHwnd(), item, NULL, NULL) ) )\

    {\

       if (!::GetWindowRect(item, &r))\

           continue;\

       ScreenToClient(&r);\

       m_OriginLayout[item] = r;\

    }\

}

 

#define FIX_LAYOUT_SIZE {\

    if (m_ow == 0)\

       m_ow = cx;\

    if(m_oh == 0)\

       m_oh = cy;\

    float rw = (float)cx/ m_ow;\

    float rh = (float)cy/ m_oh;\

    HWND item = NULL;\

    CRect r;\

    while( NULL != (item = ::FindWindowEx(GetSafeHwnd(), item, NULL, NULL) ) )\

    {\

       if (m_OriginLayout.find(item) == m_OriginLayout.end())\

           continue;\

       r = m_OriginLayout[item];\

       r.left *= rw;\

       r.right    *= rw;\

       r.top  *= rh;\

       r.bottom*= rh;\

       ::MoveWindow(item, r.left, r.top, r.right - r.left, r.bottom - r.top, true);\

    }\

}

 


 FIX_LAYOUT_DATA宏,定义保存布局信息的成员变量;

 FIX_LAYOUT_INIT宏,获取窗口中当前的布局信息;

 FIX_LAYOUT_SIZE宏,在窗口大小发生变化时,调整各子窗口的位置和大小。

使用方法:

 在你的窗口定义类中加入FIX_LAYOUT_DATA宏。

 在窗口的初始化函数中加入FIX_LAYOUT_INIT宏。

 在窗口的ONSIZE响应函数中加入FIX_LAYOUT_SIZE宏。

说明:如果你的窗口在运行时,有些控件会发生变化,你也可以在变化发生后,重新调用FIX_LAYOUT_INIT宏,这样新的变化就会更新在布局信息数据中。

 

posted on 2011-02-12 11:21  资料回收站  阅读(120)  评论(0)    收藏  举报

导航