When I resize my window software crashes because hbrush objcet isn't destoyed, I wrote this:
HBRUSH CDlgEst::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
HBRUSH hBrush = CreateSolidBrush(RGB(240, 240, 240));
HBRUSH hBrush1 = CreateSolidBrush(RGB(240, 240, 240));
int n_color;
RGBTRIPLE rgb;
double red;
double green;
double blue;
COLORREF Color;
CBrush Brush;
CSize csSizeOfText;
CString cs;
switch (pWnd->GetDlgCtrlID())
{
case IDC_STATIC_TIME1:
case IDC_STATIC_TIME2:
case IDC_STATIC_TIME3:
case IDC_STATIC_TIME4:
case IDC_ST_ESTS:
case IDC_TIMESEC1:
case IDC_TIMESEC2:
case IDC_TIMESEC3:
case IDC_TIMESEC4:
pDC->SetBkColor(RGB(255, 255, 255)); pDC->SetTextColor(RGB(0, 128, 0));
return (HBRUSH)(m_WhiteBrush); case IDC_ST_COLOR1:
if (m_aColor2.GetSize() > 0)
{
n_color = m_aColor2[0];
rgb.rgbtRed = GetRValue(n_color);
rgb.rgbtGreen = GetGValue(n_color);
rgb.rgbtBlue = GetBValue(n_color);
red = rgb.rgbtRed;
green = rgb.rgbtGreen;
blue = rgb.rgbtBlue;
pDC->SetBkColor(RGB(red, green, blue));
Color = RGB(red, green, blue);
Brush.CreateSolidBrush(Color);
hBrush1 = CreateSolidBrush(RGB(red, green, blue));
return (HBRUSH)(hBrush1);
}
else
return hBrush1;
case IDC_ST_COLOR2:
if (m_aColor2.GetSize() > 1)
{
n_color = m_aColor2[1];
rgb.rgbtRed = GetRValue(n_color);
rgb.rgbtGreen = GetGValue(n_color);
rgb.rgbtBlue = GetBValue(n_color);
red = rgb.rgbtRed;
green = rgb.rgbtGreen;
blue = rgb.rgbtBlue;
pDC->SetBkColor(RGB(red, green, blue));
hBrush1 = CreateSolidBrush(RGB(red, green, blue));
Color = RGB(red, green, blue);
Brush.CreateSolidBrush(Color);
return (HBRUSH)(hBrush1);
}
else
return hBrush1;
case IDC_ST_COLOR3:
if (m_aColor2.GetSize() > 2)
{
n_color = m_aColor2[2];
rgb.rgbtRed = GetRValue(n_color);
rgb.rgbtGreen = GetGValue(n_color);
rgb.rgbtBlue = GetBValue(n_color);
red = rgb.rgbtRed;
green = rgb.rgbtGreen;
blue = rgb.rgbtBlue;
pDC->SetBkColor(RGB(red, green, blue));
hBrush1 = CreateSolidBrush(RGB(red, green, blue));
Color = RGB(red, green, blue);
Brush.CreateSolidBrush(Color);
return (HBRUSH)(hBrush1);
}
else
return hBrush1;
case IDC_ST_COLOR4:
if (m_aColor2.GetSize() > 3)
{
n_color = m_aColor2[3];
rgb.rgbtRed = GetRValue(n_color);
rgb.rgbtGreen = GetGValue(n_color);
rgb.rgbtBlue = GetBValue(n_color);
red = rgb.rgbtRed;
green = rgb.rgbtGreen;
blue = rgb.rgbtBlue;
pDC->SetBkColor(RGB(red, green, blue));
hBrush1 = CreateSolidBrush(RGB(red, green, blue));
Color = RGB(red, green, blue);
Brush.CreateSolidBrush(Color);
return (HBRUSH)(hBrush1);
}
else
return hBrush1;
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
DeleteObject((HBRUSH)hbr);
DeleteObject((HBRUSH)hBrush);
DeleteObject((HBRUSH)hBrush1);
return hbr;
}
but software crashes...
What I have tried:
I wrote code in this way but software crashes when I resize