反复执行,约几万次会出现资源耗尽的现象,我该如何修改.我实现的代码如下:
HBRUSH CYGLoginChildDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG ||nCtlColor == CTLCOLOR_STATIC )
pDC ->SetBkColor (m_Color);
// return hbr;
return (HBRUSH)::CreateSolidBrush(m_Color);
}
HBRUSH CYGLoginChildDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG ||nCtlColor == CTLCOLOR_STATIC )
pDC ->SetBkColor (m_Color);
// return hbr;
return (HBRUSH)::CreateSolidBrush(m_Color);
}
记得最后删除。
{
static HBRUSH hbrush[6]={NULL,NULL,NULL,NULL,NULL,NULL};
// TODO: Change any attributes of the DC here
if( nCtlColor == CTLCOLOR_STATIC )
{
int i=-1,r,g,b;
switch( pWnd->GetDlgCtrlID() )
{
case IDC_STC1:i=0;r=a1;g=a2;b=a3;break;
case IDC_STC2:i=1;r=a4;g=a5;b=a6;break;
case IDC_STC3:i=2;r=a7;g=a8;b=a9;break;
case IDC_STC4:i=3;r=b1;g=b2;b=b3;break;
case IDC_STC5:i=4;r=b4;g=b5;b=b6;break;
case IDC_STC6:i=5;r=b7;g=b8;b=b9;break;
}
if( i !=-1 )
{
if( hbrush[i] )::DeleteObject( hbrush[i] );
hbrush[i] = ::CreateSolidBrush( RGB(r,g,b) );
return hbrush[i];
}
}
// TODO: Return a different brush if the default is not desired
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == IDC_STATIC1)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
} return hbr;
}