Solved

Drawing in a window?

Posted on 2000-02-21
6
232 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now