Results 1 to 4 of 4

Thread: Set window background

  1. #1

    Thread Starter
    Addicted Member BarankinBeAMan's Avatar
    Join Date
    Aug 2002
    Location
    Reston,Va
    Posts
    164

    Angry Set window background

    How do I set dialog based window background to any other color
    in run time ?
    I noticed that background is set onInitialize ,
    is there a way to change the color just like for other control as CEdit?

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Here is how you could change the backcolor of a dialog:

    PHP Code:
    HBRUSH g_hbrBackground CreateSolidBrush(RGB(0,255,0));

    case 
    WM_CTLCOLORDLG:
          return (
    LON)g_hbrBackGround;
    case 
    WM_CTLCOLORSTATIC:
     {
         
    HDC hdcStatic = (HDC)wParam;
         
    SetTextColor(hdcStaticRGB(255,255,255));
         
    SetBkMode(hdcStatic,TRANSPARENT);
         return (
    LONG)g_hbrBackground;
    }
    break; 
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3

    Thread Starter
    Addicted Member BarankinBeAMan's Avatar
    Join Date
    Aug 2002
    Location
    Reston,Va
    Posts
    164
    Where do I insert this code in Dialog based window?
    Does it have to be in window message hanling function?

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)?



  4. #4
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Yes.

    Here is an example:

    PHP Code:
    #include <windows.h>

    #include "resource.h" 

    HBRUSH g_hbrBackground NULL;

    BOOL CALLBACK DlgProc(HWND hwndUINT MessageWPARAM wParamLPARAM lParam)
    {
        switch(
    Message)
        {
            case 
    WM_INITDIALOG:
                
    g_hbrBackground CreateSolidBrush(RGB(000));

                
    SendMessage(hwndWM_SETICONICON_SMALL, (LPARAM)LoadIcon(NULL
                    
    MAKEINTRESOURCE(IDI_APPLICATION)));
                
    SendMessage(hwndWM_SETICONICON_BIG, (LPARAM)LoadIcon(NULL
                    
    MAKEINTRESOURCE(IDI_APPLICATION)));
            break;
            case 
    WM_CLOSE:
                
    EndDialog(hwnd0);
            break;
            case 
    WM_CTLCOLORDLG:    
                return (
    LONG)g_hbrBackground;
            case 
    WM_CTLCOLORSTATIC:
            {
                
    HDC hdcStatic = (HDC)wParam;
                
    SetTextColor(hdcStaticRGB(255255255));
                
    SetBkMode(hdcStaticTRANSPARENT);
                return (
    LONG)g_hbrBackground;
            }
            break;
            case 
    WM_COMMAND:
                switch(
    LOWORD(wParam))
                {
                    case 
    IDOK:
                        
    EndDialog(hwnd0);
                    break;
                }
            break;
            case 
    WM_DESTROY:
                
    DeleteObject(g_hbrBackground);
            break;
            default:
                return 
    FALSE;
        }
        return 
    TRUE;
    }

    int WINAPI WinMain(HINSTANCE hInstanceHINSTANCE hPrevInstance,
        
    LPSTR lpCmdLineint nCmdShow)
    {
        return 
    DialogBox(hInstanceMAKEINTRESOURCE(IDD_MAIN), NULLDlgProc);

    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

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