Seite 1 von 1

ComboBoxGadget() COLOR

Verfasst: 28.04.2018 10:45
von Velindos
Hallo Leute,

wie stelle ich den Font/Backcolor beim ComboBoxGadget() ein?

Code: Alles auswählen

  UsePNGImageDecoder()
  LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
  
  If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
      AddGadgetItem(0, -1, "ComboBox editable...")

    ComboBoxGadget(1, 10, 40, 250, 21, #PB_ComboBox_Image)
      AddGadgetItem(1, -1, "ComboBox item with image", ImageID(0))

    ComboBoxGadget(2, 10, 70, 250, 21)
      For a = 1 To 5
        AddGadgetItem(2, -1,"ComboBox item " + Str(a))
      Next

    SetGadgetState(0, 0)
    SetGadgetState(1, 0)
    SetGadgetState(2, 2)    ; den dritten Eintrag (beginnend bei 0) als den aktiven Eintrag setzen
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Das Beispiel funzt unter 5.62 nicht!

Code: Alles auswählen

;Autor: Hroudtwolf
;http://www.purebasic.fr/english/viewtopic.php?p=284242#p284242

EnableExplicit

Define a

Structure tCBGEX
   hBackgroundBrush  .i
   nFrontColor       .i
   *oProc
EndStructure

Procedure _CBGExCB ( hWnd.i , idMsg.i , wParam.i , lParam.i )
   Protected *CBGEx.tCBGEX = GetProp_( hWnd , "CBGEXDATA" )
 
   Select idMsg
      Case #WM_CTLCOLOREDIT , #WM_CTLCOLORLISTBOX
      SetBkMode_( wParam , #TRANSPARENT )
      SetTextColor_( wParam , *CBGEx\nFrontColor )
      ProcedureReturn *CBGEx\hBackgroundBrush
     
      Case #WM_DESTROY
      DeleteObject_( *CBGEx\hBackgroundBrush )
      SetWindowLongPtr_( hWnd , #GWL_WNDPROC , *CBGEx\oProc )
      FreeMemory ( *CBGEx )
     
   EndSelect
 
  ProcedureReturn CallWindowProc_( *CBGEx\oProc , hWnd.i , idMsg.i , wParam.i , lParam.i )
EndProcedure

Procedure.i ComboBoxGadgetEx ( idGadget.i , nX.i , nY.i , nWidth.i , nHeight.i , btFlags.i = #Null )
   Protected nResult .i
   Protected hWnd    .i
   Protected *CBGEx  .tCBGEX
   
   nResult = ComboBoxGadget ( idGadget , nX , nY , nWidth , nHeight , btFlags )
   If Not nResult
      ProcedureReturn #Null
   EndIf
   
   If idGadget = #PB_Any
      hWnd = GadgetID ( nResult )
   Else
      hWnd = GadgetID ( idGadget )
   EndIf
   
   *CBGEx                     = AllocateMemory ( SizeOf ( tCBGEX ) )
   *CBGEx\oProc               = GetWindowLongPtr_( hWnd , #GWL_WNDPROC )
   *CBGEx\nFrontColor         = GetSysColor_( #COLOR_BTNTEXT )
   *CBGEx\hBackgroundBrush    = CreateSolidBrush_( GetSysColor_( #COLOR_WINDOW ) )
   
   SetProp_( hWnd , "CBGEXDATA" , *CBGEx )   
   SetWindowLongPtr_( hWnd , #GWL_WNDPROC , @ _CBGExCB () )
   
   InvalidateRect_( hWnd , #Null , #True )
   
   ProcedureReturn nResult
EndProcedure

Procedure.i ComboBoxGadgetEx_Color ( idGadget.i , nMode.i , nColor.i )
   Protected *CBGEx.tCBGEX 
   Protected hWnd
   
   If IsGadget ( idGadget )
      *CBGEx = GetProp_( GadgetID ( idGadget ) , "CBGEXDATA" )
      If Not *CBGEx
         ProcedureReturn #False
      EndIf   
   
      Select nMode
         Case #PB_Gadget_BackColor
         DeleteObject_( *CBGEx\hBackgroundBrush )
         *CBGEx\hBackgroundBrush = CreateSolidBrush_( nColor )
         
         Case #PB_Gadget_FrontColor
         *CBGEx\nFrontColor = nColor
         
         Default
         ProcedureReturn #False
               
      EndSelect
   
      InvalidateRect_( hWnd , #Null , #True )
      ProcedureReturn #True
   EndIf
   
   ProcedureReturn #False
EndProcedure

If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ComboBoxGadgetEx(1,10,10,480,20,0)
  
  For a=1 To 10
    AddGadgetItem(1,-1,"Testitem "+Str(a),0,0)
  Next
  
  SetGadgetState(1,0)
  
  ComboBoxGadgetEx_Color(1,#PB_Gadget_BackColor,RGB(50,50,255))
  ComboBoxGadgetEx_Color(1,#PB_Gadget_FrontColor,RGB(200,200,255))
  
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 5.31 (Windows - x64)
; CursorPosition = 2
; Folding = -
; EnableUnicode
; EnableXP
; EnableUser
; EnableCompileCount = 0
; EnableBuildCount = 0
Gruss ... Velindos

Re: ComboBoxGadget() COLOR

Verfasst: 28.04.2018 12:19
von Andreas21

Re: ComboBoxGadget() COLOR

Verfasst: 29.04.2018 10:10
von Velindos
Hallo Andreas21,
Danke für den Tip! Teileweise lässt sich das Popup einfärben, dass Combo jedoch nicht. Von der Zeile keine Rede!

Gruss ... Velindos!

Re: ComboBoxGadget() COLOR

Verfasst: 29.04.2018 12:12
von Bisonte
Man kann auch sein kreatives Gen benutzen ;)

ComboBoxGadget -> CanvasGadget
ComboBoxGadget Edit-> CanvasGadget mit ContainerFlag + StringGadget

Wenn Menu Standard -> PopupMenu
Wenn Menu Farbig -> Ein Fenster und ein Canvas

Man muss nicht immer mit der WindowsAPI alles über's Knie brechen.

Und um es gleich vorweg zu nehmen : Es ist mehr Aufwand, aber
man kann es danach sogar auf Linux und Mac zu benutzen :mrgreen: