vc 对话框操作

在mfc中,对话框是最常用的,下面介绍一下在mfc中新建对话框的两种方法和对话框最大化时对话框上控件也成比例放大。

1 新建对话框:

   第一种方法: 

       CYourDlg   dlg;///  
        dlg.DoModal(); 

     关于CYourDlg类,可以自己手动从CDialog中继承,也可以在资源中用控件画好对话框,然后双击对话框就可以自动生成相应的类。

 

  第二种方法:

            CYourDlg *dlg;                             //这要放在某各类的头文件中,或直接声明为全局变量  
             
              /以下执行代码      
             dlg=   new   CYourDlg ();     //记得程序退出时要执行   delete   dlg                
              dlg.Create(IDD_DIALOG1,this);  
              dlg.ShowWindow(SW_SHOWNORMAL);  

        其中IDD_DIALOG1 为你的对话框的资源ID,在对话框的属性中可以看到

 

2 对话框最大化时内部控件成比例扩大

在对话框的属性栏里可以设置对话框是否最大化、最小化等按钮

    控件成比例扩大可以在OnPaint函数中用MoveWindow控制

BOOL MoveWindow(
  HWND hWnd,      // 窗口的句柄
  int X,          // 控件开始的x坐标
  int Y,          // 垂直的y坐标
  int nWidth,     // 控件的宽度
  int nHeight,    // 控件的高度
  BOOL bRepaint   // 是否重画
);
 
Parameters
hWnd
Handle to the window.
X
Specifies the new position of the left side of the window.
Y
Specifies the new position of the top of the window.
nWidth
Specifies the new width of the window.
nHeight
Specifies the new height of the window.
bRepaint
Specifies whether the window is to be repainted. If this parameter is TRUE, the window receives a WM_PAINT message. If the parameter is FALSE, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of moving a child window. If this parameter is FALSE, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值