Hello Carlos and all Dev-C++ users,
Wednesday, July 23, 2003, 7:07:33 PM, Carlos wrote as follows:
CGdM> In the Win32 API reference it's claimed that when you want to use the
CGdM> lpCustColors of that structure, you shall provide a pointer to a 16
CGdM> COLORREF values.
CGdM> So you shall do this:
CGdM> LPCOLORREF rgbCust = (LPCOLORREF)GlobalAlloc(GPTR, 16 * sizeof(COLORREF));
CGdM> And in the message where you want select a color through the common dialog
CGdM> CHOOSECOLOR chc;
CGdM> [...]
CGdM> chc.lpCusrtColors = rgbCust;
CGdM> if (!ChooseColor(&chc)){
CGdM> [...]
CGdM> When I do this I get that the first square of custom colors is
CGdM> initialized to a random color, not black, and if I select it, then when
CGdM> I want paint something I get a memory access violation.
CGdM> Then I change rgbCust to point to 17 values.
CGdM> The same happens.
CGdM> Then I make it point to 17 and pass &rgbCust[1];
CGdM> Now it works nice.
CGdM> Then I make it point to 16 values and I pass &rgbCust[1]. It works.
CGdM> So this is the problem: you pass the COLORREF array to the struct but it
CGdM> receives &rgbCust[-1] from the pointer you provide.
There is nothing strange when you do likt this (code from Platform SDK
AFAIR):
CHOOSECOLOR cc; // common dialog box structure
static COLORREF custClrs[ 16 ];
// Initialize CHOOSECOLOR
ZeroMemory( &cc, sizeof( CHOOSECOLOR ));
cc.lStructSize = sizeof( CHOOSECOLOR );
cc.hwndOwner = main_hwnd;//main_hwnd is my var
//cc.hInstance = hInstance;
cc.rgbResult = chosen_color;//my global var for storing color
cc.Flags = CC_ANYCOLOR | CC_RGBINIT | CC_FULLOPEN;
cc.lpCustColors = custClrs;
if( ChooseColor( &cc ) == TRUE )
{
chosen_color = cc.rgbResult;
return TRUE;
}
return FALSE;
--
regards, Zodiaq
|