 |
|
 |
Hello
Env: VS 2010
I use CMemDC in a CScrollView-based app.. Works great when zoom is 100%. Flicker is gone.. Works great also when I change the zoom ratio from 25% to 400%... But, with a zoom ratio higher than 100%, background is not updated correctly when I scroll the view using the scroll bars
Thanks for any clue ...
|
|
|
|
 |
|
 |
Very simple and effective. Thanks!
|
|
|
|
 |
|
 |
Hi Keith,
I'm trying to add a couple of new features to our old MFC application (which has been upgraded to MFC 10). I want to be able to use CMFCToolBar. To use this class I need to include "afxtoolbar.h", which in turn includes "afxcontrolbarutil.d". This header declares a class with the same name as yours "CMemDC". So understandably, when I compile I get compile error C2011.
The MFC class is meant for internal purposes only so I can't use that where I use yours. I thought that I could somehow add namespaces in the code that includes the headers but this hasn't worked for me so far. The only other is to modify your CMemDC class and put it in a namespace, or rename it to something else.
How would you recommend getting around this problem?
Cheers,
Jason
|
|
|
|
 |
|
 |
Just rename the class and file to something different (like CCustomMemDC and CustomMemDC.h). I have done that and it works for me.
|
|
|
|
 |
|
|
 |
|
 |
Perfect, easy solution. Extremely easy to integrate!
|
|
|
|
 |
|
 |
Man, words can't express how grateful I feel for your article. I have an MFC image manipulating application and it flickered like crazy when modifying brightness using a scroll bar control. Now it looks perfect.
Thanks!
|
|
|
|
 |
|
 |
It's the perfect example for what I needed: eliminating flickering when working with Device Contexts.
|
|
|
|
 |
|
 |
I tried to follow steps to use CMemDC class but I found I got memory leak in OnPaint method once override OnEraseBkgnd method. I did not do anything with CMemDC yet. The following is code snap. Could you please give me some clue?
void CDoubleBufferMemorryLeakDlg::OnPaint()
{
CPaintDC dc(this);
}
...
BOOL CDoubleBufferMemorryLeakDlg::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
|
|
|
|
 |
|
 |
Hello everyone,
I'm trying this CMemDC stuff in a sliding-graphic test application...
I made a CWnd base class where I have OnPaint()...
At creation of the component I set:
CPaintDC dc(this);
CRect rc;
::GetClientRect(this->m_hWnd, &rc);
dc.SetBkColor(RGB(0,0,0));
dc.SetMapMode(MM_ANISOTROPIC); <--- so in this way I would let device context to do
the hard stuff about repainting scaled
dc.SetWindowOrg(rc.BottomRight()); <--- since it's a sliding from right to left
dc.SetViewportOrg(0,0);
dc.SetViewportExt(-1, -1);
dc.SetWindowExt(1, 1);
in the OnPaint() before to call OnDraw() I recall:
CPaintDC dc(this);
CRect rect;
::GetClientRect(this->m_hWnd, &rect);
SIZE sz = rect.Size();
dc.SetViewportExt(-sz.cx, -sz.cy);
dc.SetWindowExt(sz.cx, sz.cx);
but the graphic when repainted isn't rescaled to new dimensions of client ( using PolyLine(...) )... on the other hand since I settled SetBkColor(RGB(0,0,0)) at start the CMemDC should get back the black background color and refill it but it shows white background so I have to implement FillRect() in the OnDraw() right before to draw stuffs...
Any idea?...
Thanks a lot
Ciao, Luigi
|
|
|
|
 |
|
 |
Hi,
I would like to know if reusing this piece of codes in commercial product will have any licensing issue ?
Please help...
Thank you.
|
|
|
|
 |
|
 |
I don't have any problem with the code being used in a commercial application.
Keith Rule
|
|
|
|
 |
|
 |
Keith,
I am a software engineer for IBM.
We have downloaded code samples from "The Code Project" website, specifically http://www.codeproject.com/KB/GDI/flickerfree.aspx.
We have used CMemDC class (and modified it). We have stated in our source code that we are free to use your code as long as "Keith's original copyright is retained". We have kept your copyright in our source code.
Besides the copyright requirement, can you give us permission to use your code?
Do you have some sort of open source license that you hand out to those of us that download code from www.codeproject.com?
Estel Dandridge
IS Release Manager and IDM Project Advisor
(714) 327-7604
|
|
|
|
 |
|
 |
Estel,
I'm happy you found this useful. You are free to use this in a commerical product.
Keith
Keith Rule
|
|
|
|
 |
|
 |
Keith,
Our legal department is not approving the use of your source code in our product with the CPOL license.
Can we use an MIT and BSD style license?
Estel
|
|
|
|
 |
|
 |
I have compiled the program on W7 with vs2008sp1. The same computer on xp cpu usage is low in w7 high. Any help.
|
|
|
|
 |
|
 |
I am using CMemDC in my app and now would like my app to support Right-to-Left languages (Arabic, Hebrew) by calling ::SetProcessDefaultLayout(LAYOUT_RTL) in InitInstance(). I found out that CMemDC will no longer work and all my windows that use CMemDC will not draw correctly (draw blank/garbled). I experimented by replacing .left with .right in CMemDC implementation but that does not seem to make it work.
www.zidsoft.com
|
|
|
|
 |
|
 |
For the record, the problem in RTL mode is that the LPtoDP call sets m_rect to have negative width, which means the subsequent CreateCompatibleBitmap call doesn't work. If you wrap an abs() round the second parameter to CreateCompatibleBitmap, then it works OK. You don't need to change anything in the later BitBlt because by that time DPtoLP has flipped m_rect back again.
|
|
|
|
 |
|
 |
Thanks for the good directions. It now works but not 100%. One anomaly I observed is with hatching where I am using gdiplus to fill some place holder cells
HDC hdc = pDC->GetSafeHdc();
Graphics g(hdc);
HatchBrush brush(
(HatchStyle) CInSyncOption::Get()->GetHatchStylePlaceHolderCol(),
color.crText,
color.crBkgnd);
g.FillRectangle(&brush, rect.left, rect.top,
rect.Width(), rect.Height());
The code is identical and in both cases I am using UI mirroring but when I use MemDC the hatched area incorrectly appears at the wrong place of the CListCtrl.
Here is two pictures with and without MemDC both with UI mirroring
www.zidsoft.com/temp/RTL_without_memDC.jpg
www.zidsoft.com/temp/RTL_with_memDC.jpgwww.zidsoft.com
modified on Tuesday, February 23, 2010 9:21 PM
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
|
 |