change ChooseColor() Background Color
Posted: Wed Apr 05, 2023 1:24 pm
hi,
i have ask ChatGPT how to color ChooseColor()
what i´m doing wrong ... or is it Fake from ChatGPT ... 
i have ask ChatGPT how to color ChooseColor()
i have try it but it have no Effect in my SampleIf you are using the Win32 API to display these dialogs, you may be able to change the background color of the parent window before displaying the dialog box. Here is some sample code:In this example, we are setting the background color of the parent window to green using SetClassLongPtr() before calling ChooseColor(). After the user selects a color, we restore the original background color using GetStockObject().Code: Select all | Expand
// create the CHOOSECOLOR structure CHOOSECOLOR cc = { 0 }; cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; // set the parent window handle cc.Flags = CC_FULLOPEN | CC_RGBINIT; // set the dialog options cc.rgbResult = RGB(255, 0, 0); // set the initial color // change the background color of the parent window SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(0, 255, 0))); // display the ChooseColor dialog if (ChooseColor(&cc)) { // user clicked OK, use the selected color // ... } // restore the background color of the parent window SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH));
Code: Select all | Expand
HB_FUNC ( CHOOSECOLOR2 )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
CHOOSECOLOR cc = { 0 };
COLORREF crCustClr[16] ;
int i ;
for( i = 0 ; i <16 ; i++ )
{ if ( HB_ISARRAY(3) )
crCustClr[i] = hb_parvnl (3, i+1);
else
crCustClr[i] = GetSysColor ( COLOR_BTNFACE );
}
ZeroMemory ( &cc, sizeof(cc) );
cc.lStructSize = sizeof ( CHOOSECOLOR ) ;
cc.hwndOwner = HB_ISNIL(1) ? GetActiveWindow() : (HWND) hWnd;
cc.rgbResult = (COLORREF) HB_ISNIL(2) ? 0 : hb_parnl (2);
cc.lpCustColors = crCustClr ;
cc.Flags = CC_ANYCOLOR | CC_RGBINIT | ( hb_parl (4) ? CC_FULLOPEN : CC_PREVENTFULLOPEN ) ;
SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(0, 255, 0)));
if ( ChooseColor (&cc) )
hb_retnl ( cc.rgbResult );
else
hb_retnl ( -1 );
// restore the background color of the parent window
SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH));
}
