views:

123

answers:

1

The following code works fine:

for(int i=0; i<500; i++) {
for(int j=0; j<100; j++) {
m_title.SetWindowText(_T("lol"));
}
}

But when I set a background color for the dialog:

HBRUSH CTaggingDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
return CreateSolidBrush(RGB(0,0,0));//BLACK
}

The loop above causes the program to hit a breakpoint in wingdi.cpp at:

CPaintDC::CPaintDC(CWnd* pWnd)

How do I set a background color for the dialog without having it crash?

A: 

Never mind. By changing the way I set the background color to the method in this article:

http://www.codeguru.com/cpp/w-d/dislog/background/article.php/c1895

The problem has been resolved.

Chetan
It'll be because you were leaking brushes (CreateSolidBrush gives you a new brush each time). By using a CBrush as a member variable, you only have one brush object, and it's cleaned up along with the window.
Roger Lipscombe