2017-05-28 90 views
0

我有一个包含许多控件的对话框。例如:编辑控件。 现在我正在开发这些具有丰富边框的编辑控件。 但每次用户在编辑控件中输入输入时控件都会重绘,因此边框闪烁。 现在我想在具有此控件的对话框上绘制边框。在mfc中可能吗?在mfc的父对话框中绘制

+0

你是如何进行编辑控制图纸边界?我会通过处理'WM_NCCALCSIZE'来定义边框尺寸和'WM_NCPAINT'来实际绘制边框。如果正确,没有闪烁。 – zett42

+1

*“现在我正在开发这些编辑控件” - 这可能意味着什么。作为你的问题的核心组成部分,它值得更多的细节。 – IInspectable

回答

4

您可以通过自定义您的控件类并在非客户区绘制来实现此目的。 我已经在我的项目中实现了这个功能,没有闪烁问题。

enter image description here

这里的想法云:

///////////////////////////////////////////////////////////////////////////// 
/// 
/// /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 
} 

和非客户区,你只画红色矩形:

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

我在筛上部分所做的更改,并通过降低控制每边1px然后绘制边框。 像这样

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