VC常用知识

1、模式对话框如何最大化?

答:在对话框的OnInitDialog里面调用:

[html]  view plain copy
  1. ShowWindow(SW_MAXIMIZE);        //最大化  


MSDN:

OnInitDialogOnOK, and OnCancel are virtual functions. To override them, you declare an overriding function in your derived dialog class using the Properties window.

Member function

Message it responds to

Purpose of the override

OnInitDialog

WM_INITDIALOG

Initialize the dialog box's controls.

 

2、如何设置static字体大小?

答:在OnInitDialog里,先CreateFont,再SetFont:

[cpp]  view plain copy
  1. BOOL CLoginDlg::OnInitDialog()  
  2. {  
  3.     CDialog::OnInitDialog();  
  4.     // TODO:  Add extra initialization here  
  5.     CFont font;  
  6.     font.CreateFont(24,   0,   0,   0,   0,   0,   0,   0,   1,   0,   0,   0,   0,   _T( "宋体 "));  //24为字体大小  
  7.     GetDlgItem(IDC_STATIC_NAME)->SetFont(&font);  
  8.     GetDlgItem(IDC_STATIC_SEX)->SetFont(&font);  
  9.     GetDlgItem(IDC_STATIC_GROUP)->SetFont(&font);  
  10.     return TRUE;  // return TRUE unless you set the focus to a control  
  11.     // EXCEPTION: OCX Property Pages should return FALSE  
  12. }  

修正:上述是有问题的,刷新屏幕一次,则字体回到默认,原因就在于字体变量font应该定义为全局变量或者成员变量。
 3、如何设置Tab顺序?

答:在对话框上Ctrl键+D

4、如何删除一个消息定义函数?

答:

首先,在头文件中删除消息函数定义

       afx_msg BOOL OnEraseBkgnd(CDC* pDC);

其次,在源文件中删除消息函数响应

BOOL CMatchDlg::OnEraseBkgnd(CDC* pDC)

{

     // TODO: Add your message handler code here and/or call default

     return CDialog::OnEraseBkgnd(pDC);

}

最后,在BEGIN_MESSAGE_MAP和END_MESSAGE_MAP中删除消息响应宏:

ON_WM_ERASEBKGND()

 

5、 对话框背景图片如何自适应对话框大小?就是说,对话框变大时,图片自动放大;对话框变小时,图片自动缩小。

 答:用StretchBlt函数

Msdn上的StretchBlt解释:

Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.(拉伸或压缩图片以适应目标矩形尺寸的大小)

在OnEraseBkgnd函数中调用StretchBlt函数。

 

6、求立方根

[cpp]  view plain copy
  1. float x;  
  2. x=10.1;  
  3. long y;  
  4. y=3;  
  5. long z;  
  6. z=x*y;  
  7. float m=pow(z,1.0/3.0);  //pow函数的第一个参数必须为long或int型,float型编译出错  

 

//pow函数的第一个参数必须为long或int型,float型编译出错

1>d:\backup\我的文档\visual studio 2008\projects\hjh\hjh\hjhdlg.cpp(163) : error C2666: 'pow' : 6 overloads have similar conversions
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(573): or       'long double pow(long double,long double)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or       'float pow(float,int)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(525): or       'float pow(float,float)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or       'double pow(double,int)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(123): or       'double pow(double,double)'

why???

另外,第二个参数还必须写为小数点的形式,否则也提示出错:

1>d:\backup\我的文档\visual studio 2008\projects\hjh\hjh\hjhdlg.cpp(163) : error C2668: 'pow' : ambiguous call to overloaded function
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or       'float pow(float,int)'
1>        c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or       'double pow(double,int)'
1>        while trying to match the argument list '(long, int)'

 另外,第二个参数必须大于O,否则计算结果为-1.#IND00

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值