PB5.50; ToolBar; background color;

Windows specific forum
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

PB5.50; ToolBar; background color;

Post by HanPBF »

Hello,

how can I change the background color of a toolbar?


Thanks in advance!
Regards
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB5.50; ToolBar; background color;

Post by RSBasic »

Code: Select all

EnableExplicit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If OpenWindow(1, 0, 0, WindowWidth(0), 22, "", #WS_CHILD, WindowID(0))
    If CreateToolBar(1, WindowID(1))
      ToolBarStandardButton(1, #PB_ToolBarIcon_New)
      ToolBarStandardButton(2, #PB_ToolBarIcon_Open)
      ToolBarStandardButton(3, #PB_ToolBarIcon_Save)
      
      SendMessage_(ToolBarID(1), #TB_SETSTYLE, 0, SendMessage_(ToolBarID(1), #TB_GETSTYLE, 0, 0) | #CCS_NODIVIDER)
    EndIf
    
    SetWindowColor(1, RGB(0, 150, 255))
  EndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Image
Image
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: PB5.50; ToolBar; background color;

Post by HanPBF »

Thanks a lot!

I saw that height of buttons can not be set.
So I changed dev to CanvasGadget.

Anyway, RSBasic.de is always a great help!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PB5.50; ToolBar; background color;

Post by netmaestro »

I see it's already solved but I worked on this so you get it anyway:

Code: Select all

Procedure ToolbarProc(hwnd, msg, wparam, lparam)
  Shared hBrush
  oldproc = GetProp_(hwnd, "oldproc")
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
      
    Case #WM_ERASEBKGND
      hdc = wparam
      GetClientRect_(hwnd, @rc.RECT)
      FillRect_(hdc, @rc, hBrush)
      
    Case #WM_PAINT
      hdc = BeginPaint_(hwnd, @ps.PAINTSTRUCT)
      bcount = SendMessage_(hwnd, #TB_BUTTONCOUNT,0,0)
      hotitem = SendMessage_(hwnd, #TB_GETHOTITEM,0,0)
      imglist = SendMessage_(hwnd, #TB_GETIMAGELIST, 0, 0)
      For i = 0 To bcount-1
        SendMessage_(hwnd, #TB_GETBUTTON, i, @thisbutton.TBBUTTON)
        SendMessage_(hwnd, #TB_GETITEMRECT, i, @rc.RECT)
        If thisbutton\fsState & #TBSTATE_PRESSED
          ImageList_Draw_(imglist, thisbutton\iBitmap, hdc,rc\left+5,rc\top+5,#ILD_NORMAL)
        Else
          ImageList_Draw_(imglist, thisbutton\iBitmap, hdc,rc\left+4,rc\top+4,#ILD_NORMAL)
          If i=hotitem
            DrawFocusRect_(hdc, @rc)
          EndIf
        EndIf
      Next
      EndPaint_(hwnd, ps)
      
  EndSelect
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure

hBrush = CreateSolidBrush_(RGB(255,255,223))

If OpenWindow(0, 0, 0, 150, 250, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  toolbar = CreateToolBar(0, WindowID(0))
  SetProp_(toolbar, "oldproc", SetWindowLongPtr_(toolbar, #GWL_WNDPROC, @ToolbarProc()))
  ToolBarStandardButton(0, #PB_ToolBarIcon_New)
  ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
  ToolBarStandardButton(2, #PB_ToolBarIcon_Save)

  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Menu
      Debug "ToolBar ID: "+Str(EventMenu())
    EndIf
  Until Event = #PB_Event_CloseWindow 
EndIf
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: PB5.50; ToolBar; background color;

Post by RASHAD »

#1 :

Code: Select all

Procedure sizeCB()
  ResizeGadget(1,#PB_Ignore, #PB_Ignore,WindowWidth(0),#PB_Ignore)
EndProcedure


If OpenWindow(0, 0, 0, 400, 260, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget|#PB_Window_ScreenCentered)

  ContainerGadget(1,0, 0,400,25,#PB_Container_BorderLess)
  SetGadgetColor(1, #PB_Gadget_BackColor, $FEFAB6)

  TB = CreateToolBar(0, GadgetID(1))
  SetClassLongPtr_(TB,#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH))
  SetWindowTheme_(TB, @null.w, @null.w) 
  For i=0 To 10 : ToolBarStandardButton(i,i) : Next
    
  CloseGadgetList()

  If CreateMenu(0, WindowID(0))
    MenuTitle("Project")
      MenuItem(0, "New")
      MenuItem(1, "Open")
      MenuItem(2, "Save")
  EndIf
  
  BindEvent(#PB_Event_SizeWindow,@sizeCB())
  
  Repeat
    Event = WaitWindowEvent()

    Select Event
    
      Case #PB_Event_Menu
        MessageRequester("Information", "ToolBar or Menu ID: "+Str(EventMenu()), 0)
        
      
      Case #PB_Event_CloseWindow 
        Quit = 1
        
    EndSelect

  Until Quit = 1
  
EndIf

End  
   
#2 :

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 0, 0, 400, 260, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget|#PB_Window_ScreenCentered)  
  SetWindowColor(0,  $FEFAB6)  
  TB = CreateToolBar(1, WindowID(0))   
  ToolBarImageButton(0,LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\world.png")) 
  ContainerGadget(1,0, 24,400,236,#PB_Container_BorderLess) 
  CloseGadgetList()
 
  Repeat
    Event = WaitWindowEvent()

    Select Event
   
      Case #PB_Event_Menu
        MessageRequester("Information", "ToolBar or Menu ID: "+Str(EventMenu()), 0)
        
      Case #PB_Event_SizeWindow
          ResizeGadget(1,#PB_Ignore, #PB_Ignore,WindowWidth(0),WindowHeight(0) - 24)       
     
      Case #PB_Event_CloseWindow
        Quit = 1
       
    EndSelect

  Until Quit = 1
 
EndIf

End 
Egypt my love
ludoke
Enthusiast
Enthusiast
Posts: 153
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

Re: PB5.50; ToolBar; background color;

Post by ludoke »

i am new .
in the examples are strange commands,like this
SendMessage_(ToolBarID(1), #TB_SETSTYLE, 0, SendMessage_(ToolBarID(1), #TB_GETSTYLE, 0, 0) | #CCS_NODIVIDER)
SetClassLongPtr_(TB,#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH)) .

I can not find in the help of PB.
these are WinAPI ?
where I can find more about it, I try to learn
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: PB5.50; ToolBar; background color;

Post by HanPBF »

Hello!

These are Win32 API commands.

A great source of examples for these is
http://www.rsbasic.de/winapi-library/

You can find help for them online from Microsoft.

But I suggest to simply search this forum or ask if something seems too complex.

PureBasic programming is fun!
Post Reply