String gadgets colors

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

String gadgets colors

Post by BackupUser »

Code updated for 5.20+ (same as SetGadgetColor())

Restored from previous forum. Originally posted by fweil.

Here is a sample code for placing background / foreground colors in different string gadgets, and also how to color a list view.

Methods are different (SendMessage_() for list view and callback for String).

Code: Select all

;=================================================================
#Background_ListView = $502828
#Foreground_ListView = $B4FFFF
#Background_Edit1 = $0000FF
#Foreground_Edit1 = $B4FFFF
#Background_Edit2 = $FF0000
#Foreground_Edit2 = $00FF00
#StringGadget1 = 100
#ListIconGadget = 101
#StringGadget2 = 102

; ColorBrush_Edit1.l
; ColorBrush_Edit2.l
; hStringGadget1.l
; hStringGadget2.l

Global ColorBrush_Edit1, ColorBrush_Edit2
Global hStringGadget1, hStringGadget2

Procedure MyWindowCallBack(WindowID.l, Message.l, wParam.l, lParam.l)
  Result.l
  Result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_CTLCOLOREDIT
      Debug "WM_CTLCOLOREDIT"
      Select lParam
        Case hStringGadget1
          SetTextColor_(wParam, #Foreground_Edit1)
          SetBkMode_(wParam, #TRANSPARENT)
          Result = ColorBrush_Edit1
        Case hStringGadget2
          SetTextColor_(wParam, #Foreground_Edit2)
          SetBkMode_(wParam, #TRANSPARENT)
          Result = ColorBrush_Edit2
        Default
      EndSelect
    Case #WM_SIZE
      ResizeGadget(#StringGadget1, 0, 0, WindowWidth(0), 100)
      ResizeGadget(#StringGadget2, 0, 240, WindowWidth(0), 80)
    Default
  EndSelect
  ProcedureReturn Result
EndProcedure

;
; Main starts here
;

hWnd.l
Quit.l

Quit = #False

ColorBrush_Edit1 = CreateSolidBrush_(#Background_Edit1)
ColorBrush_Edit2 = CreateSolidBrush_(#Background_Edit2)

hWnd = OpenWindow(0, 200, 200, 320, 320, "MyWindow", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If hWnd
  AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
  
  LoadFont(0, "Arial Black", 12)
  SetGadgetFont(#PB_Default, FontID(0))
  hStringGadget1 = StringGadget(#StringGadget1, 0, 0, 320, 100, "The quick brown fox jumps over the lazy dog ..." + Chr(13) + Chr(10) + "Voyez le brick géant que j'examine près du wharf ...", #ES_AUTOVSCROLL | #WS_VSCROLL | #WS_HSCROLL)
  hListIconGadget = ListIconGadget(#ListIconGadget, 0, 105, 320, 130, "Title", 120, 0)
  hStringGadget2 = StringGadget(#StringGadget2, 0, 240, 320, 80, "The quick brown fox jumps over the lazy dog ..." + Chr(13) + Chr(10) + "Voyez le brick géant que j'examine près du wharf ...", #ES_AUTOVSCROLL | #WS_VSCROLL | #WS_HSCROLL)
  AddGadgetColumn(#ListIconGadget, 1, "Column2", 120)
  AddGadgetColumn(#ListIconGadget, 2, "Column3", 120)
  
  SetWindowCallback(@MyWindowCallBack())
  
  For i = 0 To 1000
    Number.s = Str(i)
    While Len(Number) < 4
      Number = "0" + Number
    Wend
    AddGadgetItem(#ListIconGadget, -1, "Item" + Number + Chr(10) + "String1" + Chr(10) + "String2")
  Next
  SendMessage_(hListIconGadget, #LVM_SETTEXTBKCOLOR, 0, #Background_ListView)
  SendMessage_(hListIconGadget, #LVM_SETTEXTCOLOR, 0, #Foreground_ListView)
  SendMessage_(hListIconGadget, #LVM_SETBKCOLOR, 0, #Background_ListView)
  SendMessage_(hListIconGadget, #LVM_SETCOLUMNWIDTH, 0, #LVSCW_AUTOSIZE)
  SendMessage_(hListIconGadget, #LVM_SETCOLUMNWIDTH, 1, #LVSCW_AUTOSIZE)
  SendMessage_(hListIconGadget, #LVM_SETCOLUMNWIDTH, 2, #LVSCW_AUTOSIZE)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = #True
      Case #PB_Event_Menu
        Select EventMenu()
          Case 99
            Quit = #True
        EndSelect
    EndSelect
  Until Quit
EndIf
End
;================================================

Francois Weil
14, rue Douer
F64100 Bayonne
Last edited by fsw on Fri Aug 23, 2013 1:04 am, edited 2 times in total.
Reason: Code updated for 5.20+
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

I posted this snippet with full comments on Paul's ressource site.

This allow me to particpate the contest and test the new upload form.

BTW, this site is really nice, better than before.

KRgrds

Francois Weil
14, rue Douer
F64100 Bayonne
Post Reply