背景: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;请问我该肿么办?求大神指点

解决方案 »

  1.   

    不知道你dlg的OnPaint()怎么写的,如果用了DC拉伸,取消拉伸就可以了,不过也可能遮不住了.
      

  2.   

    OnPaint函数如下
    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);
    }
      

  3.   

    IsIconic()好像是最小化,有没有对所提到的变形图片的定义或操作?
      

  4.   

    在你工作窗口的OnDraw函数中用BilBit来绘背景图,或者pDC->SetStretchBltMode(HALFTONE);
    pDC->StretchBlt(0, 0, ..., SRCCOPY);
      

  5.   

    “背景图片不会变形。”
    1.背景图片足够大 用 BbitBlt
    2.背景图片不够大 用 StretchBlt 
      

  6.   

    你的OnPaint()函数中怎么贴图的?StretchBlt() ??
      

  7.   

    这个是工作界面的OnPaint()函数
    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();
    }
    }我有些看不明白。
      

  8.   

    谢谢各位大神。我搞定了。原来在else中贴出如下代码即可
     //     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);
    要把
      

  9.   

    你的dlg应该是resouce editor画的,如果用文本打开,就会发现都是绝对坐标.
    java的api里面有Layout层的功能,如FlowLayout,BoxLayout等,你可以在创建的时候模糊的规定控件的位置,对话框大小变化时,该层会随窗口大小动态调整控件位置,间距
    MFC里面好像还没有(至少2005没有,2008之后不知道),win32也没有那么聪明
    如果要动态调整,MoveWindow()...