Solved

redrawing text and graphics of a window

Posted on 2002-03-17
14
261 Views
Last Modified: 2013-11-20
If I draw some graphics or text in a window using DC classes, I can't be able to regain the content after minmizing and maximizing or if another window overlaps, they are lost.  Pls tell me What I should do to redraw the contents.

Venkataramanan
0
Comment
Question by:venkataramanan
  • 2
  • 2
  • 2
  • +5
14 Comments
 
LVL 2

Accepted Solution

by:
shilpa_Jb earned 25 total points
ID: 6876038
Hi,
U should write ur code in the WM_PAINT message i.e override this message in the window class.
In OnPaint() of that window place ur code to draw grahics or to write text.
Hope that helps u.
-Shilpa
0
 
LVL 1

Expert Comment

by:pkreddy
ID: 6876162
use Ondraw(CDC *pDC) of your view class to draw inthe client area, this function is called for every WM_PAINT message.
0
 

Author Comment

by:venkataramanan
ID: 6879128
i am having a static control in a dialog box and i like have to free hand drawing in that.  I am capturing the mousedown and mousemove events and setting pixels in that static control.  I want that drawing to be persistent.  what i have to do for this
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 6879332
You need to store the mouse/keyboard actions somehow and then 'replay' this store everytime you need to repaint.  See the Scribble example that comes with VC++, if I remember correctly that does the same as you are doing just in a view.
0
 
LVL 1

Expert Comment

by:Mazen
ID: 6879491
Hi Venkataramanan ,
 you can store your drawings in a metafile and then eveytime you refresh(minimze or maximize) you will play back the graphics by calling the method
 PlayMetaFile(myfile)which should be called from the
 OnDraw().
N.B:The metafile can store DC class graphics.
Write a comment for me if you're interested and  want me to give you the whole code.
Good luck
Bye
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Crius
ID: 6881148
Hi! I recommend you first CreateCompatibleDC() of your screen (GetDC() of your display), then CreateCompatibleBitmap() (And pass in the compatible DC).

Once you have this, all drawing, do it to the Bitmap instead (You can just get the DC of the Bitmap anytime to make changes to it). Then, when you have to display the bitmap on the screen, in the OnDraw(), take your Bitmap DC, the and CDC passed to you in the OnDraw, and do a pDC->BitBlt() passing in the bitmap's DC.

This is the simplest, fastest, and most easily understood method I know of.

Good luck, questions?
0
 

Expert Comment

by:surki
ID: 6882131
Dear Mazen,

I will be very much happy if u give me the code.

Thanks in advance.

-Venkataramanan
0
 
LVL 1

Assisted Solution

by:Mazen
Mazen earned 25 total points
ID: 6886301
Hi Venkataramanan, ok there goes the code:
first in the Doc.h write in the public area:
CMetaFileDC* pMetaFileDC;
and in the Doc constructor write this:
pMetaFileDC = new CMetaFileDC();
pMetaFileDC->Create();
Now in the methods that are used to draw graphics you should mirror every drawing to the metafile like this, for example if you're drawing ellipse:
pDC->Ellipse(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
also write with it:
pDoc->pMetaFileDC->Ellipse(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
and so on...
and don't forget to declare the pointer pDoc to Doc using GetDocument() in these methods
Now to play the metafile again at refreshing,add the following code to the OnDraw() method:
{
HMETAFILE MetaFileHandle = pDoc->pMetaFileDC->Close();
// to play a metafile you must close it first
pDC->PlayMetaFile(MetaFileHandle);
CMetaFileDC* replaceMetaFile = new CMetaFileDC();
replaceMetaFile->Create();
replaceMetaFile->PlayMetaFile(MetaFileHandle);
// this is a back up metafile before deletion
DeleteMetaFile(MetaFileHandle);
delete pDoc->pMetaFileDC;
pDoc->pMetaFileDC = replaceMetaFile;
}

I hope this helps you
Best Regards
Mazen
0
 

Expert Comment

by:amarzee
ID: 7023724
Try to use the metafile for storing drawing actions and in OnDraw method play that metafile content.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11116232
My comment should have given him all he required.
0
 
LVL 3

Expert Comment

by:Crius
ID: 11120962
I think most of ours did, one way or another.

The question is likely abandoned because it got answered satisfactorily. :\
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 53
Modbus - whats the maximum I can store in one register? 4 78
noX challenge 17 92
how to split multiple lines delimiter : 8 79
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

15 Experts available now in Live!

Get 1:1 Help Now