c++ - 在mfc中绘制父对话框

标签 c++ visual-c++ mfc drawing

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

最佳答案

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

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

关于c++ - 在mfc中绘制父对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44229357/

相关文章:

c++ - 抛出异常后我可以信任 vector::size 吗?

c++ - 如何显示不带小数的整数

c++ - 可以使用ofstream在打印机上打印

c++ - 在非成员函数中访问MFC对话框的成员变量

c++ - 如何创建哈希表

c++ - OpenCV 中的支持 vector 机 : low accuracy OCR with RBF kernel

c# - directx/directshow preparesurface 失败/无法呈现图像

debugging - VisualStudio2005调试速度非常慢

c++ - CRecordset::snapshot 在 VS2012 中不再起作用——有什么选择?

C++ 错误 : identifier "CWnd" is not defined