As per documentation ,
"The system automatically deletes class background brushes when the class is unregistered by using UnregisterClass. An application should not delete these brushes.".
Remove the call to ::DeleteObject(hredBrush);.
-SM
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi,
I have a question about the background color of MFC.
My code is as follows
Mainfrm.h
class C_MainFrame : public CFrameWnd
{
public:
C_MainFrame(); // Declear Constructor
};
Mainfrm.cpp
// CMainFrame
//Define Constructor
C_MainFrame::C_MainFrame() {
HBRUSH hredBrush = ::CreateSolidBrush(RGB(255, 200, 20));
CString MyWindowClass = AfxRegisterWndClass(
CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW ,
AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING),
hredBrush, //"unable to read memory".
AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION));
Create(MyWindowClass, _T("Main Window A"), WS_OVERLAPPEDWINDOW);
::DeleteObject(hredBrush);
}
when I use hredBrush as parameter of AfxRegisterWndClass,It shows me "unable to read memory".
but when i use ::CreateSolidBrush(RGB(255, 200, 20)) as parameter of AfxRegisterWndClass it works fine.
I means refer the below code:
CString MyWindowClass = AfxRegisterWndClass(
CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW ,
AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING),
::CreateSolidBrush(RGB(255, 200, 20)), // work fine
AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION));
Create(MyWindowClass, _T("Main Window A"), WS_OVERLAPPEDWINDOW);
Can Anyone please help me to understand why this is happening?
As per documentation ,
"The system automatically deletes class background brushes when the class is unregistered by using UnregisterClass. An application should not delete these brushes.".
Remove the call to ::DeleteObject(hredBrush);.
-SM