|
给你一个可参考的实例吧
在oninitial中添加以下代码实现最大化
//fullScreen
GetClientRect(&m_rect);
CRect m_FullScreenRect;
CRect WindowRect;
GetWindowRect(&WindowRect);
CRect ClientRect;
RepositionBars(0,0xffff,AFX_IDW_PANE_FIRST,reposQuery,&ClientRect);
ClientToScreen(&ClientRect);
int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
int nFullHeight=GetSystemMetrics(SM_CYSCREEN);
m_FullScreenRect.left = WindowRect.left-ClientRect.left;
m_FullScreenRect.top=WindowRect.top-ClientRect.top;
m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth;
m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight;
this->SetWindowPos(&wndBottom,m_FullScreenRect.left,m_FullScreenRect.top,m_FullScreenRect.Width(),m_FullScreenRect.Height(),SWP_SHOWWINDOW);
如何在OnSize中添加以下代码根据窗体大小的变化调整控件大小
CWnd *pWnd;
LOGFONT logFont;
CFont *pFont;
CString cClassName;
CRect rect;//获取控件变化前大小
pWnd=GetWindow(GW_CHILD);//获取控件句柄
while(pWnd)
{
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);//将控件大小转换为在对话框中的区域坐标
rect.left=rect.left*cx/m_rect.Width();///调整控件大小
rect.right=rect.right*cx/m_rect.Width();
rect.top=rect.top*cy/m_rect.Height();
rect.bottom=rect.bottom*cy/m_rect.Height();
pWnd->MoveWindow(rect);//设置控件大小
//adjust font size
static CFont font1;
GetClassName(pWnd->GetSafeHwnd(),cClassName.GetBuffer(255),255);
/*MessageBox(NULL,cClassName,MB_OK);*/
if(cClassName.Compare(_T("static")) !=0)//
{
pFont=pWnd->GetFont();
pFont->GetLogFont(&logFont);
logFont.lfWidth=logFont.lfWidth*(int)(cx/m_rect.Width());
logFont.lfHeight=logFont.lfHeight*(int)(cy/m_rect.Height());
font1.CreateFontIndirect(&logFont);
pWnd->SetFont(&font1);
font1.Detach();
}
pWnd=pWnd->GetWindow(GW_HWNDNEXT);
}
GetClientRect(&m_rect);//将变化后的对话框大小设为旧大小 |
|