Click to See Complete Forum and Search --> : HBrush use in Class Regiester, Delete after Application ended?


Irwan
June 29th, 2010, 11:15 PM
Hi.


My writing a application.
1. The Main Window Client Area is splitted into several child window.
2. Each Child Window background is paint with different color.
3. Background color is register in the wndclass.hbrBackground for each child window.
4. The bush is created by CreateSolidBrush().


The question:
1. Do I need to delete the brushs?
2. Where to delete it?



The Code:
(unrelated lines is deleted)

#

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
// Win32 API Structure Declaration
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
static TCHAR szAppName[] = TEXT("SplitterApp");


// Main Window Class
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, szAppName);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = CreateSolidBrush(RGB(195,218,249));
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);


// Left Panel Class
wndclass.lpfnWndProc = LeftPanelProc;
wndclass.hbrBackground = CreateSolidBrush(RGB(255,255,255));
wndclass.lpszClassName = TEXT("LeftPanel");
RegisterClass(&wndclass);



// Splitter Panel Class
wndclass.lpfnWndProc = SplitterPanelProc;
wndclass.hbrBackground = CreateSolidBrush(RGB(255,0,0));
wndclass.lpszClassName = TEXT("SplitterPanel");
RegisterClass(&wndclass);



// Create Window for Main Window
hwnd = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW | SW_MAXIMIZE | WS_VISIBLE,
us->getStartXPos(),
us->getStartYPos(),
us->getWndStartWidth(),
us->getWndStartHeight(),
NULL,
NULL,
hInstance,
szCmdLine);

//All child Window is Created in the WndProc()



// Message Pump
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}


return (int)msg.wParam;
}

#

hoxsiew
June 30th, 2010, 07:44 AM
Please use code tags.

Since you're not using a system brush, you should free its resources by calling DeleteObject() when it is no longer needed. To do this, you'll have to keep track of the brush handle in a global variable. You could delete is when your WinMain terminates (say, right before "return (int)msg.wParam;").

Irwan
June 30th, 2010, 11:09 PM
OK. Done that. Thank you. That would confirm my action. Thanks.


About the code tag, The Tag button is not appears during writing is topic.

hoxsiew
July 1st, 2010, 07:20 AM
It's easier to just add them manually (at least for me). Just type:

int main()
{
return 0;
}


and you'll get:


int main()
{
return 0;
}