TextGadget on PanelGadget with panels with background color

Just starting out? Need help? Post your questions and find answers here.
Lima
User
User
Posts: 40
Joined: Tue Jul 14, 2015 2:52 pm

TextGadget on PanelGadget with panels with background color

Post by Lima »

The code I put together below works fine with PB 6.01.
With PB 6.02 the TextGadget(10,50,60,100,20,"ddgdfswewe") has a black background color, and nothing can be read.
The solutions I found are using ImageGadget() or ContainerGadget() to get the background color of the PanelGadget, or activating the commented line in the code SetGadgetColor(10,#PB_Gadget_BackColor,$ABABAB).
Any of these solutions requires changing many points of the application.
Is there a simpler solution?
Or wait for this problem to be fixed in future versions?

(The problem was found on Win 10 and Win 11.)

Thanks in advance for any ideas.

Code: Select all

 
 If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    PanelGadget     (0, 8, 8, 306, 203)
      AddGadgetItem (0, -1, "Panel 1")
        PanelGadget (1, 5, 5, 290, 166)
          AddGadgetItem(1, -1, "Sub-Panel 1")
          AddGadgetItem(1, -1, "Sub-Panel 2")
          AddGadgetItem(1, -1, "Sub-Panel 3")
        CloseGadgetList()
      AddGadgetItem (0, -1,"Panel 2")
        ButtonGadget(2, 10, 15, 80, 24,"Button 1")
        ButtonGadget(3, 95, 15, 80, 24,"Button 2")
        
        TextGadget(10,50,60,100,20,"ddgdfswewe")
;          SetGadgetColor(10,#PB_Gadget_BackColor,$ABABAB)
        
        CloseGadgetList()
        
        SetGadgetState(0, 1)
  
brush  = CreateSolidBrush_($ABABAB)

SetWindowTheme_(GadgetID(0), @null.w, @null.w)

        SetClassLongPtr_(GadgetID(0), #GCL_HBRBACKGROUND, brush)
      
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
    
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: TextGadget on PanelGadget with panels with background color

Post by BarryG »

Lima wrote: Wed Jun 07, 2023 12:14 pm The code I put together below works fine with PB 6.01.
With PB 6.02 the TextGadget(10,50,60,100,20,"ddgdfswewe") has a black background color, and nothing can be read.
PureBasic 6.02 has changed the way it subclasses things, so it's not going to be fixed as such. You're in the same boat as me: lots of points in my code where things don't work in 6.02 anymore, so I have to stay with 6.01 now.
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: TextGadget on PanelGadget with panels with background color

Post by NicknameFJ »

Hi !

I´ve had the same/similar problem. I wanted to colorize the active Panel with OwnerDraw

See the german forum.

https://www.purebasic.fr/german/viewtopic.php?t=32987

Geetings

NicknameFJ


Code: Select all

Import "Comctl32.lib" 
  ; use the PureBasic Syntax (Windows API Functions using trailing underscore) 
  ; 
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    SetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, dwRefData)  As "SetWindowSubclass" 
    GetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, *dwRefData) As "GetWindowSubclass"
    RemoveWindowSubclass_(hWnd, *fnSubclass, uIdSubclass)          As "RemoveWindowSubclass"
    DefSubclassProc_(hWnd, uMsg, wParam, lParam)                   As "DefSubclassProc"
  CompilerElse
    SetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, dwRefData)  As "_SetWindowSubclass@16" 
    GetWindowSubclass_(hWnd, *fnSubclass, uIdSubclass, *dwRefData) As "_GetWindowSubclass@16"
    RemoveWindowSubclass_(hWnd, *fnSubclass, uIdSubclass)          As "_RemoveWindowSubclass@12"
    DefSubclassProc_(hWnd, uMsg, wParam, lParam)                   As "_DefSubclassProc@16" 
  CompilerEndIf
EndImport 


#Window_Einstellung_Benutzer = 1
#Panel_Einstellungen_Benutzer = 10
#Panel_Option_2 = 11
#Text_HauptAnsicht = 20
#Checkbox_Hauptansicht = 21
#Combobox_hauptansicht = 22


; ---------------------------------------------------------------------------------------------------------------------
;  SubclasssWindowProc .. (all in one) 
; ---------------------------------------------------------------------------------------------------------------------

Define hBrushStatic 


Procedure SubclassWindowProc(hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) 
  Shared hBrushStatic 
  Protected bkcolor 

  Select uMsg 
    Case #WM_NCDESTROY 
      RemoveWindowSubclass_(hWnd, @SubclassWindowProc(), uIdSubclass)  ; return is non-zero if successful 

    Case #WM_CTLCOLORSTATIC
      SetTextColor_(wParam, #Black) 
      bkcolor = GetSysColor_(#COLOR_BTNFACE) 
     ;bkcolor = GetSysColor_(#COLOR_INFOBK) 
      SetBkColor_(wParam, bkcolor) 

      If hBrushStatic = #Null 
        hBrushStatic = CreateSolidBrush_(bkcolor) 
      EndIf 
      ProcedureReturn hBrushStatic 
    
    Case #WM_DESTROY 
      DeleteObject_(hBrushStatic)  ; not needed with GetSysColorBrush_(), but with CreateSolidBrush_() 

    Case #WM_DRAWITEM 
      Protected *drawItem.DRAWITEMSTRUCT 
      Protected text.s, textColor, brush  

      *drawItem = lParam  ; type cast :) 

      ; 
      ; here we can use uIdSubclass (assigned #Panel_Einstellungen_Benutzer) 
      ;
      
      If wParam = uIdSubclass 
        If *drawItem\itemID <> -1 And *drawItem\CtlType = #ODT_TAB  
          text = GetGadgetItemText(wParam, *drawItem\itemID) 

          brush = CreateSolidBrush_(GetSysColor_(#COLOR_3DFACE)) 
          If (*drawItem\itemState & #ODS_SELECTED) <> 0  ; for the selected tab we use RED 
            textColor = #Red
          Else   
            textColor = GetSysColor_(#COLOR_WINDOWTEXT) 
          EndIf 

          FillRect_(*drawItem\hdc, *drawItem\rcItem, brush) 
          DeleteObject_(brush)  ; no longer needed 
          SetTextColor_(*drawItem\hdc, textColor) 
          SetBkMode_(*drawItem\hdc, #TRANSPARENT)  

          DrawText_(*drawItem\hdc, @text, Len(text), *drawItem\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER | #DT_NOCLIP)
         ;TextOut_(*drawItem\hdc, *drawItem\rcItem\left+2, *drawItem\rcItem\top, @text, Len(text)) 

          ProcedureReturn 0  
        EndIf 
      EndIf ; wParam = uIdSubclass  

  EndSelect 
  ProcedureReturn DefSubclassProc_(hWnd, uMsg, wParam, lParam) 
EndProcedure
  


If OpenWindow(#Window_Einstellung_Benutzer, 0, 0, 720,400, "Einstellungen",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  
  PanelGadget(#Panel_Einstellungen_Benutzer,0,0,720,350)
  SetWindowLong_(GadgetID(#Panel_Einstellungen_Benutzer), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_Einstellungen_Benutzer), #GWL_STYLE) | #TCS_OWNERDRAWFIXED) 
  SetWindowSubclass_(WindowID(#Window_Einstellung_Benutzer), @SubclassWindowProc(), #Panel_Einstellungen_Benutzer, 0) 
  
  AddGadgetItem(#Panel_Einstellungen_Benutzer,-1,"Auswertung")
  AddGadgetItem(#Panel_Einstellungen_Benutzer,-1,"Ansicht")
  
  PanelGadget(#Panel_Option_2,0,0,600,250)
  SetWindowLong_(GadgetID(#Panel_Option_2), #GWL_STYLE, GetWindowLong_(GadgetID(#Panel_Option_2), #GWL_STYLE) | #TCS_OWNERDRAWFIXED) 
  SetWindowSubclass_(GetParent_(GadgetID(#Panel_Option_2)), @SubclassWindowProc(), #Panel_Option_2, 0) 
  
  AddGadgetItem(#Panel_Option_2,-1,"TEST")
  AddGadgetItem(#Panel_Option_2,-1,"noch ein Test")
  
  TextGadget(#Text_HauptAnsicht,10,20,100,24,"Vollauswertung")
  SetWindowSubclass_(GetParent_(GadgetID(#Text_HauptAnsicht)), @SubclassWindowProc(), 0, 0) 
  CheckBoxGadget(#checkbox_Hauptansicht,10,50,100,24,"CHECK IT")
  ComboBoxGadget(#Combobox_Hauptansicht,10,80,100,24)
  
  AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 1")
  AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 2")
  AddGadgetItem(#Combobox_Hauptansicht,-1,"Auswahl 3")
  SetGadgetState(#Combobox_hauptansicht,1)
  
  
  CloseGadgetList()  ; <-- this should be added 
  CloseGadgetList()
  
  
  Repeat :  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf

PS: Sorry for my weird english, but english is not my native language.



Image
Post Reply