• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • 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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

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

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