|
发表于 2018-4-28 11:55:34
|
显示全部楼层
DuiLib 重设窗口大小ResizeClient()函数
使用DUILIB进行界面编写的时候,一般会在xml预设窗口的大小。如:
- <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <Window size="400,260">
复制代码
在上面xml中窗口大小预设为宽400,高260。
有时候一个window控件下有多个其他控件(如水平控件或垂直控件),这些控件高度可能跟预设窗体高度不一样,这个时候需要改变预设的窗口大小。如下:
- <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <Window size="400,260">
- <VerticalLayout>
- <TabLayout name="XXX">
- <HorizontalLayout name="test_0" width="400" height="260">
- <HorizontalLayout name="test_1" width="400" height="300">
- </TabLayout>
- </VerticalLayout>
复制代码
窗体预设大小为宽400,高260,在window控件下,有两个水平控件test_0和test_1,test_0控件大小和预设一直,但是test_1高度大于了预设的260,如果直接在xml进行设置height,其实是不起作用的。这个时候可以使用CWindowWnd窗口中的ResizeClient函数来重新设置窗口尺寸大小,宽和高。
- void ResizeClient(int cx = -1, int cy = -1);//cx为窗体的宽度,cy为窗体的高度
复制代码
cx和cy的值取决于你需要重设窗口的具体宽和高,这个具体的值可以自己摸索和尝试。函数定义:
- void ResizeClient(int cx /*= -1*/, int cy /*= -1*/)
- {
- ASSERT(::IsWindow(m_hWnd));
- RECT rc = { 0 };
- if( !::GetClientRect(m_hWnd, &rc) ) return;
- if( cx != -1 ) rc.right = cx;
- if( cy != -1 ) rc.bottom = cy;
- if( !::AdjustWindowRectEx(&rc, GetWindowStyle(m_hWnd), (!(GetWindowStyle(m_hWnd) & WS_CHILD) && (::GetMenu(m_hWnd) != NULL)), GetWindowExStyle(m_hWnd)) ) return;
- ::SetWindowPos(m_hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- }
复制代码 |
|