[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Drawing in a window?

Hi there
I would like to display the contents of a matrix in a window.
if I use code like this:

CClientDC dc;
//do drawing
dc.SetPixel(...);

It works of course, but I do not want to draw directly into the window. Instead I would like to draw to a CDC (i guess) and then blt the contents into the window causing all the changes to happen at once instead of one pixel at a time.

I have tried something like this:

CCLientDC dc;
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
//do drawing
dcMem.SetPixel(...)
dc.BitBlt(0, 0, Width, Height, &dcMem, 0, 0, SRCCOPY);

but it does not work (no change in the window)

How should I do it?
(maybe creating a bitmap - how?)

Jacob
0
jacobkristensen
Asked:
jacobkristensen
  • 5
1 Solution
 
WynCommented:
The problem is you must select a bitmap into the Memory Device Context.
0
 
WynCommented:
Use the CreateCompatibleBitmap().
Code here:
0
 
WynCommented:
CCLientDC dc;
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,1,1);
CBitmap* pOldBmp = dcMem.SelectObject( &bmp );
//do drawing
dcMem.SetPixel(...)
dc.BitBlt(0, 0, Width, Height, &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject( pOldBmp );
dcMem.DeleteDC();
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WynCommented:
Btw: the 1,1 above is imaginary.
0
 
jacobkristensenAuthor Commented:
Great! Just what I needed
Thank you Wyn

Jacob
0
 
WynCommented:
You are welcome:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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