-
July 17th, 2013, 04:40 PM
#1
CButton surrounded with a red line
Hi all
i am trying to do a button with red line around it, i don't know exactly how do it.
i am understanding i need to take the DC with GetDC and i have to use a pen,
but i cannot see any red line.
Can somebody show me how do it?
Thanks in advance.
Giovanni
-
July 18th, 2013, 01:07 AM
#2
Re: CButton surrounded with a red line
You have to use an ownerdraw button. Search MSDN for details.
Besides there is a lot of examples in CD and CP article sections.
Victor Nijegorodov
-
July 18th, 2013, 02:08 AM
#3
Re: CButton surrounded with a red line
Well, I would go with painting in dialog's DC. That would allow me to have not only ownerdrawn buttons there in the dialog.
Best regards,
Igor
-
July 18th, 2013, 02:31 AM
#4
Re: CButton surrounded with a red line
Originally Posted by Igor Vartanov
Well, I would go with painting in dialog's DC. That would allow me to have not only ownerdrawn buttons there in the dialog.
i am trying in this moment like this:
void CFormView::OnDraw(CDC* pDC)
{
CPen NewPen;
CRect r;
GetDlgItem(IDC_BUTTON)->GetClientRect(r);
NewPen.CreatePen(PS_SOLID, 1, RGB(255, 25, 5));
pDC->SelectObject(&NewPen);
pDC->Rectangle(r);
}
But the rectangle is drawn the same dimension but is not centered on the button, maybe i am near please help me to understand this
-
July 18th, 2013, 02:40 AM
#5
Re: CButton surrounded with a red line
GetClientRect gives you coordinates of control's client area. What you need is control's window rect mapped to dialog's client area. Besides, you need to inflate the rect a little to let the line be not obscured by the control borders.
Last edited by Igor Vartanov; July 18th, 2013 at 02:45 AM.
Best regards,
Igor
-
July 18th, 2013, 07:19 AM
#6
Re: CButton surrounded with a red line
As Igor said, you need to make the rect bigger than the button of the button will draw right over the top of it.
-
July 19th, 2013, 02:20 AM
#7
Re: CButton surrounded with a red line
I've done it!!!!
I post this for future reference:
void CFormView::OnDraw(CDC* pDC)
{
CPen cpRedPen;
CRect crRect;
cpRedPen.CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
pDC->SelectObject(&cpRedPen);
m_MyButton.GetWindowRect(crRect);
ScreenToClient(crRect);
pDC->Rectangle(crRect);
}
-
July 19th, 2013, 07:32 AM
#8
Re: CButton surrounded with a red line
You need to get to a habit of unselecting everything you selected, after your drawing completed.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|