Link to home
Start Free TrialLog in
Avatar of tko092397
tko092397

asked on

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
Avatar of tko092397
tko092397

ASKER

Edited text of question.
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();

}
Avatar of Zoppo
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
A memory DC without a bitmap selected into it can't be used for drawing.
ASKER CERTIFIED SOLUTION
Avatar of jclanz
jclanz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!!

Tomas