Anoop Kumar
Anoop Kumar

Reputation: 137

Draw on parent dialog in mfc

I have a dialog which contains many controls. for ex: edit control. Now I am developing these edit controls which is having colorful border. But control redraw itself each time user enter the input in edit control, so border flickers. Now I want to draw border on the dialog which is having this control. Is it possible in mfc?

Upvotes: 0

Views: 1249

Answers (2)

Anoop Kumar
Anoop Kumar

Reputation: 137

I made changes in Onsize and reduced the control by 1px on each side then draw the border. something like this

rcRichEdit.left += 1;
        rcRichEdit.right -= 1;
        rcRichEdit.bottom -= 1;

Upvotes: 0

Santosh
Santosh

Reputation: 1815

You can achieve this by customizing your control class and drawing on non client area. I have implemented this in my project with no flicking issue.

enter image description here

Here is the idea goes:

/////////////////////////////////////////////////////////////////////////////
///
/// /This method is overriden, to modify the style of editcrtl
///
/////////////////////////////////////////////////////////////////////////////
void CEdit1::PreSubclassWindow()
{
    ModifyStyleEx(0, WS_EX_STATICEDGE, 0); //to make sure your border is static edge
}

and on non client area you just draw red rectangle:

/////////////////////////////////////////////////////////////////////////////
///
/// /This handler is used to paint the non- client area
///
/// /return none
///
/////////////////////////////////////////////////////////////////////////////
void CEdit1::OnNcPaint() 
{
    CDC* pDC = GetWindowDC();

    //work out the coordinates of the window rectangle,
    CRect rect;
    GetWindowRect( &rect);
    rect.OffsetRect( -rect.left, -rect.top);

    //Draw a single line around the outside
    CBrush brush(RGB(255,0,0));
    pDC->FrameRect(&rect, &brush);
    ReleaseDC( pDC);
}

Upvotes: 4

Related Questions