• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1608
  • Last Modified:

How to draw into memDC, then show it

I would like to:
1. memDC.LineTo(60,60)
2. Determine the extension of memDC
3. draw memDC to my window screen

Is this possible without using bitmap?

If bitmap is needed to use, now I can
handle it but must first determine the
extension of bitmap first, then draw on
memDC. But I want to first draw on
memDC, then create a bitmap with the
correct needed extension, then draw
bitmap on window.

Please write sample code.
I use VisualStudio 6, MFC, c++

Thanks, Tomas
0
tko092397
Asked:
tko092397
1 Solution
 
tko092397Author Commented:
Edited text of question.
0
 
migelCommented:
Hi!
You can not transwer data from one DC to another without bitmaps.

When you use memoryDC
You must before create bitmap with required dims. select it into thebmemory context? draw into the context, BitBlt from memory context to the destination context and then select memory context old bitmap back.
for example:
{
CDC dcDisplay;
dcDisplay.CreateIC("DISPLAY", "", "", NULL)
CDC dcMem;
dcMem.CreateCompatibleDC(NULL);
CBitmap bm;
bm.CreateCompatibleBitmap(&dcDisplay,100,100 );
CBitmap* pbmOld = dcMem.SelectObject(&bm);
/* drawing routines here width using dcMem */
dcDest.BitBlt(...); //dcDest is the DC where to your image will be transfered
dcMem.SelectObject(pbmOld);
dcDisplay.DeleteDC();

}
0
 
ZoppoCommented:
Hi tko,

perhaps you'd prefer drawing to a metafile in memory and than draw this metafile to your dc. For this see help for CreateMetaFile, CloseMetaFile and CDC::PlayMetaFile()

ZOPPO
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
chensuCommented:
A memory DC without a bitmap selected into it can't be used for drawing.
0
 
jclanzCommented:
Hello,
I give you my code in CMyView::OnDraw() to avoid flicking. You can use it to draw all you need in a bitmap and copy this bitmap to the screen.

void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// traw to memory to avoid flicking
CRect rect; GetClientRect(&rect);
CDC dcMem; dcMem.CreateCompatibleDC(pDC);
CBitmap bitmap; bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
CBitmap *pOldBitmap = dcMem.SelectObject(&bitmap);

// draw backgroung, but implement OnEraseBkgnd() to do nothing
CBrush brush(RGB(255,255,255));
dcMem.FillRect(&rect, &brush);
brush.DeleteObject();      

// TODO: Your drawing using dcMem

// copy bitmap to screen
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMem, 0, 0, SRCCOPY);

dcMem.SelectObject(pOldBitmap);
bitmap.DeleteObject();
dcMem.DeleteDC();
}

BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

regards, jean-claude.
0
 
tko092397Author Commented:
Thanks!!

Tomas
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now