[Dev-C++] Curiosity about CHOOSECOLOR.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <ten...@ne...> - 2003-07-23 17:07:51
|
In the Win32 API reference it's claimed that when you want to use the
lpCustColors of that structure, you shall provide a pointer to a 16
COLORREF values.
So you shall do this:
LPCOLORREF rgbCust = (LPCOLORREF)GlobalAlloc(GPTR, 16 * sizeof(COLORREF));
And in the message where you want select a color through the common dialog
CHOOSECOLOR chc;
[...]
chc.lpCusrtColors = rgbCust;
if (!ChooseColor(&chc)){
[...]
When I do this I get that the first square of custom colors is
initialized to a random color, not black, and if I select it, then when
I want paint something I get a memory access violation.
Then I change rgbCust to point to 17 values.
The same happens.
Then I make it point to 17 and pass &rgbCust[1];
Now it works nice.
Then I make it point to 16 values and I pass &rgbCust[1]. It works.
So this is the problem: you pass the COLORREF array to the struct but it
receives &rgbCust[-1] from the pointer you provide.
|