 |
|
 |
When this class is used in combination with MFC Feature Pack for Visual C++ 2008[^] it must be renamed (e.g. into CMemoryDC) because Microsoft now has defined its own CMemDC class.
Otherwise class redefinition errors occur:
error C2011: 'CMemDC' : 'class' type redefinition
cheers,
Michael
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
|
|
|
|
 |
|
 |
mykel wrote: When this class is used in combination with MFC Feature Pack for Visual C++ 2008[^] it must be renamed (e.g. into CMemoryDC) because Microsoft now has defined its own CMemDC class.
When I first wrote CMemDC I wondered why MFC didn't offer this feature. It seemed like a pretty obvious need. Now it appears that MFC does using an internal, not well documented class. I guess that's progress.
BTW- Thanks for the renaming suggestion. I'm sure this will save folks some pain.
Keith Rule
|
|
|
|
 |
|
 |
Hi Keith!
Yes, I thought it would be good to add a comment to your article because other developers will certainly encounter the same problem. And up to now there is not so much info about the MFC Feature Pack available.
Furthermore, I don't think it was Microsoft itself who introduced CMemDC... but that's pure speculation. Since they bought the new components from BCGSoft[^] I think they developed it (see MFC Update Powered By BCGSoft[^]).
And thanks for your fine class!
cheers,
Michael
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
|
|
|
|
 |
|
 |
I ran into this error using 2010. So if MFC now includes CMemDC do we still need this class? Or do they have completely different uses?
|
|
|
|
 |
|
 |
Oh yes. I just did a "global" search and replace. I named my class CRuleMemDC just so I dont forget the big man.
Hope you all do the same......
Thanks to KR.
bart
|
|
|
|
 |
|
|
 |
|
 |
myDlg->ShowWindow(SW_HIDE);
do something...
myDlg->ShowWindow(SW_SHOW);
|
|
|
|
 |
|
 |
Hey:
I've been searching through the forums/googling for days now. I am working with a CDialog based application in MFC that has an MSFlexgrid control on the main dialog form. In an OnTimer routine, I am drawing updates to the MSFlexgrid control every ~100ms. This leads to flickering, because the window is not being double buffered.
I have attempted to include memdc.h in my dialog-based code even though the tutorial presented at The Code Project is written only for MFC application-based projects. I have overwritten the OnPaint() function (as opposed to the OnDraw() function- which is not available in CDialog based apps) with no success. Also note that the MSFlexgrid control does not have an OnDraw function associated with it as well...
Any ideas?
Thanks.
-Tom
|
|
|
|
 |
|
 |
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
|
|
|
|
 |