 |
|
 |
I am using C++ and have cut and paste the code into a new class, and changed everything as required. However it isn't compiling at the moment.
What I can see is that whenever pDC points to something (e.g SelectObject, Arc) as I hover over these words nothing appears , and I have a lot of errors saying "CMemDC does not have an overloaded member 'operator->'" and eg. "'Ellipse': is not a member of 'CMemDC'".
Has anyone any ideas how to solve this please?
|
|
|
|
 |
|
 |
Partial success. It is compiling when I use IMPLEMENT_DYNCREATE and DECLARE_DYNCREATE, but it still flickers
Does anyone know of possible reasons why?
Thankyou for any help
|
|
|
|
 |
|
 |
There is an error at IMPLEMENT_DYNCREATE which says "Cannot instantiate......"
Sorry for so many questions. I dont know why I'm getting so many problems.
|
|
|
|
 |
|
 |
In the example, the usage is :
CMemDC pDC(pdc) //pdc is a CDC*
Note pDC is an object, pdc was a CDC*.
You must change all your code from pdc->XXXX to pDC.XXXX
Alternatively, do:
CMemDC* pDC = new CMemDC(pdc);
// -- your code
delete pDC; //if you don't delete, the destructor will not be called
//the code uses the destructor to repaint.
|
|
|
|
 |
|
 |
:) I WOULD ASK SOME HELP IN AREA DRAWING A PICTURE AND GETTING A FORM OF A BRACE.
JEFF WILSON
|
|
|
|
 |
|
 |
thank you Keith, CMemDC is really cool and easy to use. It help me out with the anti-flickering problem. But another problem have puzzled me a lot. After trying everything, i just cannot display non-solid-color background in scroll-view correctly, can you help me Keith.
chenzd
|
|
|
|
 |
|
 |
I used your memdc and it worked and helped me a lot. I thank u very much;)
Murali.S
|
|
|
|
 |
|
 |
I have data (2D Array) that has less or higher size than the window it shall be painted to. So the data needs to be streched of compressed.
Such things should be possible using SetViewportExt in MFC.
Now I wonder howto use this with CMemDC
Matthias
|
|
|
|
 |
|
 |
Hi,
I do not know if I understand your question well. But I used a CScrollView for a college project and got something to let it work good.
Its a 'simple' drawing application which uses MouseMove en MouseDown events, in that events I managed to get the CPoint to 'point' to the right place like this (put on top inside events):
void CScrollView::OnMouseMove(UINT nFlags, CPoint point) // Or other Mouse event
{
// Convert relative point to absolute point (because of CScrollView)
CPoint relativepoint = this->GetScrollPosition();
point.x = point.x + relativepoint.x;
point.y = point.y + relativepoint.y;
}
And to only draw the right place in the CScrollView I use (OnDraw event):
void CScrollView::OnDraw(CDC* pDC)
{
// If on display, not printing
if (pDC->GetDeviceCaps(TECHNOLOGY) == DT_RASDISPLAY) {
CPoint point = this->GetScrollPosition();
pDC->SetViewportOrg(-point.x, -point.y);
}
}
The teacher checked our project a couple of hours ago and rated it 9 out of 10! Its not only drawing, but some business rules too, and electric schema. Now finish this year of college!
I hope I helped some people. Maybe if the author of this article can update the article this can be mentioned underneath a CScrollView section.
Thanks for this MemDC, Keith Rule!
And b.t.w., C++ is a pain in the ass.
|
|
|
|
 |
|
 |
just for the record
it doesnt work with MM_LOENGLISH, and MM_HIMETRIC, im postitive about those two.
in MM_LOENGLISH, your method "mirrors" and enlarges an image amd puts it to bottom left corner, with center outside view
btw, when setting erase back to false one has to refresh backround on starting an app, on maximizing, on size changes and so on. otherwise areas that are not drawn on are transparent.
I would suggest use of InvalidateRect(). I would also do it but i have many objects and MM_LOENGLISH mode su there would have to be a lot of error-prone math when calculating surrounding rects to invalidate
regards
kresimir
|
|
|
|
 |
|
 |
This code should work on windows CE, as long as you remove these calls
SetMapMode(pDC->GetMapMode());
SetWindowExt(pDC->GetWindowExt());
SetViewportExt(pDC->GetViewportExt());
and
SetWindowOrg(m_rect.left, m_rect.top);
|
|
|
|
 |
|
 |
Keith,
The following copyright notice:
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: keithr@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
suggests that users of this source code or its derivatives can incorporate its object code into the distribution of commercially available software products.
Can you confirm?
Thank you.
|
|
|
|
 |
|
 |
Feel free to use it how ever you like. Commercial use is fine.
Keith Rule
|
|
|
|
 |
|
 |
...something like device context resource error or,
...memory leak, blah...
|
|
|
|
 |
|
 |
Hi, I'm trying to use it in my application derived CScrollView class,but it doesn't work . when the mouse left button is pressed down ,the images should have been displayed will flash past ,why?
How to resolve this problem?
Could anyone help me ?
Any help will definitely be appreciated.
-- modified at 18:56 Thursday 2nd November, 2006
|
|
|
|
 |
|
|
 |
|
 |
will flash past? I do not understand what you mean with this, with my reasonably good english vocabulary.
Maybe, if still needed, you can fix your problems with my message (see a couple of threads above):
http://www.codeproject.com/gdi/flickerfree.asp?df=100&forumid=55&select=2091984#xx2091984xx
|
|
|
|
 |
|
 |
thanks from germany
for this pretty good usefull thing
|
|
|
|
 |
|
 |
First of all, this is a great class - very useful. I did have a problem, though. I am creating a control to put in Word (via insert object), but the control didn't work the first time I tried it. After some debugging, I found that the problem is with the CreateCompatibleDC statement in the CMemDC constructor - it will return 0 if this control is in a Word document. I changed CreateCompatibleDC(pDC) to CreateCompatibleDC(NULL) and it worked, but I don't think that's a good workaround. I'm not sure why CreateCompatibleDC would fail - I checked pDC, and it supports raster operations (which was the only issue MSDN acknowledged). Does anyone know another reason CreateCompatibleDC would fail?
|
|
|
|
 |
|
 |
hi, Keith,
Your MemDC is wonderful.
Maybe many programers use your MemDC in a scrollview ,such as me. But I don't know how to use it in a scroll view. Can you write it and add to this article? I think this article will be more perfect .
Thanks.
|
|
|
|
 |
|
 |
Brilliant class, perfectly simple to use and does the job very well.
Coding as it should be- elegant, neat and simple. Well done!
Dave Kerr
codechamber@hotmail.com
http://www.codechamber.com
|
|
|
|
 |
|
 |
I'm glad to hear it was helpful.
Keith Rule
|
|
|
|
 |
|
 |
Is there anyway to speed this up ? eg, some of the initialization done in the constructor, could this be done just once, instead of with every re-draw.
Thanks for any replies, etaylor_1@hotmail.co.uk
|
|
|
|
 |
|
 |
edwardking wrote: Is there anyway to speed this up ? eg, some of the initialization done in the constructor, could this be done just once, instead of with every re-draw.
I've done roughly what you suggested in the past and I'm sure others have too.
My experience (though my memory is vague because I haven't used MFC in several years) was that off-screen drawing is much slower than on-screen drawing. I presume is because you don't benefit from any graphic hardware acceleration with off-screen rendering.
I found that caching the previous rendered data was quite valuable for dealing with redraws when nothing changed which required rerendering. Also, prerendering static portions of the screen into a bitmap and then blitting it into the bitmap before rendering the non-static elements has been helpful to me too.
Another helpful thing to do is only draw inside the clip rect. This limits rendering to a much smaller area.
As I recall, my experience was that these types of changes had much more effect than caching the memdc.
I'd encourage you to post your experience here and if you come up with a nice generalized implementation then please write a codeproject article.
Keith Rule
-- modified at 12:10 Friday 21st July, 2006
|
|
|
|
 |
|
 |
Has anybody accomplished this? I want to put a simple graph in a dialog based application in Visual C++. Sounds simple enough, but when this MemDC class is added and the instructions are followed--the background of the entire dialog window goes blank. The "Ok" and "Cancel" button are fine, but "Hey! They flicker." Cute huh?
I have tried this method here. I have tried my own code. I cannot get it to work.
Has anybody developed a flicker free dialog-based application control for drawing simple lines (for example graphing aduio signals like Windows Media Player does). Just a simple line graph of X,Y pairs?
Anybody? And please share your code.
Thank you.
A8
|
|
|
|
 |