ComboBoxGadget() COLOR

Anfängerfragen zum Programmieren mit PureBasic.
Benutzeravatar
Velindos
Beiträge: 598
Registriert: 15.11.2010 10:56

ComboBoxGadget() COLOR

Beitrag 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
Windows 7/8/8.1/10 (32/64-Bit) |Ubuntu 10.4 (64-Bit) |Purebasic 5.71 LTS (32/64-Bit)
Andreas21
Beiträge: 390
Registriert: 30.08.2004 09:05
Computerausstattung: Desktop
Windows 10 Pro x64
CPU: AMD Ryzen 5 2600 3.40 GHz
Ram: 16GB RAM
Grafik: NVIDA Geforce 1060
PB: 5.72 X86/X64
Wohnort: Heidelberg

Re: ComboBoxGadget() COLOR

Beitrag von Andreas21 »

Windows 10 x64 Pro - PB 5.61 X64 / x32 - PB 4.6 x32
Benutzeravatar
Velindos
Beiträge: 598
Registriert: 15.11.2010 10:56

Re: ComboBoxGadget() COLOR

Beitrag 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!
Windows 7/8/8.1/10 (32/64-Bit) |Ubuntu 10.4 (64-Bit) |Purebasic 5.71 LTS (32/64-Bit)
Benutzeravatar
Bisonte
Beiträge: 2427
Registriert: 01.04.2007 20:18

Re: ComboBoxGadget() COLOR

Beitrag 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:
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
Antworten