Thread: win32 - how can i change the windows\form backcolor?

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    451

    win32 - how can i change the windows\form backcolor?

    i continue with some problems with windows properties
    how can i change the window backcolor?

    Code:
    //.............
    HBRUSH g_hbrBackground = NULL;
    //...............
    //inst is the class instance pointer
    case WM_CTLCOLORSTATIC:
                {
                    if ( inst->blnTransparent == true)
                    {
                        SetTextColor((HDC)wParam, inst->clrTextColor);
                        SetBkMode( (HDC)wParam, TRANSPARENT);
                        return (LRESULT) GetStockObject(NULL_BRUSH);
                    }
                    else
                    {
                        DeleteObject(g_hbrBackground);
                        SetTextColor((HDC)wParam, inst->clrTextColor);
                        SetBkColor((HDC)wParam,inst->clrBackColor);
                        SetBkMode((HDC)wParam, TRANSPARENT);
                        g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
                        return (LONG)g_hbrBackground;
                    }
                }
                break;
    Last edited by joaquim; 09-07-2014 at 01:13 PM.

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    finally i put it to work
    Code:
    SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, (LONG)CreateSolidBrush(clrBackColor));
                        InvalidateRect(hwnd,NULL,true);
    the 'clrBackColor' can be changed with RGB() function.
    i must use the InvalidateRect() for change the value... from MSDN:
    "Use the SetClassLongPtr function with care. For example, it is possible to change the background color for a class by using SetClassLongPtr, but this change does not immediately repaint all windows belonging to the class."
    heres the MSDN page: SetClassLongPtr function (Windows)
    from here we can change the icon and mouse icon and more
    i have tested with 2 forms but the backcolors are the same
    Last edited by joaquim; 09-07-2014 at 02:24 PM.

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    now i resolve it
    when i create the form, i change the lpszClassName with an index and the problem is resolved
    now the backcolor and others are independente. i just need ask 1 thing:
    is good use diferent lpszClassName with the same message loop procedure(lpfnWndProc)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [win32] - how hide backcolor in a form?
    By joaquim in forum Windows Programming
    Replies: 2
    Last Post: 07-18-2014, 12:33 PM
  2. Change Network Configuration using win32 VC++
    By NetCoder in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2013, 06:50 AM
  3. Windows form C++ - referencing the form
    By rocketman50 in forum Windows Programming
    Replies: 2
    Last Post: 05-22-2010, 11:58 AM
  4. c++builder6 change form names problem
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2008, 08:20 AM
  5. Finding a knoppix demo in win32 form
    By Stan100 in forum Tech Board
    Replies: 3
    Last Post: 01-15-2005, 06:08 PM