Click here to Skip to main content
15,886,741 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I want to write a WINDOWS program which changes the background of its client area with the help of common color dialog box. i Can't seem to get it right. Please Help. I Want the background of the Client Area be painted with the color i select from the common color Dialog Box. Sorry if i couldn't make it clear enough i am a newbie to window API.
Posted
Updated 30-Jan-12 0:04am
v3
Comments
theanil 28-Jan-12 13:33pm    
desktop background or forms?
iamrohitsingh 28-Jan-12 14:04pm    
The background of a client area - wndclass.hbrBackground ...

You will need to capture the WM_ERASEBKGND[^] message and do your own painting of the client area.
 
Share this answer
 
Comments
iamrohitsingh 29-Jan-12 16:45pm    
What i am not being able to understand is that how do i use the brush which is returned from choosecolor structure to paint the client area of the owner window
Richard MacCutchan 30-Jan-12 5:47am    
See my alternative solution.
A little sample to demonstrate how to paint the background instead of allowing Windows to erase it. This paints different system colours across the window - see the colour list starting at COLOR_SCROLLBAR in WinUser.h.

C++
BOOL Cls_OnEraseBkgnd(HWND hWnd,
                      HDC  hDC
                      )
{
    HBRUSH  hBrush;
    RECT    rectClient;
    int     nWidth;
    
    GetClientRect(hWnd, &rectClient);
    nWidth = rectClient.right / 30;
    rectClient.right = 1;
    for (int nBrush = 0; nBrush <= 30; ++nBrush)
    {
        hBrush = GetSysColorBrush(nBrush);
        rectClient.right += nWidth;
        FillRect(hDC, &rectClient, hBrush);
        rectClient.left += nWidth;
    }
    
    return TRUE;
}
 
Share this answer
 
v2
Comments
iamrohitsingh 30-Jan-12 5:56am    
Thats not what i was asking .....i was just asking how do i save the brush returned from common color dialog box and use it to paint the client area of the owner window of that Common color dialog box




#include <windows.h>
#include <commdlg.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static CHOOSECOLOR cc ;
static COLORREF crCustColors[16] ;

cc.lStructSize = sizeof (CHOOSECOLOR) ;
cc.hwndOwner = NULL ;
cc.hInstance = NULL ;
cc.rgbResult = RGB (0x80, 0x80, 0x80) ;
cc.lpCustColors = crCustColors ;
cc.Flags = CC_RGBINIT | CC_FULLOPEN ;
cc.lCustData = 0 ;
cc.lpfnHook = NULL ;
cc.lpTemplateName = NULL ;

return ChooseColor (&cc) ;
}

How do i save cc.RgbResult to paint the client area of owner window..
Richard MacCutchan 30-Jan-12 6:35am    
What do you mean? The value is already saved in the CHOOSECOLOR structure when the dialog closes. Use this value to create a custom brush which you can then use to paint the window.
iamrohitsingh 30-Jan-12 9:45am    
Sorry if i couldn't make anything clear...i am just a newbie to WINDOWS programming..
It would be so nice of you if you can provide me an Example ...using Only WINDOWS API NO MFC ....
Richard MacCutchan 30-Jan-12 9:56am    
That's what I gave you above, it's the code that gets invoked when you capture the WM_ERASEBKGND message. If you need a full sample of a Win32 program there are thousands around, just check the articles here on CodeProject or use the sample project in Visual studio.
iamrohitsingh 30-Jan-12 10:08am    
Ok i will.....Thanks for the help...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900