NO

Author Topic: Background Color on Dialog  (Read 3768 times)

tbohon

  • Guest
Background Color on Dialog
« on: April 16, 2010, 07:50:20 PM »
I continue to learn and have managed to answer/resolve my previous questions PLUS I figured out how to use the Windows clipboard (easier than I thought it would be, actually).

Right now I'm wrestling with figuring out a way to change the background color on my dialog box and am going nowhere rapidly.  I'll continue searching in my 'spare' time but was wondering if a guru here could point out what I'm doing wrong in the code fragment below ...

Code: [Select]
/****************************************************************************
 *                                                                          *
 * Function: WinMain                                                        *
 *                                                                          *
 * Purpose : Initialize the application.  Register a window class,          *
 *           create and display the main window and enter the               *
 *           message loop.                                                  *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;

    ghInstance = hInstance;

    HBRUSH mybrush = CreateSolidBrush((COLORREF) RGB (255,255,255) );

    /* Initialize common controls. Also needed for MANIFEST's */
    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
    InitCommonControlsEx(&icc);

    /* Get system dialog information */
    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

    /* Add our own stuff */
    wcx.hInstance = hInstance;
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
    wcx.lpszClassName = _T("win1Class");
wcx.hbrBackground = mybrush;
    if (!RegisterClassEx(&wcx))
        return 0;

    /* The user interface is a modal dialog box */
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}


Any hints appreciated - again I learn best by being pointed toward the answer and then left to figure it out on my own.

Tnx in advance.

Tom

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Background Color on Dialog
« Reply #1 on: April 19, 2010, 07:05:35 PM »
Tom,

Here's a little one off demo I just threw together.

The dialog based project behaves differently then the window based.  This is because the dialog's processes, including drawing, are handled by windows internally in a standard way.  There is a way to override the default painting of background and text however, and that is what the attached project demonstrates.  As a bonus I threw in some code for the choose color dialog so that you could play around with it.

Regards,
DMac
No one cares how much you know,
until they know how much you care.

tbohon

  • Guest
Re: Background Color on Dialog
« Reply #2 on: April 20, 2010, 03:39:08 AM »
Thank you kind sir ... greatly appreciated!

Best,

Tom