Page 1 of 1

Transparent Toolbar

Posted: Thu May 10, 2012 2:43 pm
by javabean
I can to put a toolbar into a container gadget. But then the toolbar loses it's transparency.
Any ideas how I could restore toolbar transparency?

Demonstration code:

Code: Select all

Procedure StopToolbarAutoAlign(Toolbar)
  T = ToolBarID(Toolbar)
  SetWindowLongPtr_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NODIVIDER| #CCS_NOPARENTALIGN| #CCS_NORESIZE)  
EndProcedure

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
SetWindowColor(0, #White);white window

ContainerGadget(1,100, 100, 400, 150)
SetGadgetColor(1, #PB_Gadget_BackColor, #White);white container

CreateToolBar(0, GadgetID(1))
SendMessage_(ToolBarID(0), #TB_SETSTYLE, 0, #TBSTYLE_TRANSPARENT);set toolbar transparency: -> toolbar should be transparent now
StopToolbarAutoAlign(0);to get rid of the toolbar topline

  ;add some buttons to the toolbar
  ToolBarStandardButton(0, 0)
  ToolBarStandardButton(0, 1)
  ToolBarSeparator()
  
  ToolBarStandardButton(0, 2)
  ToolBarStandardButton(0, 3)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Re: Transparent Toolbar

Posted: Thu May 10, 2012 7:34 pm
by RASHAD
Disable XP Skin support in the Compiler Options

Code: Select all

Procedure StopToolbarAutoAlign(Toolbar)
  T = ToolBarID(Toolbar)
  SetWindowLongPtr_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NODIVIDER| #CCS_NOPARENTALIGN| #CCS_NORESIZE)  
EndProcedure

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
SetWindowColor(0, #White);white window

ContainerGadget(1,100, 100, 400, 150)
;SetGadgetColor(1, #PB_Gadget_BackColor, #White);white container

TB = CreateToolBar(0, GadgetID(1))
SendMessage_(ToolBarID(0), #TB_SETSTYLE, 0, #TBSTYLE_TRANSPARENT);set toolbar transparency: -> toolbar should be transparent now
StopToolbarAutoAlign(0);to get rid of the toolbar topline

  ;add some buttons to the toolbar
  ToolBarStandardButton(0, 0)
  ToolBarStandardButton(0, 1)
  ToolBarSeparator()
  
  ToolBarStandardButton(0, 2)
  ToolBarStandardButton(0, 3)
CloseGadgetList()

SetClassLongPtr_(GadgetID(1),#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Menu 
       Select EventMenu()
         Case 0
            InvalidateRect_(WindowID(0),0,#True)

       EndSelect
        

  EndSelect
ForEver

OR :

Code: Select all

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindow(1, 0, 360, 512, 24, "", #PB_Window_BorderLess)
SetParent_(WindowID(1),WindowID(0))
SetWindowColor(0, #White)
SetWindowColor(1, #White)

CreateToolBar(0, WindowID(1))
  ToolBarStandardButton(0, 0)
  ToolBarStandardButton(0, 1)
  ToolBarSeparator()
  
  ToolBarStandardButton(0, 2)
  ToolBarStandardButton(0, 3) 

SetWindowLongPtr_(WindowID(1), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(1), #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(1), #White, 0, #LWA_COLORKEY)

SetActiveWindow(0)


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Menu
        Select EventMenu()
          Case 0
            SetActiveWindow(0)
        EndSelect 
  EndSelect
ForEver

Re: Transparent Toolbar

Posted: Fri May 11, 2012 10:15 am
by culita
good evening from general DIMITRI CULITA.

here is your solution from netmaestro(our spy) :

Code: Select all

; Owner drawn button example
; netmaestro 2009


Prototype AlphaBlend(hdcDest,DestX,DestY,DestW,DestH,hdcSrc,SrcX,SrcY,SrcW,SrcH,BLENDFUNCTION)
msimg32 = OpenLibrary(#PB_Any, "msimg32.dll")
Global AlphaBlend_.AlphaBlend = GetFunction(msimg32, "AlphaBlend")

Global MyButton

Enumeration
  #allbuttons
  #state_normal
  #state_pressed
  #state_disabled
EndEnumeration

UsePNGImageDecoder()
LoadImage(#allbuttons, GetCurrentDirectory()+"print.png")
GrabImage(#allbuttons, #state_normal, 0,0,64,64)
GrabImage(#allbuttons, #state_pressed, 64,0,64,64)
GrabImage(#allbuttons, #state_disabled, 128,0,64,64)

Procedure WinProc(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents

  Select msg
    Case #WM_DRAWITEM
      *dis.DRAWITEMSTRUCT = lparam
      Select *dis\CtlID
        Case MyButton
          If *dis\itemState & #ODS_SELECTED ; Button is pressed
            hdc = *dis\hDC
            hdcin = StartDrawing(ImageOutput(#state_pressed))
              AlphaBlend_(hdc, 0,0,64,64,hdcin,0,0,64,64,$1FF0000)
            StopDrawing()
          Else
            If *dis\itemState & #ODS_DISABLED
              hdc = *dis\hDC
              hdcin = StartDrawing(ImageOutput(#state_disabled))
                AlphaBlend_(hdc, 0,0,64,64,hdcin,0,0,64,64,$1600000)
              StopDrawing()
            Else
              hdc = *dis\hDC
              hdcin = StartDrawing(ImageOutput(#state_normal))
                AlphaBlend_(hdc, 0,0,64,64,hdcin,0,0,64,64,$1600000)
              StopDrawing()
            EndIf
         EndIf     
     EndSelect
     
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,240,"Ownerdrawn Button Sample",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowCallback(@WinProc())
ContainerGadget(0, 120,50,68,68)
hRgn = CreateEllipticRgn_(0,0,68,68)
SetWindowRgn_(GadgetID(0),hRgn, 1)
  MyButton = ButtonGadget(#PB_Any, 1,1,64,64,"",#BS_OWNERDRAW)
CloseGadgetList()
ButtonGadget(1, 110,200,110,20,"Dis/Enable TEST")

state=0
Repeat
  EventID = WaitWindowEvent()
 
  Select EventID
    Case #PB_Event_Gadget
      Select EventGadget()
        Case MyButton
          Debug "Test pushed"
        Case 1
          state=1-state
          DisableGadget(MyButton, state)
      EndSelect
  EndSelect   

Until EventID=#PB_Event_CloseWindow

CloseLibrary(msimg32)

End


make a toolbar using this method so you got a transparent toolbar ...


boooooooooooooooooooooooom!

boooooooooom!







general DIMITRI CULITA