论坛: 编程破解 标题: VC++的问题! 复制本贴地址    
作者: hongyang [hongyang]    论坛用户   登录
我在用VC++的基于对话框的功能时,其自动生成的代码中有下面的一段,我不知道其确切的意识,望您给指导一下!!谢谢!!
就是下面的OnPaint作用是什么?
IsIconic()是判断什么的?
两个GetSystemMetrics(SM_CXICON)是起什么作用的?
下面的两句怎么理解?
int x = (rect.Width() - cxIcon + 1) / 2
int y = (rect.Height() - cyIcon + 1) / 2;

代码如下:

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.


void CGetimageDlgDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}


地主 发表时间: 10/25 12:42

回复: cyshaoping [cyshaoping]   论坛用户   登录
GetSystemMetrics(SM_CXICON)获得标准图表的宽
另一个就获得高

B1层 发表时间: 10/25 18:31

回复: hongyang [hongyang]   论坛用户   登录
那么上面的OnPaint函数的整体作用只是加载程序图标么?还是什么作用?
IsIconic()函数是判断什么的,起什么作用啊?不懂,郁闷!!

下面两句中的
int x = (rect.Width() - cxIcon + 1) / 2
int y = (rect.Height() - cyIcon + 1) / 2;

int x=(rect.Width()-cxIcon+1)/2是怎么回事,为什么要减去cxIcon,还要加1
并且还要除以2(/2)??
仁兄指点一下!!谢谢!!

B2层 发表时间: 10/25 19:04

回复: cyshaoping [cyshaoping]   论坛用户   登录
onpaint()负责屏幕输出工作
IsIconic()判断窗口是否已最小化,返回值Long,非零表示成功,零表示失败
你这个onpaint()函数应该是要在客户区中间画一个图标
为什么要加1我就不知道了

B3层 发表时间: 10/25 19:26

回复: hongyang [hongyang]   论坛用户   登录
cyshaoping仁兄,太感谢你了,你的API函数我受到了,太谢谢你了,我真想与你当面相谢,但事与愿违,以后小弟就由你多多照顾了,谢了!!

B4层 发表时间: 10/25 21:16

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号