FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Combobox background color
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Combobox background color
Posted: Tue Jun 17, 2025 08:48 AM

Hi,

I have a dialog with a lot of comboboxes, and the default item is an empty one.

The user must select something.

Is it possible to make the background red if it's empty, so the user have a better overview which one is still empty.

I don't want the list of items with a other background, only the box.

Thank you,

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Combobox background color
Posted: Tue Jun 17, 2025 02:18 PM

It is possible only if you deactivate the theme for your app or for each combobox you want to colorize. Otherwise, Windows takes care of the comboboxes colors.

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Combobox background color
Posted: Thu Jun 19, 2025 04:54 PM
hi,
Marc Vanzegbroeck wrote: Is it possible to make the background red if it's empty, so the user have a better overview which one is still empty.
you must use Ownerdraw to get "none System Colors" see this
      oCombo_left := TComboBox() :new( 0, 0,, acItem, 90, 300, oMain,,,, BFcolor, BGcolor, .T., oFontDefault,,,, .F., acBitmaps )
      oCombo_left:nDropWidth( 200 )
      oCombo_left:nItemHeight( 32 )
      oCombo_left:nSelectionHeight( 32 )
      oCombo_left:Select( DriveNumber( cStartLeft ) )
      oCombo_left:bCloseUp := { || Change2Drive( oCombo_left:GetSelText(), 1 ) }
      oCombo_left:lIncSearch := .T.

      __ChangeStyleWindow( oCombo_left:hWnd, WS_TABSTOP,, .F. )

      oCombo_left:bOwnerDraw := { | a, b, c, d | oExpl_Left:DoMyComBo( a, b, c, d, @acItem, @acType, @acBitmaps, oCombo_left ) }
      oCombo_left:GetKeyChar( ASC( SUBSTR( cHome, 1, 1 ) ) )

***
METHOD DoMyComBo() CLASS TExplorer

LOCAL WinDir        := GETENV( "Windir" )
LOCAL cPara         := ""
LOCAL cAlign        := nOr( DT_LEFT, DT_NOPREFIX )
LOCAL nIcoHandle    := 0
LOCAL nSize         := 32
LOCAL ii, nCount, xPara
LOCAL oSelf
LOCAL nIdCtl
LOCAL oStruc
LOCAL nPointer
LOCAL acItem, acType, cItemText, oObj
LOCAL CtlType
LOCAL CtlID
LOCAL itemID
LOCAL itemAction
LOCAL itemState
LOCAL hwndItem
LOCAL hDC
LOCAL aRect
LOCAL nLeft
LOCAL nTop
LOCAL nRight
LOCAL nBottom
LOCAL itemData
LOCAL cDLL
LOCAL hModule
LOCAL nResID        := 0
LOCAL cBitmap, hBitMap, acBitmaps, aBitmaps
LOCAL OldAt         := - 1
LOCAL BrushHiBack   := CreateSolidBrush( BFcolor )
LOCAL BrushSysColor := CreateSolidBrush( BGcolor )
LOCAL aGrad         := { ;
                    { .5, BFcolor, BGcolor }, ;
                    { .6, BGcolor, BFcolor } ;
                    }

   nCount := PCOUNT()
   FOR ii := 1 TO nCount
      xPara := PValue( ii )
      DO CASE
         CASE ii = 1
            oSelf := xPara
         CASE ii = 2
            nIdCtl := xPara
         CASE ii = 3
            oStruc := xPara
         CASE ii = 4
            nPointer := xPara

         CASE ii = 5
            acItem := xPara
         CASE ii = 6
            acType := xPara
         CASE ii = 7
            acBitmaps := xPara
         CASE ii = 8
            oObj := xPara
            IF !EMPTY( oObj )
               IF VALTYPE( oObj ) = "O"
                  OldAt := oObj:nAt

                  oObj:SetBitmaps( acBitmaps )
               ENDIF
            ENDIF
      ENDCASE
   NEXT

   CtlType := oStruc:CtlType
   CtlID := oStruc:CtlID
   itemID := oStruc:itemID
   itemAction := oStruc:itemAction
   itemState := oStruc:itemState
   hwndItem := oStruc:hwndItem
   hDC := oStruc:hDC
   aRect := oStruc:aRect
   itemData := oStruc:itemData

   nTop := aRect[ 1 ]
   nLeft := aRect[ 2 ]
   nBottom := aRect[ 3 ]
   nRight := aRect[ 4 ]

   IF CtlType = ODT_COMBOBOX .OR. CtlType = ODT_LISTBOX               // .AND. CtlID =

      SetBkMode( hDC, 1 )                                             // TRANSPARENT =1 OPAQUE =2

      DO CASE
         CASE itemAction = ODA_SELECT
            FillRect( hDC, aRect, BrushSysColor )
            SetTextColor( hDC, BFcolor )

         CASE itemAction = ODA_DRAWENTIRE
            IF OldAt = itemID + 1 .AND. oObj:IsOpen()
               OldAt = - 1
               IF BGColor = 256 * 256 * 256 - 1                       // 16777215
                  //  Msginfo("white")
                  FillRect( hDC, aRect, COLOR_MENUHILIGHT + 1 )
                  SetTextColor( hDC, GetSysColor( COLOR_MENU ) )
               ELSE
                  GradientFill( hDC, aRect[ 1 ], aRect[ 2 ], aRect[ 3 ] - 1, aRect[ 4 ], aGrad, .t. )
                  //                FillRect( hDC, aRect, BrushSysColor )
                  SetTextColor( hDC, BFcolor )
               ENDIF
            ELSE
               FillRect( hDC, aRect, BrushSysColor )
               SetTextColor( hDC, BFcolor )
            ENDIF

         CASE itemAction = ODA_FOCUS
            IF BGColor = 256 * 256 * 256 - 1                          // 16777215
               FillRect( hDC, aRect, COLOR_MENUHILIGHT + 1 )
               SetTextColor( hDC, GetSysColor( COLOR_MENU ) )
            ELSE
               GradientFill( hDC, aRect[ 1 ], aRect[ 2 ], aRect[ 3 ] - 1, aRect[ 4 ], aGrad, .t. )
               //                FillRect( hDC, aRect, BrushSysColor )
               SetTextColor( hDC, BFcolor )
            ENDIF

      ENDCASE

#define Work_System
#IFDEF Work_System
      // use System Icon from DLL
      IF !EMPTY( acType )

         cDLL := WinDir + "\System32\imageres.dll"

         DO CASE
            CASE acType[ itemID + 1 ] = DRIVE_UNKNOWN
               nResID := 75
            CASE acType[ itemID + 1 ] = DRIVE_NO_ROOT_DIR
               nResID := 32

            CASE acType[ itemID + 1 ] = DRIVE_REMOVABLE
               IF SUBSTR( acItem[ itemID + 1 ], 1, 1 ) $ "AB"
                  nResID := 23
               ELSE
                  cDLL := WinDir + "\System32\DDORes.dll"
                  nResID := 2389
               ENDIF

            CASE acType[ itemID + 1 ] = DRIVE_FIXED
               IF SUBSTR( acItem[ itemID + 1 ], 1, 2 ) = "C:"
                  nResID := 36
               ELSE
                  nResID := 32
               ENDIF
            CASE acType[ itemID + 1 ] = DRIVE_REMOTE
               nResID := 33
            CASE acType[ itemID + 1 ] = DRIVE_CDROM
               nResID := 30
            CASE acType[ itemID + 1 ] = DRIVE_RAMDISK
               nResID := 34

         ENDCASE

         IF !EMPTY( nResID )
            hModule := GetModuleHandle( cDLL )
            IF hModule == 0
               hModule := LoadLibrary( cDLL )
            ENDIF
            nIcoHandle := LOADIMAGERESICON( hModule, nResID, 32 )

            DrawIconEx( hDC, ;
                        nTop - 4, ;
                        nLeft, ;
                        nIcoHandle, ;
                        nSize, ;
                        nSize, ;
                        0, ;                                          // _In_     UINT   istepIfAniCur,
                        0, ;                                          // _In_opt_ HBRUSH hbrFlickerFreeDraw,
                        nOr( DI_NORMAL ) )                            // _In_     UINT   diFlags

            DestroyIcon( nIcoHandle )
            FreeLibrary( hModule )
         ENDIF

      ENDIF
#ELSE

      DO CASE
         CASE acType[ itemID + 1 ] = DRIVE_UNKNOWN
            cBitmap := "MYUNKNOWN16"

         CASE acType[ itemID + 1 ] = DRIVE_NO_ROOT_DIR
            cBitmap := "MYFIXDRIVE16"

         CASE acType[ itemID + 1 ] = DRIVE_REMOVABLE
            IF SUBSTR( acItem[ itemID + 1 ], 1, 1 ) $ "AB"
               cBitmap := "MYFLOPPY16"                                // Floppy
            ELSE
               cBitmap := "MYUSBSTICK16"                              // DRIVE_REMOVABLE
            ENDIF

         CASE acType[ itemID + 1 ] = DRIVE_FIXED
            IF SUBSTR( acItem[ itemID + 1 ], 1, 1 ) = "C"
               cBitmap := "MYSYSDRIVE16"
            ELSE
               cBitmap := "MYFIXDRIVE16"
            ENDIF
         CASE acType[ itemID + 1 ] = DRIVE_REMOTE
            cBitmap := "MYNETDRIVE16"
         CASE acType[ itemID + 1 ] = DRIVE_CDROM
            cBitmap := "MYCDROM16"
         CASE acType[ itemID + 1 ] = DRIVE_RAMDISK
            cBitmap := "MYRAMDISK16"
         OTHERWISE
            cBitmap := "MYUNKNOWN16"
      ENDCASE

      aBitmaps := FW_ReadImage( nil, acBitmaps[ itemID + 1 ], { nSize - 2, nSize - 2 }, .F. )
      hBitMap := aBitmaps[ 1 ]

      DrawBitmap( hDC, hBitMap, nTop + 3, nLeft, nSize - 3, nSize - 6 )

      PalBmpFree( aBitmaps )
      DeleteObject( hBitMap )

#ENDIF

      nLeft += 32 + 4

      cItemText := acItem[ itemID + 1 ]

      DrawText( hDC, ;
                cItemText, ;
                { nTop + 4, nLeft, nBottom, nRight }, ;
                cAlign )
   ENDIF

   DeleteObject( BrushHiBack )
   DeleteObject( BrushSysColor )

RETURN .T.
greeting,

Jimmy
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Combobox background color
Posted: Fri Jun 20, 2025 06:58 AM

Thank you Jimmy,

I will investigate your example

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite

Continue the discussion