change ChooseColor() Background Color

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

change ChooseColor() Background Color

Post by Jimmy »

hi,

i have ask ChatGPT how to color ChooseColor()
If 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:

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));
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().
i have try it but it have no Effect in my Sample

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));
   
}
what i´m doing wrong ... or is it Fake from ChatGPT ... :?:
greeting,
Jimmy
User avatar
karinha
Posts: 7963
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 5 times
Contact:

Re: change ChooseColor() Background Color

Post by karinha »

Maybe:

https://github.com/harbour/core/blob/ma ... wvgutils.c

Code: Select all | Expand

#pragma BEGINDUMP
#define _WIN32_IE 0x0500

#ifdef __POCC__
#define _WIN32_WINNT 0x0500
#else
#define _WIN32_WINNT 0x0400
#endif

#include 

#include "hbapi.h"

#include 
#include 
#include 
#include 

#include "hbapiitm.h"

#define HB_PARSTRDEF( n, h, len )             hwg_wstrnull( hwg_wstrget( hb_param( n, HB_IT_ANY ), h, len ) )
#define HB_RETSTR( str )                      hwg_wstrset( hb_param( -1, HB_IT_ANY ), str )

#ifdef __XHARBOUR__
#define HB_PARNL( n, x ) hb_parnl( n, x )
#define HB_STORC( n, x, y ) hb_storc( n, x, y )
#define HB_STORL( n, x, y ) hb_storl( n, x, y )
#define HB_STORNI( n, x, y ) hb_storni( n, x, y )
#define HB_STORNL( n, x, y ) hb_stornl( n, x, y )
#else
#define HB_PARNL( n, x ) hb_parvnl( n, x )
#define HB_STORC( n, x, y ) hb_storvc( n, x, y )
#define HB_STORL( n, x, y ) hb_storvl( n, x, y )
#define HB_STORNI( n, x, y ) hb_storvni( n, x, y )
#define HB_STORNL( n, x, y ) hb_storvnl( n, x, y )
#endif

#ifdef __XHARBOUR__
#define HB_ISNIL( n )       ISNIL( n )
#define HB_ISCHAR( n )      ISCHAR( n )
#define HB_ISNUM( n )       ISNUM( n )
#define HB_ISLOG( n )       ISLOG( n )
#define HB_ISDATE( n )      ISDATE( n )
#define HB_ISBYREF( n )     ISBYREF( n )
#define HB_ISARRAY( n )     ISARRAY( n )
#endif

HB_FUNC( CHOOSEFONT )
{
   CHOOSEFONT cf;
   LOGFONT lf;
   long PointSize;
   int bold;
   HDC hdc;
   HWND hwnd;

   strcpy( lf.lfFaceName, hb_parc(1) );

   hwnd = GetActiveWindow();
   hdc = GetDC( hwnd );

   lf.lfHeight = -MulDiv( hb_parnl(2), GetDeviceCaps(hdc, LOGPIXELSY), 72 );

   if( hb_parl(3) )
      lf.lfWeight = 700;
   else
      lf.lfWeight = 400;

   if( hb_parl(4) )
      lf.lfItalic = TRUE;
   else
      lf.lfItalic = FALSE;

   if( hb_parl(6) )
      lf.lfUnderline = TRUE;
   else
      lf.lfUnderline = FALSE;

   if( hb_parl(7) )
      lf.lfStrikeOut = TRUE;
   else
      lf.lfStrikeOut = FALSE;

   lf.lfCharSet = ( BYTE ) hb_parni( 8 );

   cf.lStructSize = sizeof( CHOOSEFONT );
   cf.hwndOwner = hwnd;
   cf.hDC = ( HDC ) NULL;
   cf.lpLogFont = &lf;
   cf.Flags = HB_ISNUM( 9 ) ? hb_parni( 9 ) : CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
   cf.rgbColors = hb_parnl( 5 );
   cf.lCustData = 0L;
   cf.lpfnHook = ( LPCFHOOKPROC ) NULL;
   cf.lpTemplateName = ( LPSTR ) NULL;
   cf.hInstance = ( HINSTANCE ) NULL;
   cf.lpszStyle = ( LPSTR ) NULL;
   cf.nFontType = SCREEN_FONTTYPE;
   cf.nSizeMin = 0;
   cf.nSizeMax = 0;

   if( !ChooseFont(&cf) )
   {
      hb_reta( 8 );
      HB_STORC( "", -1, 1 );
      HB_STORNL( ( LONG ) 0, -1, 2 );
      HB_STORL( 0, -1, 3 );
      HB_STORL( 0, -1, 4 );
      HB_STORNL( 0, -1, 5 );
      HB_STORL( 0, -1, 6 );
      HB_STORL( 0, -1, 7 );
      HB_STORNI( 0, -1, 8 );
      ReleaseDC( hwnd, hdc );
      return;
   }

   PointSize = -MulDiv( lf.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY) );

   if( lf.lfWeight == 700 )
      bold = 1;
   else
      bold = 0;

   hb_reta( 8 );
   HB_STORC( lf.lfFaceName, -1, 1 );
   HB_STORNL( ( LONG ) PointSize, -1, 2 );
   HB_STORL( bold, -1, 3 );
   HB_STORL( lf.lfItalic, -1, 4 );
   HB_STORNL( cf.rgbColors, -1, 5 );
   HB_STORL( lf.lfUnderline, -1, 6 );
   HB_STORL( lf.lfStrikeOut, -1, 7 );
   HB_STORNI( lf.lfCharSet, -1, 8 );

   ReleaseDC( hwnd, hdc );
}

HB_FUNC( C_GETFILE )
{
   OPENFILENAME ofn;
   char buffer[ 32768 ];
   char cFullName[ 256 ][ 1024 ];
   char cCurDir[ 512 ];
   char cFileName[ 512 ];
   int iPosition = 0;
   int iNumSelected = 0;
   int n;

   DWORD flags = OFN_FILEMUSTEXIST;

   buffer[ 0 ] = 0;

   if( hb_parl(4) )
      flags = flags | OFN_ALLOWMULTISELECT | OFN_EXPLORER;

   if( hb_parl(5) )
      flags = flags | OFN_NOCHANGEDIR;

   memset( ( void * ) &ofn, 0, sizeof( OPENFILENAME ) );
   ofn.lStructSize = sizeof( ofn );
   ofn.hwndOwner = GetActiveWindow();
   ofn.lpstrFilter = hb_parc( 1 );
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = buffer;
   ofn.nMaxFile = sizeof( buffer );
   ofn.lpstrInitialDir = hb_parc( 3 );
   ofn.lpstrTitle = hb_parc( 2 );
   ofn.nMaxFileTitle = 512;
   ofn.Flags = flags;

   if( GetOpenFileName(&ofn) )
   {
      if( ofn.nFileExtension != 0 )
         hb_retc( ofn.lpstrFile );
      else
      {
         wsprintf( cCurDir, "%s", &buffer[ iPosition ] );
         iPosition = iPosition + strlen( cCurDir ) + 1;

         do
         {
            iNumSelected++;
            wsprintf( cFileName, "%s", &buffer[ iPosition ] );
            iPosition = iPosition + strlen( cFileName ) + 1;
            wsprintf( cFullName[ iNumSelected ], "%s\\%s", cCurDir, cFileName );
         }
         while( ( strlen(cFileName) != 0 ) && ( iNumSelected <= 255 ) );

         if( iNumSelected > 1 )
         {
            hb_reta( iNumSelected - 1 );

            for( n = 1; n < iNumSelected; n++ )
               HB_STORC( cFullName[ n ], -1, n );
         }
         else
            hb_retc( &buffer[ 0 ] );
      }
   }
   else
      hb_retc( "" );
}

// JK JP

// JK HMG 1.0 Experimental Build 8
// --- callback function for C_BROWSEFORFOLDER(). Contributed By Andy Wos

HB_FUNC( SELECTFOLDER2 )
{
   BROWSEINFO bi;
   TCHAR lpBuffer[ MAX_PATH ];
   LPCTSTR lpResult = NULL;
   LPITEMIDLIST pidlBrowse;     // PIDL selected by user
   void * hTitle;

   SHGetSpecialFolderLocation( GetActiveWindow(), HB_ISNIL(2) ? CSIDL_DRIVES : hb_parni(2), &pidlBrowse );

   bi.hwndOwner = GetActiveWindow();
   bi.pidlRoot = pidlBrowse;
   bi.pszDisplayName = lpBuffer;
   bi.lpszTitle = HB_PARSTRDEF( 1, &hTitle, NULL );
   bi.ulFlags = BIF_USENEWUI;
   bi.lpfn = NULL;
   bi.lParam = 0;
   bi.iImage = 0;

   // Browse for a folder and return its PIDL.

   pidlBrowse = SHBrowseForFolder( &bi );

   if( pidlBrowse )
   {
      SHGetPathFromIDList( pidlBrowse, lpBuffer );
      hb_retc( lpBuffer );
   }
   else
      hb_retc( "" );

   /*pidlBrowse = SHBrowseForFolder( &bi );
   if( pidlBrowse != NULL )
   {
      if( SHGetPathFromIDList( pidlBrowse, lpBuffer ) )
         lpResult = lpBuffer;
      CoTaskMemFree( pidlBrowse );
   }
   HB_RETSTR( lpResult ); */
   hb_strfree( hTitle );
}

HB_FUNC( CHOOSECOLOR )
{
   CHOOSECOLOR cc;
   COLORREF crCustClr[ 16 ];
   int i;

   for( i = 0; i < 16; i++ )
      crCustClr[ i ] = ( HB_ISARRAY(3) ? ( COLORREF ) HB_PARNL(3, i + 1) : GetSysColor(COLOR_BTNFACE) );

   cc.lStructSize = sizeof( CHOOSECOLOR );
   cc.hwndOwner = HB_ISNIL( 1 ) ? GetActiveWindow() : ( HWND ) hb_parnl( 1 );
   cc.rgbResult = ( COLORREF ) HB_ISNIL( 2 ) ? 0 : hb_parnl( 2 );
   cc.lpCustColors = crCustClr;
   cc.Flags = ( WORD ) ( HB_ISNIL(4) ? CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT : hb_parnl(4) );

   if( !ChooseColorA(&cc) )
      hb_retnl( -1 );
   else
      hb_retnl( cc.rgbResult );
}
#pragma ENDDUMP
 
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: change ChooseColor() Background Color

Post by Jimmy »

hi,

thx for Answer

i have try to use Function which you have upload

Code: Select all | Expand

CHOOSEFONT()
C_GETFILE()
SELECTFOLDER2()
CHOOSECOLOR()
but Source crash with lot Error e.g. Line 10 where is

Code: Select all | Expand

#include
but no filename behind :shock:

---

my Problem are not "Common Dialog" itself ... i want "Dark-Mode"

but i don´t "see" how i can "paint it black"
that was what i ask ChatPGT and Answer was
If 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:
not sure if i understand Answer right as my Sample seem not to change Color of "Common Dialog" :(
greeting,
Jimmy
User avatar
Detlef
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: change ChooseColor() Background Color

Post by Detlef »

I already asked ChatGpt some questions concerning xHarbour.
None of the answers were free of errors.

Sometimes natural intelligence beats artificial intelligence. :D
User avatar
Rick Lipkin
Posts: 2677
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA
Been thanked: 2 times

Re: change ChooseColor() Background Color

Post by Rick Lipkin »

Opinion ...

It seems almost everyone is rushing to AI ... the worlds largest fast food company McDonalds is preparing to lay-off thousands of workers in favor of AI automation .. at what point do Humans become the enslaved and the Machines become the Masters .. We are in the midst of an AI revolution and the beginning of "Skynet" starts now and we all know how that ends ..

Rick Lipkin

https://www.foxbusiness.com/economy/mcd ... ces-report

https://www.foxbusiness.com/technology/ ... t-out-work
Post Reply