prabhakar157
June 14th, 2006, 02:59 AM
Is it possible to modify the default Background color of the Client which is white to a custom color?
I tried to change the background color to black using FillRect method of CDC in the following way..........
A simple code to test...........
void CXYZ::OnDraw(CDC* pDC)
{
CXYZ* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect r;
a) CBrush blackBrush(RGB(0,0,0));
b) //pDC->SetBkMode(TRANSPARENT);
c) GetClientRect(&r);
d) pDC->FillRect(&r,&blackBrush);
CBrush redBrush(RGB(210,0,0));
CRect rect(100,100,400,400);
pDC->BeginPath();
pDC->Rectangle(&rect);
pDC->EndPath();
rgn.CreateFromPath(pDC);
pDC->FillRgn(&rgn,&redBrush);
rgn.OffsetRgn(movePoint.x-100,movePoint.y-100);
pDC->FillRgn(&rgn,&redBrush);
rgn.DeleteObject();
// TODO: add draw code for native data here
}
movePoint rgn object are declared in CXYZ.h file
The value of movePoint is assigned the value of Mouse point which is handled in the MouseMove Event.
void CXYZ::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
movePoint = point;
InvalidateRgn(&rgn,0);
CView::OnMouseMove(nFlags, point);
}
I used InvalidateRgn() instead of Invalidate() coz i dont want to redraw the Background to avoid flickering.
I know that the problem is with the lines a,c and d.. as i'm redrawing the entire rectangle every time by calling OnDraw from the mousemove event.
As a result there is a flickering in the Rectangle region.
But when the lines a,c and d are commented (the background color of the client is set to its default color WHITE) there is not a pinch of flickering on the screen as the background is not erased.
So is it possible for me to change the color of the client view during runtime just like that of paint, so that i can fill the background of the view with my desired color and also be able to move different shapes on the same background at RUNTIME ?
I tried to change the background color to black using FillRect method of CDC in the following way..........
A simple code to test...........
void CXYZ::OnDraw(CDC* pDC)
{
CXYZ* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect r;
a) CBrush blackBrush(RGB(0,0,0));
b) //pDC->SetBkMode(TRANSPARENT);
c) GetClientRect(&r);
d) pDC->FillRect(&r,&blackBrush);
CBrush redBrush(RGB(210,0,0));
CRect rect(100,100,400,400);
pDC->BeginPath();
pDC->Rectangle(&rect);
pDC->EndPath();
rgn.CreateFromPath(pDC);
pDC->FillRgn(&rgn,&redBrush);
rgn.OffsetRgn(movePoint.x-100,movePoint.y-100);
pDC->FillRgn(&rgn,&redBrush);
rgn.DeleteObject();
// TODO: add draw code for native data here
}
movePoint rgn object are declared in CXYZ.h file
The value of movePoint is assigned the value of Mouse point which is handled in the MouseMove Event.
void CXYZ::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
movePoint = point;
InvalidateRgn(&rgn,0);
CView::OnMouseMove(nFlags, point);
}
I used InvalidateRgn() instead of Invalidate() coz i dont want to redraw the Background to avoid flickering.
I know that the problem is with the lines a,c and d.. as i'm redrawing the entire rectangle every time by calling OnDraw from the mousemove event.
As a result there is a flickering in the Rectangle region.
But when the lines a,c and d are commented (the background color of the client is set to its default color WHITE) there is not a pinch of flickering on the screen as the background is not erased.
So is it possible for me to change the color of the client view during runtime just like that of paint, so that i can fill the background of the view with my desired color and also be able to move different shapes on the same background at RUNTIME ?