对话框的一些操作

来源:互联网 发布:淘宝网的绿知了的价格 编辑:程序博客网 时间:2024/04/30 19:22

1.响应一个按键,弹出对话框

 

void CBreathCmDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
    OnOK();          //销毁引导窗口//    销毁原对话框
  CMain dlg;       //进入主窗口    //   Cmain 为响应按键要显示的对话框
   dlg.DoModal();                     //x显示对话框
 
}

 

 

2.对话框最大化

在对话框的初始化函数中加入:  
  BOOL   dlg::OnInitDialog()    
  {  
          //...  
          ShowWindow(SW_SHOWMAXIMIZED);  
          //...  
  }  
  这样就可以实现窗口最大化。

 

也可以这样

   RECT   r;  
 SystemParametersInfo(   SPI_GETWORKAREA,   sizeof(RECT),   &r,   0   );  
 SetWindowPos(NULL,  
  r.left,   r.top,  
  r.right,   r.bottom,  
  SWP_SHOWWINDOW);  

 

3.使对话框上的按键,按照比例扩大

 

void CtestDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);

static RECT LastWindowRect = {0, 0, 0, 0};//用来保存窗口上一次的大小
    CWnd *hWin;//构造一个句柄
    int ux = cx - LastWindowRect.right;
 
 //求出窗口的水平变化量
    int uy = cy - LastWindowRect.bottom;
 
 //求出窗口的竖直变化量
 if((hWin = GetDlgItem(IDOK|IDCANCEL)) != NULL) //IDC_LIST1为控件的ID号
    {
        RECT rect;
        hWin->GetWindowRect(&rect);//获得控件的大小
        ScreenToClient(&rect);//设备到客户
        rect.right += ux;//
        rect.bottom += uy;
        hWin->MoveWindow(&rect);//改变控件大小
    }
    LastWindowRect.right = cx;
    LastWindowRect.bottom = cy;

原创粉丝点击