-
January 27th, 2013, 07:46 AM
#1
How to create an image buffer in MFC
Hello everyone,
I'm new to codeguru and beginner with MFC.
Can anyone please explain, or point out to an internet resource that explains how to create, initialize, and maintain a memory device context that works as a local buffer for images? The idea is to maintain some large images in local DCs and bitmaps, and only bitblt them to screen in OnDraw().
What I did so far was was to define CDC and CBitmap objects as members of my View class, and then tried to initialize them with the sequence that begins at "// Initialize buffer". I placed that sequence in either OnInitialUpdate, or PreCreateWindow, or OnPrepareDC, or the view constructor, to no avail. The code always crashes in OnDraw, and I've noticed that the m_hDC member of myDevice is zero at that point.
Obviously, the initialization is wrong and MFC does (too many) things in the background which I'm not aware of.... My question was where can I read about that?
Code:
class CMyView : public CScrollView
{
// ...
CDC myDevice;
CBitmap bmp;
CBitmap *oldbmp;
};
// Initialize buffer
CDC* pdc = GetDC();
myDevice.CreateCompatibleDC(pdc);
bmp.CreateCompatibleBitmap(pdc,XMAX,YMAX);
oldbmp = myDevice.SelectObject(&bmp);
myDevice.SetBkColor(BLK);
// Initialize buffer - end
Thank you,
Cris.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|