VC++实例:动态显示的窗口

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VC++实例:动态显⽰的窗⼝
添加如下关键代码:
⽂件名为haha
BOOL CHahaDlg::OnInitDialog() //中添加
{ CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
MoveWindow(
(desktopRect.Width()-dlgRect.Width())/2,
(desktopRect.Height()-dlgRect.Height())/2,
0,
0);//居中显⽰窗⼝
nWidth=dlgRect.Width();
nHeight=dlgRect.Height();
dx=11;
dy=11;
dx1=10;
dy1=10;//窗⼝放⼤、缩⼩的间隔
SetTimer(1,10,NULL);
}
添加timer消息:
void CHahaDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
if(nIDEvent==1)
{
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)) KillTimer(1);
}
if(nIDEvent==2)
{//MessageBox("haha");
MoveWindow(
(+dx+desktopRect.Width()-dlgRect.Width())/2,
(+dy+desktopRect.Height()-dlgRect.Height())/2,
-dx1+dlgRect.Width(),
-dy1+dlgRect.Height());
if(dlgRect.Width()<=0)
dx1=0;
if(dlgRect.Height()<=0)
dy1=0;
if((dlgRect.Width()<=0)&&(dlgRect.Height()<=0))
{KillTimer(2);
DestroyWindow();}
//CDialog::OnOK();
}
CDialog::OnTimer(nIDEvent);
}
void CHahaDlg::OnButton1()
{ SetTimer(2,10,NULL);
}。

相关文档
最新文档