将属性表背景颜色更改为与父对话框相同

时间:2017-07-13 05:06:49

标签: c++ mfc

我在对话框中创建了一个属性表。但默认情况下,属性表以白色背景颜色显示。我希望属性表的背景颜色与放置它的对话框相同。感谢。

2 个答案:

答案 0 :(得分:1)

您必须实施消息事件OnEraseBkgndCPropertyPage

class CMyPage : public CPropertyPage
{
public:

    DECLARE_MESSAGE_MAP()

    afx_msg BOOL OnEraseBkgnd(CDC* pDC);    
}

将应用程序框架消息事件添加到消息循环中:

BEGIN_MESSAGE_MAP(CMyPage, CPropertyPage)
      ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

最后实现messag事件方法。该方法的实现利用了 GetSysColorCDC::FillSolidRectCDC::GetClipBox

BOOL CMyPage::OnEraseBkgnd( CDC *pDC ) 
{
    // get the background color
    COLORREF bkCol = ::GetSysColor(COLOR_MENU);

    // get the area you have to fill
    CRect rect;
    pDC->GetClipBox(&rect); 

    // fill the rectangular area with the color
    pdC->FillSolidRect(&rect, bkCol);
  }

答案 1 :(得分:0)

我已经可以从互联网上看到这一点。

例如:

http://forums.codeguru.com/showthread.php?235997-CPropertySheet-color

要更改窗口的背景颜色,您可以使用restTemplate.postForEntity(url,entity, String.class); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class); 。您可以使用传递的CWnd::OnEraseBkgnd()对象将背景绘制为任何颜色。

相关问题