刚开始用VC,发现到处都是问题,以前用vb太多了。
现在攒了3千多分,现在拼命问问题了!!最常见的CMemDC:
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: [email protected]
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// History - 10/3/97 Fixed scrolling bug.
// Added print support.
// 25 feb 98 - fixed minor assertion bug
//
// This class implements a memory Device Contextclass CMemDC : public CDC
{
public: // constructor sets up the memory DC
CMemDC(CDC* pDC):CDC()
{
ASSERT(pDC != NULL); m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // Make a copy of the relevent parts of the current DC for printing
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY); //Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
} // Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};#endif我有几个问题不解1.构造函数中的CMemDC(CDC* pDC):CDC()
那个CDC()干什么用的,我查了csdn,发现CDC()不返回任何数据啊2.operator CMemDC*() {return this;}
是什么意思,是操作符重载?如果是的话,请帮忙详细讲讲啊。。
现在攒了3千多分,现在拼命问问题了!!最常见的CMemDC:
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: [email protected]
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// History - 10/3/97 Fixed scrolling bug.
// Added print support.
// 25 feb 98 - fixed minor assertion bug
//
// This class implements a memory Device Contextclass CMemDC : public CDC
{
public: // constructor sets up the memory DC
CMemDC(CDC* pDC):CDC()
{
ASSERT(pDC != NULL); m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // Make a copy of the relevent parts of the current DC for printing
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY); //Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
} // Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};#endif我有几个问题不解1.构造函数中的CMemDC(CDC* pDC):CDC()
那个CDC()干什么用的,我查了csdn,发现CDC()不返回任何数据啊2.operator CMemDC*() {return this;}
是什么意思,是操作符重载?如果是的话,请帮忙详细讲讲啊。。
解决方案 »
- 怎么在listview里显示文件或文件夹的修改时间、大小、类型等等
- MFC连接ADO数据库access,编译没有错误,运行报错Runtime error!
- 求在VC6.0中的能收能发的完成端口例程
- MFC封装的DLL,运行错误
- 一个比较菜的问题 CTreeCtrl
- 在使用mfc扩展dll导出类的问题!
- 有关使用timeSetEvent函数的问题(分不够再加)
- 请教高手:一个很是奇怪的问题。
- 急!VC程序如何在没有VC的机子上单独运行?
- 关于在MM_TEXT映射下的坐标变换问题??
- 赋值到datetimepicker,搞了一天没搞好,高手帮忙看看!!!!!!!!!!!!
- 求<<深入浅出MFC>>简体中文版-电子版.
2.用于从CMemDC到CMemDC*的隐式转换。
2。同上!
建议看看c++的基础书籍,呵呵,我以前也是用vb的 :)
可能的如dat04 或许这些值只能在后面才可以确定但是我们仍需要提供一些初始值
或者只是表明现在还没有提供初始值在某些意义上来说有时候需要初始化一个类对象表
明它还没有被初始化多数类都提供了一个特殊的缺省构造函数default constructor 它
不需要指定初始值典型情况下如果类对象是由缺省构造函数初始化的则我们可以认为
它还没有被初始化.
选自primer 566页,唉,你们都没有懂我的意思,不管怎样,多谢了!