Click to See Complete Forum and Search --> : The color/colour dialogue -
.pcbrainbuster
November 23rd, 2007, 04:58 AM
Hello dudes,
I tried to implement a color dialogue but miserably failed -
{global}
static COLORREF acrCustClr[16];
static CHOOSECOLOR cc;
...
{WM_CREATE}
ZeroMemory(&cc, sizeof(CHOOSECOLOR));
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hWnd;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
cc.lpCustColors = (LPDWORD) acrCustClr;
...
{WM_COMMAND}
cc.rgbResult = BrushColor;
ChooseColor(&cc);
The results are; the dialogue box shows up but when I select the colour there is no change in the colour of the line :(
Any ideas?
Thanks.
LoKi_79
November 23rd, 2007, 07:18 AM
The results are; the dialogue box shows up but when I select the colour there is no change in the colour of the line :(
Any ideas?
look on msdn, after choosing the colour you have to do something with it:CHOOSECOLOR cc; // common dialog box structure
static COLORREF acrCustClr[16]; // array of custom colors
HWND hwnd; // owner window
HBRUSH hbrush; // brush handle
static DWORD rgbCurrent; // initial color selection
// Initialize CHOOSECOLOR
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = hwnd;
cc.lpCustColors = (LPDWORD) acrCustClr;
cc.rgbResult = rgbCurrent;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&cc)==TRUE) {
hbrush = CreateSolidBrush(cc.rgbResult);
rgbCurrent = cc.rgbResult;
}
.pcbrainbuster
November 23rd, 2007, 10:31 AM
I already am, BrushColor points to the variable that has the color to be set in WM_PAINT.
Any ideas?
Thanks.
LoKi_79
November 23rd, 2007, 11:47 AM
I already am, BrushColor points to the variable that has the color to be set in WM_PAINT.
Any ideas?
Thanks.
then shouldn't it be:
ChooseColor(&cc);
BrushColor = cc.rgbResult;
or more safely:
if (ChooseColor(&cc)==TRUE) {
BrushColor = cc.rgbResult;
}
as in the MS example.
Marc G
November 23rd, 2007, 12:04 PM
Please check the MSDN as already suggested.
The definition of the CHOOSECOLOR structure is as follows:
typedef struct {
DWORD lStructSize;
HWND hwndOwner;
HWND hInstance;
COLORREF rgbResult;
COLORREF *lpCustColors;
DWORD Flags;
LPARAM lCustData;
LPCCHOOKPROC lpfnHook;
LPCTSTR lpTemplateName;
} CHOOSECOLOR, *LPCHOOSECOLOR;
Notice the red line. It's a COLORREF rgbResult. It's not a pointer. So when you assign BrushColor to it it will copy the value in rgbResult. However, after closing it will modify rgbResult but NOT BrushColor because rgbResult is a copy. You need to do like Loki said.
.pcbrainbuster
November 23rd, 2007, 02:05 PM
Weee :p RESOLVED!
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.