a new drawing not erase previous drawing?

visual studio c++ 6.0, mfc, graphics



in my program  a new drawing erases previous drawing. How to manage that all
that is drawn stays alive on the window? And is not erased when the window
is covered by another window, as well. And that the image does not
flicker...



Those last two have from time to time appeared in my attempts to solve the
first problem.  And that I didn't manage at all - make the first drawing,
then the second, see them both at the same time on the window.



I have tried the following and maybe more: Invalidate(false),
InvalidateRect(false), override OnEraseBkgnd, SendMessage(WM_PAINT, 0, 0),
RedrawWindow(NULL, NULL,RDW_NOERASE), DefWindowProc(WM_PAINT,
(WPARAM)dc.m_hDC, 0).



please help!


0
Andra
6/6/2005 7:50:48 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1611 Views

Similar Articles

[PageSpeed] 6

Andra wrote:
> visual studio c++ 6.0, mfc, graphics
> 
> 
> 
> in my program  a new drawing erases previous drawing. How to manage that all
> that is drawn stays alive on the window? And is not erased when the window
> is covered by another window, as well. And that the image does not
> flicker...
> 
> 
> 
> Those last two have from time to time appeared in my attempts to solve the
> first problem.  And that I didn't manage at all - make the first drawing,
> then the second, see them both at the same time on the window.
> 
> 
> 
> I have tried the following and maybe more: Invalidate(false),
> InvalidateRect(false), override OnEraseBkgnd, SendMessage(WM_PAINT, 0, 0),
> RedrawWindow(NULL, NULL,RDW_NOERASE), DefWindowProc(WM_PAINT,
> (WPARAM)dc.m_hDC, 0).
> 
> 
> 
> please help!
> 
> 

When you want to paint call Invalidate().  Don't do anything else.

In your OnPaint or OnDraw message handler draw all of it.  Not just the 
new part - all of it.  That is the only way.

See the Scribble introductory tutorial that comes with VC++.  You need 
to understand what it does and why.

After you understand those concepts you can improve flicker by following 
the DrawCLI sample code, which shows how to use an off-screen paint buffer.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/6/2005 10:30:50 PM
There are several answers here...
On Mon, 6 Jun 2005 22:50:48 +0300, "Andra" <andraatlatnetdotlv> wrote:

>visual studio c++ 6.0, mfc, graphics
>
>
>
>in my program  a new drawing erases previous drawing. How to manage that all
>that is drawn stays alive on the window? And is not erased when the window
>is covered by another window, as well. And that the image does not
>flicker...
****
Frequently, when you invalidate a window, the default is "TRUE", meaning to erase the
background. The OnEraseBkgnd handler is called, and the default, if you don't override it,
is to simply draw a blank area using the default background color for the window class
(usually white).

To avoid this, you can override OnEraseBkgnd and do nothing, and not call the superclass,
BUT...and here's the catch...you are now responsible in the OnPaint handler to paint any
part of the window that you do not want to remain in whatever bogus state it was left in.
The problem with OnPaint is that you have no idea why it is called; you could have had a
dialog box, including a dialog box from another app, have popped up on top of it, thus
trashing its contents. Or some other window might have partially covered it. Who knows?
You certainly don't. Therefore, you must redraw ALL of the invalidated area, without
exception, every single pixel, or you will end up with trash on the screen.

Flicker avoidance is a more serious problem. For example, the simplest way to avoid it is
to draw the entire image in an offscreen bitmap and BitBlt it onto your drawing surface.
The effect to the user is that if nothing changes, no visible change is seen. If only part
of the drawing had been obscured, the drawing area is clipped so only that part is redrawn
anyway. There can be performance implications with this technique, but unless you know
performance is a problem, you can safely ignore them (and if it IS a problem, you might
end up spending a lot of effort to reduce the problem! The simplest method, by the way, is
to create a clipping region for your bitmap which is identical to the clipping region of
your window).
****
>
>
>
>Those last two have from time to time appeared in my attempts to solve the
>first problem.  And that I didn't manage at all - make the first drawing,
>then the second, see them both at the same time on the window.
****
Be careful about this idea. There is no "first" or "second" drawing. There is only the
window image, and you have to be prepared to draw any or all of it, at any time, without
warning. While logically there is a "first" and "second" drawing, where the "second" is
what appears on top of the "first", you should expect to have to draw both, in that order,
at any time. You cannot assume that any pixel, once placed in the window, will remain
intact. On the contrary, you MUST assume that any pixel can be trashed at an time for any
reason, and you have no control of this. Your responsibility is to see that the pixels can
be re-created on demand.
****
>
>
>
>I have tried the following and maybe more: Invalidate(false),
>InvalidateRect(false), override OnEraseBkgnd, SendMessage(WM_PAINT, 0, 0),
>RedrawWindow(NULL, NULL,RDW_NOERASE), DefWindowProc(WM_PAINT,
>(WPARAM)dc.m_hDC, 0).
****
Invalidate(FALSE) and InvalidateRect(FALSE) would be one solution, but remember, the
system is free at any time to do Invalidate(TRUE) or InvalidateRect(..., TRUE), and you
can't control that. Assume it will happen.

Sending WM_PAINT is not only useless, it is harmful. Under no circumstances, ever, is it
possible to issue such a SendMessage or call DefWindowProc as you show. WM_PAINT messages
are special and can ONLY be generated by the operating system (for example, prior to
sending the message, it has prepared a clipping region for BeginPaint to work on. You
cannot do this yourself; only the system can do this). RedrawWindow will have no effect. I
think you have missed the key Windows paradigm here: any pixel can be erased at any time
for any reason by means you cannot control, and you, and you alone, have complete
responsibility to see that such pixels are correctly redrawn. There is no way to put
pixels on a window and expect they will stay there. They will not. Windows *guarantees*
they will not.
*****
>
>
>
>please help!
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
6/7/2005 1:53:24 AM
Scott and Joseph,



yes, I will paint it all over again.  As there are only four curves to
paint, it means just a couple of copy&paste, some memory consumption (by
huge arrays of points), maybe some processor time.

Another idea I understand is to save the image and next time take it as a
background and paint on it. But will it resize so nicely as it happens now
when resizing the window?



thank you both,

Andra.



P.S. I really don't know what I would do if there were, say, 25 curves...



> visual studio c++ 6.0, mfc, graphics
>
> in my program  a new drawing erases previous drawing. How to manage that
all
> that is drawn stays alive on the window? And is not erased when the window
> is covered by another window, as well. And that the image does not
> flicker...
>
> Those last two have from time to time appeared in my attempts to solve the
> first problem.  And that I didn't manage at all - make the first drawing,
> then the second, see them both at the same time on the window.
>
> I have tried the following and maybe more: Invalidate(false),
> InvalidateRect(false), override OnEraseBkgnd, SendMessage(WM_PAINT, 0, 0),
> RedrawWindow(NULL, NULL,RDW_NOERASE), DefWindowProc(WM_PAINT,
> (WPARAM)dc.m_hDC, 0).
>
> please help!


0
Andra
6/7/2005 10:38:36 AM
Andra wrote:

> Scott and Joseph,
> 
> 
> 
> yes, I will paint it all over again.  As there are only four curves to
> paint, it means just a couple of copy&paste, some memory consumption (by
> huge arrays of points), maybe some processor time.
> 
> Another idea I understand is to save the image and next time take it as a
> background and paint on it. But will it resize so nicely as it happens now
> when resizing the window?
> 
> 
> 
> thank you both,
> 
> Andra.
> 
> 
> 
> P.S. I really don't know what I would do if there were, say, 25 curves...

It is necessary to retain the arrays in memory so you can repaint 
whenever Windows requires you to repaint.  If their size is a serious 
problem you can consider compressing them to pixel coordinates, which 
makes the array size less than 1800.  But I have applications with about 
12 arrays of a million points and there is no memory problem.

Painting to an in-memory image requires a large bitmap buffer, so this 
technique adds another large memory requirement.  It will not resize 
when resizing the window.  It would be necessary to reallocate the 
in-memory bitmap and again paint all the curves onto it.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/7/2005 1:39:00 PM
Reply:

Similar Artilces:

Must buy new computer...Ideas?
Hello to all! Finally my over 10-1/2 year old Dell desktop's extreme slowness has seriously gotten on my nerves and I'm now looking for a new one. (Surprisingly, it's working pretty well otherwise...) Maybe this isn't the right forum? But beside the usual things like RAM and HD GBs, are there things I should be sure to have...or be careful NOT to have on a desktop? After n ot looking into computers for over a decade I feel like a Martian in the Earth. lol! Also, is it possible to transfer to the new one ALL my stuff, including programs, etc.? Do you thin...

Default properties for new folders
How does one set the default properties applied when creating new email folders? Currently, when I create a new folder, it is created with the AutoPreview turned on by default. I'd like to change that do that it is left off by default. It's something of a pain to create a new folder and then go in to customize it's properties. You can do this by editing the Messages view; View-> Arrange By-> Current View-> Define Views... You might want to define a new view yourself and apply that view on first use of that folder. -- Robert Sparnaaij [MVP-Outlook] www.howto-o...

New Email Messages
I just installed Outlook 2007 on my new PC and for some reason the new messages I received can only be received when I press the SEND/RECEIVE BUTTON. My Outlook at work receives these new mail messages as they are received. So how can I configure the system to make that happen? -- The Trail Hiker!! There are two settings within the accounts 1) Send on starting 2) Auto send/receive every xx minutes - set this for 10 minutes "hiker0531" <hiker0531@aol.com> wrote in message news:87259C7A-5C07-4846-BF61-DE3F98345D21@microsoft.com... >I just installed Outlook 2007 on my n...

Prevent new comments on old posts in sharepoint blogs
How do I stop comments on certain posts in a SharePoint blog? I have removed permissions to the specific post to the lowest possible access and people can STILL post a comment. If I uncheck one more item in the list of permissions, the users can no longer see the post. Any suggestions? ...

Unable to open "New" window to write email.
I am using Microsoft Outlook in Office 2003. It has been working great until today. When I click "New" to write a new email I get an error window : The messaging interface has returned an unknown error. If the problem persist, Restart Outlook. I have tried this several times, even restarted the computer to no avail. Anyone have a solution???? ...

New Location/New setup
Currently I'm downsizing our office, and moving to a new location. I'm running MS Server2003 as well as Exchange 2003. Once moved, I will no longer require the server (since I am setting up a home office). Are there currently any steps or procedures available to correctly shutdown one office...and basically setup a home office with no exchange server. Also I will be removing the current pc's from the Domain, and setting up a few in a workgroup. I would like to receive emails from the other employees for time being until I completely cancel this email account. I already have a...

A Short Video on Adding/Editing New Customers
If capturing customers at the POS is important to you, take a couple of minutes and watch this video. This application also allows for edit of Global customer information in HQ installations. http://www.retail-pos.com/ReverseLookup.wmv Contact us for detailed info and demo. sales(at)retail-pos.com www.retail-pos.com It would be nice if you could encode the videos with a more common codec, and not in wmv format. This requires the GTM3 codec (GoToMeeting). Windows Media Player 11 doesn't automatically download the codec, and I'm not going through the trouble to download and in...

How do I activate the new mail button
When I start Outlook, the "New", "forward", "reply" and "reply to all" buttons are not active which means I can not send mail. I have no problems receiving mail. Also, on web pages with email links, when I click on them, the Outlook application is not launched which is almost certainly related to this. I think I'm missing something very simple here! Are you in a mail enabled folder? Do you have an active email account installed? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert...

Style available all sheets new or old
I need a custom style that is available in all spreadsheets, new or old. I can set style and save it in book.xlt in xlstart, but that only works for new workbooks, and doesn't work with old spreadsheets when I call them up. I want to be able to select a group of cells, or column or row and apply a setting for negative numbers to have brackets. I am using Excel 2000. I even tried saving the style in personal.xls, but that doesn't work as it is hidden. Do I have to use a macro? And if so what would it be? Thanks One way: Public Sub MergeStyles() ActiveWorkbook....

Excel drawings with Hyperlink
Hello: I would like to create a hyperlink when a particular serial number is selected in a cell. Is there a way to create small drawings in excel and have those drawings pop up (or via hyperlink) when a given serial number is selected from a cell? I have created drawings in Paint and saved them as JPEG images, but when I select a serial number the Paint editor pops up at full screen with a tiny image. Regards, D.Parker What I have done in the past was insert drawings on the worksheet, hide them, then associate VBA code to unhide the desired drawing (picture) and hide all others. ...

Sub Form Assigning New Values to Old Records
I am using a subform within a form to have users update certain fields in the record where the rest remiain locked. On the Main form when the list box (which is bound to a query) is used to select the record set to display in the subform it sometimes takes an old record and assigns a new value to the record. For example it changes the Period field from 9 to 10. Taking a record created in period 9 and assigning a period ten to it which is the selection I make in the list box. Addtionally, it looks like it is taking the first record in the related table to assign this new value to. ...

Drawing tables
Hi, I am trying to draw a table from scratch by using the pen feature to create my table. I am having a hard time drawing the cells within my table. Every time I try to draw a cell, it keeps on drawing another boarder. Is there a trick I am missing on this procedure? Your expertise is greatly appreciated. Joe. Is there are requirement to use the pen feature? Try Insert > Table. I think that will be easier for you. Sandy "Joeman2010" wrote: > Hi, > > I am trying to draw a table from scratch by using the pen feature to create > my table...

Adding new pages
Any thing I do on new pages happens simultaneously on any previous page. Can someone help me please? Can you be more specific? What stencils are you using and what are you trying? John... Visio MVP Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm Need VBA examples? http://www.mvps.org/visio/VBA.htm Common Visio Questions http://www.mvps.org/visio/common_questions.htm "Joanie" <anonymous@discussions.microsoft.com> wrote in message news:4C3642E4-4F2B-4A65-8C00-E9041CE74A37@microsoft.com... > Any thing I do on new pages happens simultaneously on any previ...

Which table will refresh by adding new Account / Contact
Hi, I am new to CRM and trying to update CRM Accounts and Contacts from our Sales Management system. I am using Micorosft Bulk Import utility. I am in preparation of CVS files but not sure what columns do I need in CVS file to complete one Account/Contact record. Could anybody please help. I am .NET expert developer, please let me guide If I could develop CRM by using .NET not CVS Regards Hi Adnan, Microsoft do provide CRM SDK for CRM enhancment using .net. You can download from following url http://www.microsoft.com/downloads/details.aspx?familyid=9C178B68-3A06-4898-BC83-BD14B74308C5...

New messages comes up in Deleted folder
Sometimes when I receive new messages the go to the Deleted folder instead of the Inbox. The messages are from random people...not just one sender. What is the problem? Thanks Check your message rules/filters. "key word" in new mail subject line of body is probably being tagged and filtered to deleted items folder. Regards C. >-----Original Message----- >Sometimes when I receive new messages the go to the >Deleted folder instead of the Inbox. The messages are >from random people...not just one sender. What is the >problem? Thanks >. > ...

New User has admin rights
I just created a new user and assigned her the role of Sales Manager. This role is working correctly for other users with it assigned, but she has admin rights? This is the only role she has assigned.... Any ideas? TIA Metcalf ...

New trend, new business, new year a new beginning
New trend, at start of new year. "If you want things to work different, you must try a different...whatever..." Does that seem obvious? Brighten up with this "reading" and attack the money issue with more gusto! I am finishing my year 2005 with some regrets and some joy. For some the year passed has not been "tip top" in their view. But I believe it has just been very well as the page I shall bring you that has this statement which I believe wholeheartedly: "THINGS ARE UNFOLDING AS IT SHOULD" (paraphrased) I invite you to read the whole "poem&quo...

Creating new row in other table
Dear All, Please teach me, how to make a new row/list in other table by entering number in other table. Sample, In the table A and in the field "Details", I put the number 2 and it automatically creates two rows in table B. Can this be done in MS Access? Thank you for your help. Regards, Maulwy Why? What business need are you attempting to solve with this approach? It's generally considered not very good database design to be creating 'empty' rows in a second table. Why do you want empty rows? And if the number you enter in TableA is a 'limit&...

Drawing Bitmap into CStatic control
Im trying to draw into a CStatic cotnrol (Rectangle type) thats in a dialog. using found examples my OnPaint looks like this: CPaintDC dc(this); // device context for painting CBitmap *bmp,*oldBmp; CDC memdc; BITMAP bmInfo; RECT w; m_templatePreview.GetWindowRect(&w); this->ScreenToClient(&w); if (m_lTemplateID != -1) { //CTemplate::drawTemplatePreview(dc,w,m_lTemplateID); memdc.CreateCompatibleDC(&dc); bmp = CTemplate::getTemplateBitmap(m_lTemplateID); bmp->GetObject(sizeof(BITMAP),&bmInfo); oldBmp =...

AP
What would be the best tool to add a new field in the AP invoice screen to deploy to a client? Extender? Modifier? the ideal would be to add a field for "Job No." that is text info so the user can get some info out on certain jobs that they are paying bills for. thanks -- Linda W. Linda, You can use any tool, really, to accomplish this: - Modifier with VBA. You can add the fields to the window with Modifier, then use VBA and ADO or DUOS to store and retrieve the data. - Modifier with Dexterity. You can add the fields with Modifier, then trigger off the form with Dex...

Button "New Account" in Sub-Accountsview opens Parent account
When I open an account, and then go to the subaccounts of that account, I click on the Button "New Account" to create a new subaccount for this account. Instead of opening a new account form, the application opens the original Account form. Anybody an idea how this is possible? Regards, Sanne groenhof -- MSCRM, hosted as ASP, and configured for your business. Sanne, Have you installed any specific toolbars in your Internet Explorer? Like google toolbar/msn toolbar? -- Rob Bakkers, Avanade Netherlands "Sanne" wrote: > When I open an account, and then go to...

new to old
hi, A web designing company has just done us a website, and part of it includes the database of our stock. They have written/created it on access xp, but we have only got and old version of access. Can we open/use/update files written in access xp on an older version of access? thanks very much jethro Hi Jethro, It depends. By default Access 2002 (XP) uses the Access 2000 file format, so if you have Access 2000 you may be able to use the database as is. However, if the database is in the form of an mde file created by Access 2002 it will be in Access 2002 format. Otherwise (i.e. if t...

New Accounts on Exchange 2003
This week I entered two new people and the reciepent policy is not providing the necessary email addresses. Of course without those, the GAL does not get updated and no one can email them. I have Exchange 2003 running on Server 2003 with a w2k AD. Any suggestions for jump starting the default reciepent policy? Omer, Thanks for the response. The Recipient Update Service was scheduled for once an hour. I changed it to every 15 minutes. I also tried the "Update Now" feature. For both of these, there were no events generated. I remember setting up trace logs earlier this y...

new columns created from "&nbsp;"
I have a bunch of data in a column and it is "separated" by "&nbsp;". The data was imported from an online database. Is there a way to create columns within the current workbook from where the &nbsp; appears? (much like importing a text file) TIA, Greg Greg Wilker wrote: > I have a bunch of data in a column and it is "separated" by "&nbsp;". > > The data was imported from an online database. > > Is there a way to create columns within the current workbook from where the > &nbsp; appears? (much like importing a te...

create new folder is always greyed out-why?
"Create new folder" is always greyed out-why? ...