change ChooseColor() Background Color

change ChooseColor() Background Color

Postby Jimmy » Wed Apr 05, 2023 1:24 pm

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 view  RUN

// 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 view  RUN
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
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: change ChooseColor() Background Color

Postby karinha » Wed Apr 05, 2023 1:50 pm

Maybe:

https://github.com/harbour/core/blob/master/contrib/gtwvg/wvgutils.c

Code: Select all  Expand view  RUN

#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
karinha
 
Posts: 7835
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: change ChooseColor() Background Color

Postby Jimmy » Wed Apr 05, 2023 5:11 pm

hi,

thx for Answer

i have try to use Function which you have upload
Code: Select all  Expand view  RUN
CHOOSEFONT()
C_GETFILE()
SELECTFOLDER2()
CHOOSECOLOR()

but Source crash with lot Error e.g. Line 10 where is
Code: Select all  Expand view  RUN
#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
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: change ChooseColor() Background Color

Postby Detlef » Thu Apr 06, 2023 12:12 pm

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
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: change ChooseColor() Background Color

Postby Rick Lipkin » Thu Apr 06, 2023 2:17 pm

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
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 42 guests