第3章 MFC原理介绍

来源:互联网 发布:mac的软件强制退出不了 编辑:程序博客网 时间:2024/06/06 05:41

1.使用CTime类显示当前时间

<span style="font-size:18px;">void CTmDlg::OnTest() {</span><pre name="code" class="html"><span style="font-size:18px;">        //Creates a <strong>CTime</strong> object that represents the current time (static member function).</span>
 CTime t = CTime::GetCurrentTime();//static成员无需对象,直接使用类名来调用即可
int nYear = t.GetYear();int nMonth = t.GetMonth();int nDay = t.GetDay();int nHour = t.GetHour();int nMinute = t.GetMinute();int nSecond = t.GetSecond();CString szTime;//格式化组串:将各种类型的数据合并成一个字符串szTime.Format("%d-%d-%d %d:%d:%d",nYear,nMonth,nDay,nHour,nMinute,nSecond);AfxMessageBox(szTime);}

2.WM_COMMAND:wParam记录单击的按钮或者菜单项等ID号码;

   WM_LBUTTONDOWN:lParam记录单击界面的(x,y)坐标等;


3. CWnd::SetWindowText

     //Sets the window’s title to the specified text. If the window is a control, the text within the control is set.

4.SendMessage等待消息被处理完之后才返回;

   PostMessage只把消息放入窗口消息队列中,不管消息被处理后的结果就返回;

5.MFC调用Win32函数时,函数名前经常需要使用空定义域符号“::”,这是C++用于区别全局函数和成员函数的标志。

6.在MFC程序中,必须使用ON_MESSAGE来关联消息映射函数。

0 0