kamagra kart

Monday, November 24, 2014

How to set border of CDialog

November 3, 2009 by · 1 Comment 

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.

Top Blogs

Comments

One Response to “How to set border of CDialog”
  1. jadeer says:

    fantastic……thank you so much

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*