背景:MFC程序中。一个登录界面,输入账号密码,点击确定按钮,进入工作界面,此界面弹出后不是最大化。此工作窗口有个背景图片,按照正常流程使其最大化后因为有个背景图片,背景图片会变形。请问怎么使其最大化后背景图片不会变形。登录界面确定按钮代码:
if ( 0!=sPWD.Compare(m_password) )
{
AfxMessageBox("输入密码不正确,请重新输入", MB_ICONEXCLAMATION);
return;
}
else
{
// NewDlg.DoModal();
NewDlg=new CLAUMp4TestDlg;
NewDlg->Create(IDD_JICHETEST,NULL);
ShowWindow(SW_SHOW);
NewDlg->ShowWindow(SW_SHOWMAXIMIZED);
return;
}
UpdateData(FALSE);
以上是部分登录界面代码。BOOL CMy1App::InitInstance()中部分代码
CMy1Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;请问我该肿么办?求大神指点
if ( 0!=sPWD.Compare(m_password) )
{
AfxMessageBox("输入密码不正确,请重新输入", MB_ICONEXCLAMATION);
return;
}
else
{
// NewDlg.DoModal();
NewDlg=new CLAUMp4TestDlg;
NewDlg->Create(IDD_JICHETEST,NULL);
ShowWindow(SW_SHOW);
NewDlg->ShowWindow(SW_SHOWMAXIMIZED);
return;
}
UpdateData(FALSE);
以上是部分登录界面代码。BOOL CMy1App::InitInstance()中部分代码
CMy1Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;请问我该肿么办?求大神指点
void CMy1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
CClientDC dc(this);
CRect clientRect;
GetClientRect(&clientRect);
}
pDC->StretchBlt(0, 0, ..., SRCCOPY);
1.背景图片足够大 用 BbitBlt
2.背景图片不够大 用 StretchBlt
void CLAUMp4TestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}我有些看不明白。
// CDialog::OnPaint();
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP2);
//IDB_BITMAP是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
要把
java的api里面有Layout层的功能,如FlowLayout,BoxLayout等,你可以在创建的时候模糊的规定控件的位置,对话框大小变化时,该层会随窗口大小动态调整控件位置,间距
MFC里面好像还没有(至少2005没有,2008之后不知道),win32也没有那么聪明
如果要动态调整,MoveWindow()...