 |
|
 |
Good Article!
|
|
|
|
 |
|
 |
I cant stop presenting you my respect.
Thats what my application is looking for since about 2 years.
God bless you.
Thanks
Raymond
|
|
|
|
 |
|
 |
it's cool...
thanks...
it helps me...
From Indonesia with love..!!
|
|
|
|
 |
|
 |
Has anyone else had difficulty with CMemDC and Pocket PC(2005) Dialogs?
Specifically, in writing my own controls, as well as Chris Maunder's Grid Control, when double buffering is used, the Menu bar on the bottom gets corrupted. When you tap either button, they refresh and appear normal.
This problem is even more clear when you start to change orientation. Part of the screen turns to garbage.
The only way I've helped this is to remove, then add the menu back, clearly not the best way.
Any thoughts, advice, tips?
Steven.
|
|
|
|
 |
|
 |
Hi,
I have applied your excellent code to my custom CStatusBar control and I get flicker free Status Bar panes by overloading the OnPaint() and OnEraseBkgnd() functions in my derived CStatusBar class like this:
void MyStatusBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CStatusBar::OnPaint() for painting messages
CRect rect;
GetClientRect(&rect);
CMemDC memDC(&dc, &rect);
DefWindowProc(WM_PAINT, (WPARAM)memDC->m_hDC, (LPARAM)0);
}
BOOL MyStatusBar::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
However, the bar now shows without its borders getting painted - they are displayed as blank white areas. Any ideas what I should do to get them repainted?
Thanks,
Bruce
|
|
|
|
 |
|
 |
OK, I posted my woes elsewhere and got a reply -> in order to use CMemDC.h in your controls you need to change the call to 'FillSolidRectangle(...)' in CMemDC.h:
FillSolidRect(m_rect, pDC->GetBkColor());
to this:
HBRUSH hbrBackGrnd = (HBRUSH)GetClassLong(pDC->GetWindow()->GetSafeHwnd(),
GCL_HBRBACKGROUND);
::FillRect(GetSafeHdc(), &m_rect, hbrBackGrnd);
Hey Presto! the control borders now get repainted.
|
|
|
|
 |
|
 |
how do I send the MemDC to child windows to paint upon, without having to change their code?
thanks
Todd.
|
|
|
|
 |
|
 |
Keith,
I've been using various incarnations of your CMemDC classes for a number of years, on a number of different projects.
Your code has saved me an inordinate amount of time / effort / pain.
Thank you.
|
|
|
|
 |
|
 |
Hi,
I tried out this class. It works fine. Also the usage is very easy. But one little thing is strange. When I move the window itself, or I resize the top edge of the window, it does flicker. I dont know why ? When I resize the left edge, no flickering is done. I can not explain, why it is flickering, when I move the whole window. I looked for the messages (with Spy++), but did not found any different behaviour.
UseCase:
- Make the changes described in this article (use of CMemDC).
- Do add following code in OnDraw:
for (int i = 0; i < 200; i++)
{
pMyDC->MoveTo(0, i * 2);
pMyDC->LineTo(500, i * 2);
}
- Move the whole window --> Flickering !
Any ideas ?
|
|
|
|
 |
|
 |
Did you change the code for message handler of WM_ERAGEBKGND?
Without changing this part, you can not avoid flickering.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |