Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing in a Dialog Box

Status
Not open for further replies.

RCS1

Technical User
Aug 29, 2002
2
US
I am trying to change the color of the dialog box to white. As there are no standard properties available, I am trying to use draw a rectagle of the size equal to its client area. Below are the 2 ways I employed in vain.

Method I :

BOOL CMyWndDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
RECT rect;

this->GetClientRect(&rect);
CPaintDC mydc(this);
CDC memdc;
CBitmap *oldbitmap = NULL, newbitmap;

memdc.CreateCompatibleDC(&mydc);

newbitmap.CreateCompatibleBitmap(&mydc, rect.right, rect.bottom);
oldbitmap = memdc.SelectObject(&newbitmap);
memdc.FillSolidRect(0,0,rect.right, rect.bottom, RGB(0, 255, 255) );
mydc.BitBlt(0,0,rect.right, rect.bottom, &memdc , 0, 0, SRCCOPY);

memdc.SelectObject(oldbitmap);

return TRUE;
}

Method II:

BOOL CMyWndDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
RECT rect;

this->GetClientRect(&rect);
CClientDC mydc(this);
CPen *oldPen, newPen;
CBrush *oldBrush, newBrush;

newPen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
newBrush.CreateSolidBrush(RGB(2555, 255, 255));

oldPen = mydc.SelectObject(&newPen);
oldBrush = mydc.SelectObject(&newBrush);

mydc.Rectangle(rect.left, rect.top, rect.right, rect.top);

mydc.SelectObject(oldPen);
mydc.SelectObject(oldBrush);

return TRUE;
}

Can anyone help what is wrong in the above code. Is there any alternative method.

Thanks in advance.

rcs1
 
I do it like this:

void CAGDSplashDlg::OnPaint()
{
// set the background colour of the dialog to yellow
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, RGB(255,255,0));
}

Hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top