对话框上机操作: 实例1 要求: 创建一个工程名为CHDLG_NAME的对话框应用程序,在创建的同时将对话框的名称改为“我的对话框”,最后显示对话框。 实例2 创建一个单文档的应用程序,然后添加一个对话框类,最后添加菜单及代码并通过菜单调用对话框。 步骤: (1) 新建一个SDI应用程序,工程名为HM_Dlg (2) 打开菜单编辑器,在“查看”菜单下添加ID为ID_SHOW、Caption为“对话框(&D)”的子菜单项。 (3) 执行Insert->Reasource命令,添加一个对话框。 (4) 打开类向导对话框,添加对话框类CmyDlg.在View类下添加菜单的消息映射函数OnShow. (5) 在HM_DlgView.cpp中添加代码 #include “MyDlg.h” void CHM_DlgView::OnShow() { CMyDlg dlg; dlg.Domodal(); } 实例3 要求: 创建一个对话框应用程序,改变对话框的名称,利用Font属性将对话框的字体设置为楷体,小二号字,显示其效果。 实例4 逐渐放大的对话框 (1)对话框应用程序工程名为Move_Dlg (2)利用类向导,添加WM_TIMER消息。 (3)在Move_DlgDlg.h中声明变量 public: int nWidth,nHeight; int dx,dy; (4)在Move_DlgDlg.cpp中添加代码 BOOL CMove_DlgDlg::OnInitDialog() { 。。。。。 CRect dlgRect; this->GetWindowRect(dlgRect); this->MoveWindow(0,0,0,0); nWidth=dlgRect.Width(); nHeight=dlgRect.Height(); dx=3; dy=2; SetTimer(1,10,NULL); } void CMove_DlgDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CRect dlgRect; GetWindowRect(dlgRect); CRect desktopRect; this->GetDesktopWindow()->GetWindowRect(desktopRect); //取得桌面窗口区域 if(nIDEvent==1) { this->MoveWindow((-dx+desktopRect.Width()-dlgRect.Width())/2, (-dy+desktopRect.Height()-dlgRect.Height())/2, dx+dlgRect.Width(),dy+dlgRect.Height()); //移动窗口 if(dlgRect.Width()>=nWidth) dx=0; if(dlgRect.Height()>=nHeight) dy=0; if((dlgRect.Width()>=nWidth)&&(dlgRect.Height()>=nHeight)) this->KillTimer(1); } CDialog::OnTimer(nIDEvent); }