请问一下:DrawDibDraw函数应该怎么使用啊?~~~~~~ 在网上查了一下,中文的写的都太简略了,英文的还看不懂,所以只好到此来求教了~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #ifndef Canvas_H#define Canvas_H#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include <AfxWin.h>#include <Vfw.h>#include <AfxMt.h>class CCanvas : public CStatic{public: CCanvas(); void Clear(); void SetBitmapSize(int nWidth, int nHeight); bool Draw(unsigned char *pBitmap, unsigned long nLength);// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCanvas) //}}AFX_VIRTUAL// Implementationpublic: virtual ~CCanvas(); // Generated message map functionsprotected: //{{AFX_MSG(CCanvas) afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP()private: void InitCanvas(int nWidth, int nHeight); unsigned char *m_pBitmapBuffer; HDRAWDIB m_hDrawDIB; BITMAPINFOHEADER m_BitmapInfoHeader; CCriticalSection m_CriticalSection;};#endif #include "Canvas.h"#include "LocalLock.h"#pragma comment(lib, "Vfw32")#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endiftypedef CLocalLock<CCriticalSection> CLocalCSLock;const unsigned long BackGroundColor = 192;CCanvas::CCanvas() : m_hDrawDIB(NULL), m_pBitmapBuffer(NULL){ memset(&m_BitmapInfoHeader, 0, sizeof(m_BitmapInfoHeader)); m_hDrawDIB = ::DrawDibOpen(); InitCanvas(0, 0);}CCanvas::~CCanvas(){ ::DrawDibClose(m_hDrawDIB); m_hDrawDIB = NULL; if (m_pBitmapBuffer != NULL) { delete [] m_pBitmapBuffer; m_pBitmapBuffer = NULL; }}BEGIN_MESSAGE_MAP(CCanvas, CStatic) //{{AFX_MSG_MAP(CCanvas) ON_WM_PAINT() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCanvas message handlersvoid CCanvas::OnPaint(){ CPaintDC PaintDC(this); HDC hDC = PaintDC.GetSafeHdc(); CRect rect; bool bRet = false; if (m_pBitmapBuffer == NULL) { goto OnPaintExit; } if (hDC == NULL) { goto OnPaintExit; } GetClientRect(&rect); bRet = (::DrawDibDraw(m_hDrawDIB, hDC, 0, 0, rect.Width(), rect.Height(), &m_BitmapInfoHeader, m_pBitmapBuffer, 0, 0, m_BitmapInfoHeader.biWidth, m_BitmapInfoHeader.biHeight, 0) == TRUE);OnPaintExit: if (!bRet) { CStatic::OnPaint(); }}bool CCanvas::Draw(unsigned char *pBitmap, unsigned long nLength){ if (pBitmap == NULL || nLength == 0) { return false; } if (m_pBitmapBuffer == NULL || nLength != m_BitmapInfoHeader.biSizeImage) { return false; } CLocalCSLock localLock(&m_CriticalSection); memcpy(m_pBitmapBuffer, pBitmap, m_BitmapInfoHeader.biSizeImage); Invalidate(); UpdateWindow(); return true;}void CCanvas::InitCanvas(int nWidth, int nHeight){ if (nWidth < 0 || nHeight < 0) { return; } CLocalCSLock localLock(&m_CriticalSection); if (m_pBitmapBuffer != NULL) { delete [] m_pBitmapBuffer; m_pBitmapBuffer = NULL; } m_BitmapInfoHeader.biSize = sizeof(m_BitmapInfoHeader); m_BitmapInfoHeader.biWidth = nWidth; m_BitmapInfoHeader.biHeight = nHeight; m_BitmapInfoHeader.biPlanes = 1; m_BitmapInfoHeader.biBitCount = 24; m_BitmapInfoHeader.biCompression = 0; m_BitmapInfoHeader.biSizeImage = m_BitmapInfoHeader.biWidth * m_BitmapInfoHeader.biHeight * m_BitmapInfoHeader.biBitCount / 8; m_BitmapInfoHeader.biXPelsPerMeter = 0; m_BitmapInfoHeader.biYPelsPerMeter = 0; m_BitmapInfoHeader.biClrUsed = 0; m_BitmapInfoHeader.biClrImportant = 0; if (m_BitmapInfoHeader.biSizeImage > 0) { m_pBitmapBuffer = new unsigned char[m_BitmapInfoHeader.biSizeImage]; memset(m_pBitmapBuffer, BackGroundColor, m_BitmapInfoHeader.biSizeImage); }}void CCanvas::SetBitmapSize(int nWidth, int nHeight){ if (nWidth < 0 || nHeight < 0) { return; } InitCanvas(nWidth, nHeight);}void CCanvas::Clear(){ if (m_pBitmapBuffer == NULL) { return; } memset(m_pBitmapBuffer, BackGroundColor, m_BitmapInfoHeader.biSizeImage); Draw(m_pBitmapBuffer, m_BitmapInfoHeader.biSizeImage);} #ifndef LocalLock_H#define LocalLock_Htemplate <class Type>class CLocalLock{public: CLocalLock(Type *pObject) : m_pObject(pObject) { m_pObject->Lock(); } ~CLocalLock() { m_pObject->Unlock(); }private: Type *m_pObject;};#endif VC如何计算负数算式? 浮点数如何处理 在线急等 :用vc++6.0的mscomm控件做的串口通信程序,為什么在沒有安裝vc的机器无法运行. 30岁程序员的薪水 如何控制系統自帶的Windows Media Player播放器... 动态改变菜单项文字... 98下 ASPI命令发送 求助。 怎么实现下拉工具条,不是工具条下拉菜单那种?(第二次提问了,急用啊) 我是谁????? 类似NetMeeting编程问题...^%%&#$^$^#$@#@ 关于handle类和NULL值的问题 100分,求脱离matlab环境的vc与matlab接口编程
#ifndef Canvas_H
#define Canvas_H#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include <AfxWin.h>
#include <Vfw.h>
#include <AfxMt.h>class CCanvas : public CStatic
{
public:
CCanvas(); void Clear();
void SetBitmapSize(int nWidth, int nHeight);
bool Draw(unsigned char *pBitmap, unsigned long nLength);// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCanvas)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CCanvas(); // Generated message map functions
protected:
//{{AFX_MSG(CCanvas)
afx_msg void OnPaint();
//}}AFX_MSG DECLARE_MESSAGE_MAP()private:
void InitCanvas(int nWidth, int nHeight); unsigned char *m_pBitmapBuffer;
HDRAWDIB m_hDrawDIB;
BITMAPINFOHEADER m_BitmapInfoHeader; CCriticalSection m_CriticalSection;
};#endif
#include "Canvas.h"
#include "LocalLock.h"#pragma comment(lib, "Vfw32")#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endiftypedef CLocalLock<CCriticalSection> CLocalCSLock;const unsigned long BackGroundColor = 192;CCanvas::CCanvas()
: m_hDrawDIB(NULL),
m_pBitmapBuffer(NULL)
{
memset(&m_BitmapInfoHeader, 0, sizeof(m_BitmapInfoHeader)); m_hDrawDIB = ::DrawDibOpen();
InitCanvas(0, 0);
}CCanvas::~CCanvas()
{
::DrawDibClose(m_hDrawDIB);
m_hDrawDIB = NULL; if (m_pBitmapBuffer != NULL) {
delete [] m_pBitmapBuffer;
m_pBitmapBuffer = NULL;
}
}BEGIN_MESSAGE_MAP(CCanvas, CStatic)
//{{AFX_MSG_MAP(CCanvas)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCanvas message handlersvoid CCanvas::OnPaint()
{
CPaintDC PaintDC(this);
HDC hDC = PaintDC.GetSafeHdc();
CRect rect; bool bRet = false;
if (m_pBitmapBuffer == NULL) {
goto OnPaintExit;
} if (hDC == NULL) {
goto OnPaintExit;
} GetClientRect(&rect); bRet = (::DrawDibDraw(m_hDrawDIB, hDC, 0, 0, rect.Width(), rect.Height(), &m_BitmapInfoHeader, m_pBitmapBuffer, 0, 0, m_BitmapInfoHeader.biWidth, m_BitmapInfoHeader.biHeight, 0) == TRUE);OnPaintExit:
if (!bRet) {
CStatic::OnPaint();
}
}bool CCanvas::Draw(unsigned char *pBitmap, unsigned long nLength)
{
if (pBitmap == NULL || nLength == 0) {
return false;
} if (m_pBitmapBuffer == NULL || nLength != m_BitmapInfoHeader.biSizeImage) {
return false;
} CLocalCSLock localLock(&m_CriticalSection);
memcpy(m_pBitmapBuffer, pBitmap, m_BitmapInfoHeader.biSizeImage); Invalidate();
UpdateWindow();
return true;
}void CCanvas::InitCanvas(int nWidth, int nHeight)
{
if (nWidth < 0 || nHeight < 0) {
return;
} CLocalCSLock localLock(&m_CriticalSection);
if (m_pBitmapBuffer != NULL) {
delete [] m_pBitmapBuffer;
m_pBitmapBuffer = NULL;
} m_BitmapInfoHeader.biSize = sizeof(m_BitmapInfoHeader);
m_BitmapInfoHeader.biWidth = nWidth;
m_BitmapInfoHeader.biHeight = nHeight;
m_BitmapInfoHeader.biPlanes = 1;
m_BitmapInfoHeader.biBitCount = 24;
m_BitmapInfoHeader.biCompression = 0;
m_BitmapInfoHeader.biSizeImage = m_BitmapInfoHeader.biWidth * m_BitmapInfoHeader.biHeight * m_BitmapInfoHeader.biBitCount / 8;
m_BitmapInfoHeader.biXPelsPerMeter = 0;
m_BitmapInfoHeader.biYPelsPerMeter = 0;
m_BitmapInfoHeader.biClrUsed = 0;
m_BitmapInfoHeader.biClrImportant = 0; if (m_BitmapInfoHeader.biSizeImage > 0) {
m_pBitmapBuffer = new unsigned char[m_BitmapInfoHeader.biSizeImage];
memset(m_pBitmapBuffer, BackGroundColor, m_BitmapInfoHeader.biSizeImage);
}
}void CCanvas::SetBitmapSize(int nWidth, int nHeight)
{
if (nWidth < 0 || nHeight < 0) {
return;
} InitCanvas(nWidth, nHeight);
}void CCanvas::Clear()
{
if (m_pBitmapBuffer == NULL) {
return;
} memset(m_pBitmapBuffer, BackGroundColor, m_BitmapInfoHeader.biSizeImage);
Draw(m_pBitmapBuffer, m_BitmapInfoHeader.biSizeImage);
}
#ifndef LocalLock_H
#define LocalLock_Htemplate <class Type>
class CLocalLock
{
public:
CLocalLock(Type *pObject) : m_pObject(pObject) { m_pObject->Lock(); }
~CLocalLock() { m_pObject->Unlock(); }private:
Type *m_pObject;
};#endif