Solved

Drawing in a window?

Posted on 2000-02-21
6
267 Views
Last Modified: 2013-11-20
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
Comment
Question by:jacobkristensen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 50 total points
ID: 2542370
The problem is you must select a bitmap into the Memory Device Context.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2542385
Use the CreateCompatibleBitmap().
Code here:
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2542394
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
Independent Software Vendors: 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!

 
LVL 5

Expert Comment

by:Wyn
ID: 2542401
Btw: the 1,1 above is imaginary.
0
 
LVL 1

Author Comment

by:jacobkristensen
ID: 2543134
Great! Just what I needed
Thank you Wyn

Jacob
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2544486
You are welcome:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
child constructor and parent constructor, overriding and overloading 6 93
scoreUp challenge 14 72
how to split multiple lines delimiter : 8 129
Adjust the codes 3 59
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question