How to set border of CDialog
I am new in MFC. I put some time to draw a border around a Dialog in MFC application. Here is the solution that i found. It is very simple for any level of programmer.
Follow just three simple steps.
Step1:
Add OnCtlColor() method in your Message map like:-
BEGIN_MESSAGE_MAP(CDATToSWFDlg, CTrayDialog)
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
Step2:
Add this method in your code.
HBRUSH CDATToSWFDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{CBrush m_brush;
m_brush.CreateSolidBrush(RGB(239, 255, 255)); // Set color to your Dialog
///////// SETTING BORDER /////////pDC = GetWindowDC();
CRect rect;
GetWindowRect(&rect);
rect.OffsetRect( -rect.left, -rect.top);
CBrush brush( RGB(0, 0, 0)); // Color of your desired border
pDC->FrameRect( &rect, &brush);
int borderWidth = 4; // Set the width of your desired border.
for(int i=1; i<borderWidth; i++)
{
rect.OffsetRect( -rect.left+i, -rect.top+i);
pDC->FrameRect( &rect, &brush);
}
HDC hdc = pDC->GetSafeHdc();
for(i=1; i<borderWidth; i++)
{
rect.OffsetRect( -rect.left-i, -rect.top-i);
pDC->FrameRect( &rect, &brush);
}
ReleaseDC(pDC);
//////////////////////////////////
return m_brush;
}
Step3:
Define OnCtlColor() method in header file of Dialog like:-
class CDATToSWFDlg: public CDialog
{
// Construction
public:
HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
}
Thats it…. Now just run it and enjoy
But please add in comments if you have any powerful solution.
Thanks.
fantastic……thank you so much