LouZhang

导航

对话框学习3

学习一个收缩对话框的方法

在C***Dlg类中的OnInitDialog函数里

CRect winRect;
    GetWindowRect(winRect);
    m_winWidth = winRect.right;
    /*CString str;
    str.Format("%d", winRect.Width());
    AfxMessageBox(str);*/
    CRect btRect;
    GetDlgItem(IDC_BUTTON1)->GetWindowRect(btRect);
    m_shrinkWidth = btRect.right;
    winRect.SetRect(winRect.left, winRect.top,
        winRect.right, winRect.bottom);

GetWindowRect是获取整个对话框的CRect值

GetDlgItem(IDC_BUTTON1)->GetWindowRect(btRect)则是获取一个控件(按钮)的CRect值,并且在这里记录下来

双击button1响应消息并添加代码:

void CShrinkDlg::OnBnClickedButton1()
{
    // TODO: 在此添加控件通知处理程序代码
    CRect winRect;
    GetWindowRect(winRect);
    if(m_shrikn){
        winRect.SetRect(winRect.left, winRect.top,
            winRect.left + m_winWidth, winRect.bottom);
        GetDlgItem(IDC_BUTTON1)->SetWindowText("<<");
    }else{
        winRect.SetRect(winRect.left, winRect.top,
            winRect.left + m_shrinkWidth, winRect.bottom);
        GetDlgItem(IDC_BUTTON1)->SetWindowTextA(">>");
    }
    MoveWindow(winRect, TRUE);
    m_shrikn = ! m_shrikn;
        
}

通过SetRect函数来重新设定对话框大小 

并通过MoveWindows来实现对话框

 

 

写代码好累啊!

posted on 2012-09-28 12:01  louzhang_swk  阅读(165)  评论(0编辑  收藏  举报