Transparent Layered Window -Opaque Title Bar?

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Transparent Layered Window -Opaque Title Bar?

Post by IdeasVacuum »

Transparent window, the title bar is also transparent:

Code: Select all

#Win = 0
iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SystemMenu

If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)

                SetWindowColor(#Win, RGB(100,080,200))
             SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
   SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
                    HideWindow(#Win, #False)
                  StickyWindow(#Win, #True)
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Is there a way to set the title bar Opaque?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Transparent Layered Window -Opaque Title Bar?

Post by RSBasic »

Do you mean like this?

Code: Select all

EnableExplicit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(255, 0, 0))
  SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED)
  SetLayeredWindowAttributes_(WindowID(0), RGB(255, 0, 0), 0, #LWA_COLORKEY)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Image
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Transparent Layered Window -Opaque Title Bar?

Post by RASHAD »

Maybe

Code: Select all

#Win = 0
#Win1 = 1

Procedure WindowProc(hWnd,uMsg,wParam,lParam)
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case  #WM_SIZE,#WM_MOVE
        ResizeWindow(#Win1,WindowX(#Win,#PB_Window_InnerCoordinate), WindowY(#Win,#PB_Window_InnerCoordinate),WindowWidth(#Win),WindowHeight(#Win))
           
    Case #WM_NCACTIVATE
            Result = 1

  EndSelect
  ProcedureReturn Result
EndProcedure

iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget

If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)

                SetWindowColor(#Win, RGB(100,080,200))
             SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
   SetLayeredWindowAttributes_(WindowID(#Win), RGB(100,080,200), 0, #LWA_COLORKEY)
                  StickyWindow(#Win, #True)
  OpenWindow(#Win1, WindowX(#Win,#PB_Window_InnerCoordinate), WindowY(#Win,#PB_Window_InnerCoordinate), 200, 200, "", #PB_Window_BorderLess,WindowID(#Win))
                  SetWindowColor(#Win1, RGB(100,080,200))
             SetWindowLongPtr_(WindowID(#Win1), #GWL_EXSTYLE, #WS_EX_LAYERED)
   SetLayeredWindowAttributes_(WindowID(#Win1), 0, 100, #LWA_ALPHA)
EndIf

SetActiveWindow(#Win)
SetWindowCallback(@WindowProc())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Transparent Layered Window -Opaque Title Bar?

Post by IdeasVacuum »

Hi RSBasic

Not really, because with COLORKEY it's all or nothing, you can't control the % of transparency or colour as you can with LWA_ALPHA.

Take a look at Rashad's solution - one to add to your WinAPI Library?
Last edited by IdeasVacuum on Thu Apr 19, 2018 12:03 am, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Transparent Layered Window -Opaque Title Bar?

Post by IdeasVacuum »

Hi Rashad

That is a seriously clever idea, works perfectly!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Transparent Layered Window -Opaque Title Bar?

Post by BarryG »

How do we remove this later:

Code: Select all

SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
For when we don't want the window to be transparent anymore?
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Transparent Layered Window -Opaque Title Bar?

Post by Demivec »

BarryG wrote:For when we don't want the window to be transparent anymore?

Code: Select all

; Add WS_EX_LAYERED to window styles
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)

;set transparency
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)

; Remove WS_EX_LAYERED from this window styles
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE) & ~#WS_EX_LAYERED)

; Ask the window And its children To repaint
RedrawWindow_(WindowID(#Win), #Null, #Null, #RDW_ERASE | #RDW_INVALIDATE | #RDW_FRAME | #RDW_ALLCHILDREN)
@Edit: You can also reset the alpha level back to full but that won't free any memory that's been reserved to process the alpha.
Last edited by Demivec on Sat Oct 26, 2019 12:42 am, edited 3 times in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Transparent Layered Window -Opaque Title Bar?

Post by RASHAD »

Hi BarryG

Code: Select all

#Win = 0
iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SystemMenu

If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)
  ButtonGadget(0,10,170,60,24,"Change")
                SetWindowColor(#Win, RGB(100,080,200))
             SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
   SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
                  StickyWindow(#Win, #True)
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          run ! 1
          If run = 1
            SetLayeredWindowAttributes_(WindowID(#Win), 0, 255, #LWA_ALPHA)
          Else
            SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
          EndIf
          
      EndSelect
  EndSelect
Until Quit = 1
Egypt my love
Post Reply