CMemDC help
-
I'm having problems with the CMemDC inside a CStatic derived class.
void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; }
If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
-
I'm having problems with the CMemDC inside a CStatic derived class.
void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; }
If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
-
hi, why do you use CMemDC, and not directly dc ? HBRUSH oldbrush=(HBRUSH)dc->SelectObject(brush); HPEN oldpen=(HPEN)dc->SelectObject(pen); dc->Rectangle(&r);
Double Buffering...
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
-
Double Buffering...
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
Try this in OnDraw( CDC* dc ) like this CMemDC pDC(dc); if( !pDC->IsPrinting() ) { } "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
-
I'm having problems with the CMemDC inside a CStatic derived class.
void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; }
If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
I've changed it to a custom control derived from CWnd. Works fine now.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
-
I'm having problems with the CMemDC inside a CStatic derived class.
void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; }
If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
* If you want to set the background color, you should have a look to this article: http://www.codeproject.com/miscctrl/colorcontols.asp?target=ccolorstatic[^] On the use of MemDC: * To avoid flickering, OnEraseBkgnd should return FALSE. * you should use pointers with CDC::SelectObject
CBrush *pOldBrush = memDC->SelectObject(&brush); CPen *pOldPen = memDC->SelectObject(&pen);
...memDC->SelectObject(pOldBrush); memDC->SelectObject(pOldPen);
Every gun that is made, every warship launched, every rocket fired, signifies in the final sense a theft from those who hunger and are not fed, those who are cold and are not clothed - Dwight D. Eisenhower