CButton surrounded with a red line
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: CButton surrounded with a red line

  1. #1
    Join Date
    Jul 2013
    Posts
    3

    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

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,466

    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

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,020

    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

  4. #4
    Join Date
    Jul 2013
    Posts
    3

    Re: CButton surrounded with a red line

    Quote Originally Posted by Igor Vartanov View Post
    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

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,020

    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

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,115

    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.

  7. #7
    Join Date
    Jul 2013
    Posts
    3

    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);
    }

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,020

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center