MFC第八天

mfc绘图

绘图对象的使用,

CBitmap  使用

创建于当前dc的兼容dc   (内存中数据结构一样)

将位图选入兼容dc

将位图从兼容dc拷贝到当前dc

将位图从兼容dc中选出,恢复位图

删除兼容dc

删除位图对象

CRgn 复杂区域

创建几何区域

CRgn::CreateXXX

将两个几何区域进行运算,可以多次运算

CRgn::CombineRgn

填充区域

CDC::FillRgn

填充边框

CDC::FrameRgn

CWnd::SetWindowRgn    创建不规则窗口,按钮

CPalette  调色板,用来设置颜色,减少

MFC集合类

Arrays  动态数组

CArrays    模板类

Lists  链表(双向链表)

CList  模板类

Maps  映射

CMap   模板类

模板类 存储自定义类型的数据

非模板类  存储特定类型的数据

CArray

使用: 定义

template< class TYPE, class ARG_TYPE > class CArray : public CObject

TYPE 要存储的元素的类型

ARG_TYPE  CArray成员函数的参数类型

自定义的类需要,偶人构造,或者有默认的参数

集合会不时的调用默认构造

要预计要存储的元素的数量,设置数组的初始大小

CList

定义  参数与CArray相同

POSITION Find( ARG_TYPE searchValue, POSITION startAfter = NULL) const;

调用Find函数需要重载==运算符

template< class KEY, class ARG_KEY, class VALUE, class ARG_VALUE >

class CMap : public CObject

查找元素 根据键查找值

Lookup

***************************

key-->hashCode

nIndex=hashCode%nSize

*****************************************

template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>

class CMap : public CObject

{

protected:

// Association

struct CAssoc

{

CAssoc* pNext;   //链表

UINT nHashValue;  // needed for efficient iteration

KEY key;

VALUE value;

};

public:

// Construction

CMap(int nBlockSize = 10);

// Attributes

// number of elements

int GetCount() const;

BOOL IsEmpty() const;

// Lookup

BOOL Lookup(ARG_KEY key, VALUE& rValue) const;

// Operations

// Lookup and add if not there

VALUE& operator[](ARG_KEY key);

// add a new (key, value) pair

void SetAt(ARG_KEY key, ARG_VALUE newValue);

// removing existing (key, ?) pair

BOOL RemoveKey(ARG_KEY key);

void RemoveAll();

// iterating all (key, value) pairs

POSITION GetStartPosition() const;

void GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const;

// advanced features for derived classes

UINT GetHashTableSize() const;

void InitHashTable(UINT hashSize, BOOL bAllocNow = TRUE);

// Implementation

protected:

CAssoc** m_pHashTable;

UINT m_nHashTableSize;

int m_nCount;

CAssoc* m_pFreeList;

struct CPlex* m_pBlocks;

int m_nBlockSize;

CAssoc* NewAssoc();

void FreeAssoc(CAssoc*);

CAssoc* GetAssocAt(ARG_KEY, UINT&) const;

public:

~CMap();

void Serialize(CArchive&);

#ifdef _DEBUG

void Dump(CDumpContext&) const;

void AssertValid() const;

#endif

};

源代码

// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "MFCDraw.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here

}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
// MFCDraw.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "MFCDraw.h"

#include "MainFrm.h"
#include "MFCDrawDoc.h"
#include "MFCDrawView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawApp

BEGIN_MESSAGE_MAP(CMFCDrawApp, CWinApp)
	//{{AFX_MSG_MAP(CMFCDrawApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawApp construction

CMFCDrawApp::CMFCDrawApp()
{	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMFCDrawApp object

CMFCDrawApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawApp initialization

BOOL CMFCDrawApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMFCDrawDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CMFCDrawView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnDcCpen();
	afx_msg void OnDcGdibrush();
	afx_msg void OnDcGdifont();
	afx_msg void OnDcGdipen();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
//	ON_COMMAND(ID_DC_CPEN, OnDcCpen)
//	ON_COMMAND(ID_DC_GDIBRUSH, OnDcGdibrush)
//	ON_COMMAND(ID_DC_GDIFONT, OnDcGdifont)
//	ON_COMMAND(ID_DC_GDIPEN, OnDcGdipen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CMFCDrawApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawApp message handlers

void CAboutDlg::OnDcCpen()
{
	// TODO: Add your command handler code here

}

void CAboutDlg::OnDcGdibrush()
{
	// TODO: Add your command handler code here

}

void CAboutDlg::OnDcGdifont()
{
	// TODO: Add your command handler code here

}

void CAboutDlg::OnDcGdipen()
{
	// TODO: Add your command handler code here

}
// MFCDrawDoc.cpp : implementation of the CMFCDrawDoc class
//

#include "stdafx.h"
#include "MFCDraw.h"

#include "MFCDrawDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawDoc

IMPLEMENT_DYNCREATE(CMFCDrawDoc, CDocument)

BEGIN_MESSAGE_MAP(CMFCDrawDoc, CDocument)
	//{{AFX_MSG_MAP(CMFCDrawDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawDoc construction/destruction

CMFCDrawDoc::CMFCDrawDoc()
{
	// TODO: add one-time construction code here

}

CMFCDrawDoc::~CMFCDrawDoc()
{
}

BOOL CMFCDrawDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawDoc serialization

void CMFCDrawDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawDoc diagnostics

#ifdef _DEBUG
void CMFCDrawDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CMFCDrawDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawDoc commands
// MFCDrawView.cpp : implementation of the CMFCDrawView class
//

#include "stdafx.h"
#include "MFCDraw.h"

#include "MFCDrawDoc.h"
#include "MFCDrawView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView

IMPLEMENT_DYNCREATE(CMFCDrawView, CView)

BEGIN_MESSAGE_MAP(CMFCDrawView, CView)
	//{{AFX_MSG_MAP(CMFCDrawView)
	ON_COMMAND(ID_DC_CPEN, OnDcCpen)
	ON_COMMAND(ID_DC_GDIBRUSH, OnDcGdibrush)
	ON_COMMAND(ID_DC_GDIFONT, OnDcGdifont)
	ON_COMMAND(ID_DC_GDIPEN, OnDcGdipen)
	ON_COMMAND(ID_GDI_BMP, OnGdiBmp)
	ON_COMMAND(ID_GDI_RGN, OnGdiRgn)
	ON_COMMAND(ID_GDI_LINE, OnGdiLine)
	ON_COMMAND(ID_GDI_ELLIPSE, OnGdiEllipse)
	ON_COMMAND(ID_GDI_RECT, OnGdiRect)
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView construction/destruction

CMFCDrawView::CMFCDrawView()
{
	// TODO: add construction code here
//	m_ptBegin;
	m_nDrawType=0;
}

CMFCDrawView::~CMFCDrawView()
{
}

BOOL CMFCDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView drawing

void CMFCDrawView::OnDraw(CDC* pDC)
{
	CMFCDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView printing

BOOL CMFCDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView diagnostics

#ifdef _DEBUG
void CMFCDrawView::AssertValid() const
{
	CView::AssertValid();
}

void CMFCDrawView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCDrawDoc* CMFCDrawView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCDrawDoc)));
	return (CMFCDrawDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCDrawView message handlers

void CMFCDrawView::OnDcCpen()
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	CPen pen(PS_SOLID,5,RGB(255,0,0));
	CPen *pOldPen=dc.SelectObject(&pen);
	dc.Rectangle(50,50,150,200);
	dc.SelectObject(pOldPen);
	pen.DeleteObject();
}

void CMFCDrawView::OnDcGdibrush()
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	CBitmap bitMap;
	bitMap.LoadBitmap(IDB_BITMAP1);
//	CBrush brush(HS_BDIAGONAL,RGB(0,255,0));
	CBrush brush(&bitMap);
	CBrush *pOldBrush=dc.SelectObject(&brush);
	RECT rect={100,100,250,200};
	dc.FillRect(&rect,&brush);
	dc.SelectObject(&pOldBrush);
	brush.DeleteObject();
}

void CMFCDrawView::OnDcGdifont()
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	CFont font;
	font.CreatePointFont(500,"黑体");
	CFont *pOldFont=dc.SelectObject(&font);
	dc.TextOut(100,100,"hello CFont");
	dc.SelectObject(pOldFont);
	font.DeleteObject();
}

void CMFCDrawView::OnDcGdipen()
{
	// TODO: Add your command handler code here

}

void CMFCDrawView::OnGdiBmp()
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	//无法直接把位图选入dc,位图大小不固定。
	CBitmap bmp;
	bmp.LoadBitmap(IDB_BITMAP2);
	//创建兼容dc
	CDC dcBmp;
	dcBmp.CreateCompatibleDC(&dc);
	//将位图选入兼容dc
	CBitmap*pOldBmp=dcBmp.SelectObject(&bmp);
	//将位图从兼容dc向当前dc拷贝
/*	dc.BitBlt(
		0,0,
		253,200,
		&dcBmp,
		0,0,
		SRCCOPY
		);	*/
	CRect rcClient;
	GetClientRect(&rcClient);
	dc.StretchBlt(
		0,0,
		rcClient.Width(),rcClient.Height(),
		&dcBmp,
		0,0,
		253,200,
		SRCCOPY
		);
	dcBmp.SelectObject(pOldBmp);
	dcBmp.DeleteDC();
	bmp.DeleteObject();
}

void CMFCDrawView::OnGdiRgn()
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	CBrush brush(RGB(255,0,0));
	CBrush* pOldBrush=dc.SelectObject(&brush);
	CRgn rgn1,rgn2,rgn3;
	rgn1.CreateRectRgn(100,100,300,200);
	rgn2.CreateEllipticRgn(150,150,300,250);
	rgn2.CombineRgn(&rgn1,&rgn2,RGN_DIFF);
	dc.FillRgn(&rgn2,&brush);
	dc.SelectObject(pOldBrush);
	brush.DeleteObject();
	AfxGetMainWnd()->SetWindowRgn(rgn1,TRUE);	//制作不规则窗口 按钮
	//CWnd::SetWindowRgn
}

void CMFCDrawView::OnGdiLine()
{
	// TODO: Add your command handler code here
	m_nDrawType=0;
	m_ptBegin=0;
	m_ptEnd=0;
}

void CMFCDrawView::OnGdiEllipse()
{
	// TODO: Add your command handler code here
	m_nDrawType=2;
}

void CMFCDrawView::OnGdiRect()
{
	// TODO: Add your command handler code here
	m_nDrawType=1;
}

void CMFCDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	m_ptEnd=point;
	CClientDC dc(this);
	switch(m_nDrawType){
		case 0:{
					dc.MoveTo(m_ptBegin.x,m_ptBegin.y);
					dc.LineTo(m_ptEnd.x,m_ptEnd.y);
				break;
			   }
		case 1:{
					dc.Rectangle(m_ptBegin.x,m_ptBegin.y,m_ptEnd.x,
						m_ptEnd.y);
					break;
			   }
		case 2:{
					dc.Ellipse(m_ptBegin.x,m_ptBegin.y,m_ptEnd.x,
						m_ptEnd.y);
					break;
			   }
	}
	CView::OnLButtonUp(nFlags, point);
}

void CMFCDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	m_ptBegin=point;
	CView::OnLButtonDown(nFlags, point);
}
时间: 2024-08-27 06:05:28

MFC第八天的相关文章

《深入浅出MFC》第七章 简单而完整:MFC骨干程序

不二法门:熟记MFC类层次结构.经常使用的主要MFC类:CWinApp, CWnd<-CView, CWnd<-CFrameWnd, CFrameWnd<-CMDIFrameWnd, CFrameWnd<-CMDIChildWnd, CWnd<-CDialog, CWnd<-CControlBar, CControlBar<-CStatusBar, CControlBar<-CToolBar, CCmdTarget<-CDocument, CCmdTa

深入浅出MFC——消息映射与命令传递(六)

1. 消息分类: 2. 万流归宗——Command Target(CCmdTarget): 3. "消息映射"是MFC内建的一个信息分派机制.通过三个宏(DECLARE_MESSAGE_MAP/BEGIN.../ON.../END...)完成消息网的建构. 4. 注意:CWinThread派生自CCmdTarget,但没有DECLARE_/BEGIN_/END_宏组. 5. 消息映射与虚函数: 6.

MFC控件使用技巧:List Control

1)每列内容过长,显示不完整 只有加载数据的情况下,才会出现水平滚动条 解决方案: 可以添加如下一个空的内容项: m_List.InsertItem(0,NULL);//为了显示进度条 2)不允许点击修改第一列(当然最多能够让我们改动的也只有他了) MFC默认情况下可以修改第一列,其他的不允许修改(需要定制DrawItem) 解决方案: Edit Labels 属性设置为 False 3)报表的形式表示 View 属性设置为 Report 4)注意:不要和列表框控件混淆(英文名: List Bo

【mfc】用对话框分页实现用户登录

所谓的对话框分页就是点击完一个对话框的按钮,切换到另一个对话框, 这样的对话框多用于一些需要用户登录才能够进行操作的软件, 下面就用对话框分页来实现用户登录系统 一.基本目标 有如下的程序,输入用户名与密码,如果用户名为admin,密码为123456,那么则成功登录,切换到一个有"欢迎登录"与"关闭"按钮的对话框 如果用户名或者密码输入错误则弹出提示, 点击关闭能够关闭这个程序,不弹出用户登录的对话框. 二.制作过程 1.首先如同之前的<[mfc]对于对话框程

MFC中给控件添加变量,DoDataExchange中

DoDataExchange函数其实是一项数据动态绑定技术.比如你在写动态按钮过程中须对按钮添加变量时,怎么添加?控件类已经写好了,其变量是已经固定的.你要添加新的变量就要用到DoDataExchange函数. 你要在对话框的构造函数里面初始化一个变量,再用DoDataExchange函数将它绑定到你的动态按扭中,比如:DDX_Check(pDX, IDC_CHECK1, m_Lesson1);这就是将m_Lesson1(这是一个外部变量,其定义在对话框的构造函数里)绑定到IDC_CHECK1中

MFC消息映射的原理:笔记

多态的实现机制有两种,一是通过查找绝对位置表,二是查找名称表:两者各有优缺点,那么为什么mfc的消息映射采用了第二种方法,而不是c++使用的第一种呢?因为在mfc的gui类库是一个庞大的继承体系,而里面的每个类有很多成员函数(只说消息反映相关的成员函数啊),而且在派生类中,需要改写的也比较少(我用来做练习的程序就是那么一两个,呵呵).那么用c++的虚函数的实现机制会导致什么问题呢?就是大量虚表的建立使得空间浪费掉很多. 嗯-怎么办呢?于是各大c++名库(比如QT,MFC,VCL-)在消息映射的实

MFC-消息分派

前言 由于工作需要,这几天学了一点MFC,在AFX里看到很多熟悉的东西,如类型信息,序列化,窗口封装和消息分派.几乎每个界面库都必须提供这些基础服务,但提供的手法却千差万别.MFC大量地借用了宏,映射表来实现,而VCL则更多的在语言级别上给与支持.这其实是很容易理解的,因为C++是一个标准,不会因某个应用而随便扩展语言:相反Delphi完全由一个公司掌握,因此每支持一项新技术,变化最大的往往是语言本身. 学习MFC的代码,再对照VCL的实现,这真是一个很有意思的过程,其中可以看到两个框架在一些设

MFC中的DC CDC HDC由来由去理解

MFC中的DC CDC HDC由来由去理解 在此非常感谢博客主的究竟钻研,非常详细的参考资料:http://blog.csdn.net/yam_killer/article/details/7661449

(七):处理MFC

(一):简单介绍 为了可以在一个Winelib应用中使用MFC,你须要首先使用Winelib又一次编译MFC. 在理论上,你应该为Windows的MFC编写一个封装(怎样编写在后面介绍).可是,在实践中,对MFC来说.可能不是一个真正的解决方案: 数量巨大的API使得编写封装的工作量非常大 进一步说.MFC包括大量的API.这些API在制作封装的时候处理起来是非常复杂的. 即使你编写了封装,你也须要去改动MFC的头文件以使编译器不会堵塞他们. 在你应用中的非常大一部分MFC代码是以宏的形式展现的