这个笔记是在观看《孙鑫MFC教程》时写的,他用的是VC6.0,但是Win7和VC6.0 有不兼容的情况,我本人用VS2008来做的一些实例和练习。
窗口创建过程 | 1. 设计窗口类;2. 注册窗口类;3. 创建窗口;4. 显示及更新窗口 | |
以一个名称为Test的MFC程序 | 系统默认会产生:CAboutDlg(继承)、CMainFrame(继承CFrameWnd)、CTestApp(继承CWinApp)、CTestDoc(继承CDocument)、CTestView(继承CView)五个类 |
添加消息响应函数时,同时在三个地方加入了代码: | 1. 自己添加的消息响应函数代码2. 在相应的头文件,在 DECLARE_MESSAGE_MAP() 函数之前,会自动添加进去宏的声明3. 在相应的源文件,在BEGIN_MESSAGE_MAP(CDrawView, CView) END_MESSAGE_MAP()之间,也有相应的宏的声明 |
m_hWnd | 这是从MFC底层类库中派生来的数据成员,在类中可以直接使用。如: HDC hdc; hdc = ::GetDC(m_hWnd); ::ReleaseDC(m_hWnd, hdc); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
对于DC(DeviceContext对象,用于画图,下面是一些代码)
// CDC *pDC = GetDC();
// pDC->MoveTo(m_ptOrigin);
// pDC->LineTo(m_ptEnd);
// ReleaseDC(pDC);
// CClientDC dc(this);
// dc.MoveTo(m_ptOrigin);
// dc.LineTo(m_ptEnd);
dc(GetDesktopWindow());
// dc.MoveTo(m_ptOrigin);
// dc.LineTo(m_ptEnd);
在一个自己建立的modal()类型的对话框上有3个便签和一个加按钮。且有3个整型数据关联。实现相加功能。
//int num1, num2, num3;
//CString str1, str2, str3;
//GetDlgItem(IDC_EDIT1)->GetWindowText(str1);
//GetDlgItem(IDC_EDIT2)->GetWindowText(str2);
//num1=_ttoi((LPCTSTR)str1);
//num2=_ttoi((LPCTSTR)str2);
//num3=num1+num2;
//_itot(num3,(TCHAR*)str3.GetBuffer(10),10);
//str3.ReleaseBuffer();
//GetDlgItem(IDC_EDIT3)->SetWindowText(str3);//当计算好num1+num2 显示在第三个编辑框控件中
//GetDlgItemText(IDC_EDIT1, str1);
//GetDlgItemText(IDC_EDIT2, str2);
//num1=_ttoi((LPCTSTR)str1);
//num2=_ttoi((LPCTSTR)str2);
//num3=num1+num2;
//_itot(num3,(TCHAR*)str3.GetBuffer(10),10);
//str3.ReleaseBuffer();
//SetDlgItemText(IDC_EDIT3, str3);
/*num1 = GetDlgItemInt(IDC_EDIT1);
num2 = GetDlgItemInt(IDC_EDIT2);
num3 = num1 + num2;
SetDlgItemInt(IDC_EDIT3, num3);*/
/*UpdateData();
m_num3 = m_num1 + m_num2;
UpdateData(false);*/
//m_edit1.GetWindowText(str1);
//m_edit2.GetWindowText(str2);
//num1=_ttoi((LPCTSTR)str1);
//num2=_ttoi((LPCTSTR)str2);
//num3=num1+num2;
//_itot(num3,(TCHAR*)str3.GetBuffer(10),10);
//str3.ReleaseBuffer();
//m_edit3.SetWindowText(str3);//当计算好num1+num2 显示在第三个编辑框控件中
人为手动改变对话框的大小
// TODO: 在此添加控件通知处理程序代码
CString str;
GetDlgItemText(ID_SHOUSUO, str);
if (str == "收缩<<")
{
SetDlgItemText(ID_SHOUSUO, L"扩展>>");
}
else
{
SetDlgItemText(ID_SHOUSUO, L"收缩<<");
}
static CRect rectLarge;
static CRect rectSmall;
if (rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.top = rectLarge.top;
rectSmall.left = rectLarge.left;
rectSmall.bottom = rectLarge.bottom;
rectSmall.right = rectSeparator.right;
}
if (str == "收缩<<")
{
SetWindowPos(NULL, 0, 0, rectSmall.Width(), rectSmall.Height(), SWP_NOZORDER | SWP_NOMOVE);
}
else
{
SetWindowPos(NULL, 0, 0, rectLarge.Width(), rectLarge.Height(), SWP_NOZORDER | SWP_NOMOVE);
}
互斥量的使用
#include <windows.h>
#include <iostream.h>
DWORD WINAPI Fun1Proc(
LPVOID lpParameter // thread data
);
DWORD WINAPI Fun2Proc(
LPVOID lpParameter // thread data
);
int index=0;
int tickets=100;
HANDLE hMutex;
void main()
{
HANDLE hThread1;
HANDLE hThread2;
hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
hThread2=CreateThread(NULL,0,Fun2Proc,NULL,0,NULL);
CloseHandle(hThread1);
CloseHandle(hThread2);
/*while(index++<1000)
cout<<"main thread is running"<<endl;*/
//hMutex=CreateMutex(NULL,TRUE,NULL);
hMutex=CreateMutex(NULL,TRUE,"tickets");
if(hMutex)
{
if(ERROR_ALREADY_EXISTS==GetLastError())
{
cout<<"only instance can run!"<<endl;
return;
}
}
WaitForSingleObject(hMutex,INFINITE);
ReleaseMutex(hMutex);
ReleaseMutex(hMutex);
Sleep(4000);
// Sleep(10);
}
DWORD WINAPI Fun1Proc(
LPVOID lpParameter // thread data
)
{
/*while(index++<1000)
cout<<"thread1 is running"<<endl;*/
/*while(TRUE)
{
//ReleaseMutex(hMutex);
WaitForSingleObject(hMutex,INFINITE);
if(tickets>0)
{
Sleep(1);
cout<<"thread1 sell ticket : "<<tickets--<<endl;
}
else
break;
ReleaseMutex(hMutex);
}*/
WaitForSingleObject(hMutex,INFINITE);
cout<<"thread1 is running"<<endl;
return 0;
}
DWORD WINAPI Fun2Proc(
LPVOID lpParameter // thread data
)
{
/*while(TRUE)
{
//ReleaseMutex(hMutex);
WaitForSingleObject(hMutex,INFINITE);
if(tickets>0)
{
Sleep(1);
cout<<"thread2 sell ticket : "<<tickets--<<endl;
}
else
break;
ReleaseMutex(hMutex);
}*/
WaitForSingleObject(hMutex,INFINITE);
cout<<"thread2 is running"<<endl;
return 0;
}
分享到:
相关推荐
MFC学习笔记
MFC学习笔记(onenote格式),一个朋友参加MFC培训,其教师在讲课过程中做的学习日记。图文并茂,是初学者很好的学习资料。
C++、MFC学习笔记!
MFC学习笔记.docx 自己的学习笔记。
价值20000元达内win32加MFC学习笔记.
Visual_C++MFC学习笔记,在你一边听视频一遍查找笔记中的内容,学习C++ MFC会更容易些。
C++ MFC 学习笔记 对初学者有很大提高
MFC学习笔记--案例--销售系统,txt文件存储,格式固定,文件内容增加、删除、修改等,简单控件的使用,文本框,下拉框,表格,界面切换等,缓存,方便以后复习
本人自学MFC期间的学习笔记,分类详细,适合初学者
这是MFC的学习笔记,很好的。比较容易入门。
本人从零开始学C++/MFC的时候,积累和整理的学习笔记,其中有大部分常见问题和处理办法,看过很过帖子,也查过很多资料,最终把他们记录下来。 Demo内容: ★ ::OnTimer OnTimer()函数用于实现定时控制功能,定时...
声明:所有代码和程序仅作为参考,各位可自由使用,出现一切后果自负。 博文地址:http://blog.csdn.net/shortcoder/article/details/16370697
这是一个关于 MFC菜单操作学习笔记 的资源,有需要的朋友下载阅读。
7.16基于对话框编程对话框是一种特殊类型的窗口,绝大多数Windows程序都通过对话框与用户进行交互 2.1 创建基于对话框的 MFC 应用程序框架程序的创建
第一章 VC入门1.1 如何学好VC1.2 理解Windows消息机制1.3 利用Visual C++/MFC开发Windows程序的优势1.4 利用MFC进行开发的通用方法介绍1.5 MFC中常用类、宏、函数介绍第二章 图形输出2.1 和GUI有关的各种对象2.2 在...
达内MFC课程完整笔记
MFC学习对按钮控件的重绘,效果看文章:http://blog.csdn.net/shortcoder/article/details/16343337