CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2010
    Posts
    34

    HBrush use in Class Regiester, Delete after Application ended?

    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;
    }

    #

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: HBrush use in Class Regiester, Delete after Application ended?

    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;").

  3. #3
    Join Date
    Jun 2010
    Posts
    34

    Re: HBrush use in Class Regiester, Delete after Application ended?

    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.

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: HBrush use in Class Regiester, Delete after Application ended?

    It's easier to just add them manually (at least for me). Just type:
    [code]
    int main()
    {
    return 0;
    }
    [/code]

    and you'll get:

    Code:
    int main()
    {
      return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured