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.
Related posts
1 Comment
Leave a Reply Cancel reply
Recent Posts: TechnoBlogy
The Best Surveillance Cameras in 2018

Intel: Virus Scanners Should Use the Performance of the GPU

Azure Sphere: Microsoft uses Linux instead of Windows for the IoT

Microsoft relies on its own chips for IoT security – and Linux

Bitcoin mining through a hydraulic turbine – Dubbed Ocean Miner

Sony Xperia XZ2 Premium, with dual photo sensor and 4K HDR screen!

Microsoft Introduces Azure Sphere Hardware and Software Platform

Behind the Recent Russian Cyber Attack

What is the GDPR? The 7 most Important Questions and Answers

Hyperloop TT begins to build its test track in Toulouse

fantastic……thank you so much