1、模式对话框如何最大化?
答:在对话框的OnInitDialog里面调用:
ShowWindow(SW_MAXIMIZE); //最大化
MSDN:
OnInitDialog, OnOK, 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:
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CFont font;
font.CreateFont(24, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, _T( "宋体 ")); //24为字体大小
GetDlgItem(IDC_STATIC_NAME)->SetFont(&font);
GetDlgItem(IDC_STATIC_SEX)->SetFont(&font);
GetDlgItem(IDC_STATIC_GROUP)->SetFont(&font);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
修正:上述是有问题的,刷新屏幕一次,则字体回到默认,原因就在于字体变量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、求立方根
float x;
x=10.1;
long y;
y=3;
long z;
z=x*y;
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