Transparent window in pb4

Just starting out? Need help? Post your questions and find answers here.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Transparent window in pb4

Post by karu »

How i can do that so window is full transparent but gadgets are not

Karu
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

This'll work, I supplied methods to move and close the window, but you're certainly free to use your own imagination to accomplish those tasks:

Code: Select all

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess) 
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED) 
SetLayeredWindowAttributes_(WindowID(0),RGB(255,0,255),0,#LWA_COLORKEY) 
SetWindowColor(0,RGB(255,0,255)) 
CreateGadgetList(WindowID(0)) 
ButtonGadget(0,300,0,20,20,"X") 
StickyWindow(0,1) 

CreateImage(0,32,32) 
StartDrawing(ImageOutput(0)) 
  Box(0,0,32,32,RGB(255,0,255)) 
  Box(12,0,6,32,0) 
  Box(0,12,32,6,0) 
StopDrawing() 

ImageGadget(1,0,0,0,0,ImageID(0)) 
DisableGadget(1,1) 

quit = 0 
Repeat 
  ev = WaitWindowEvent() 
  Select ev 
    Case #WM_LBUTTONDOWN 
      SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0) 
    Case #PB_Event_Gadget 
      If EventGadget()=0 
        quit = 1 
      EndIf 
  EndSelect 
Until quit 
If you're going to put image gadget(s) on there to make a skin, remember to disable them so they aren't firing events.

For Win 9x you can use region clipping to accomplish a similar result but it's more work.
BERESHEIT
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Post by karu »

Thanks
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Nice code net..

- np
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Code: Select all

SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0) 
OMFG! I wasted so many days writing my own window caption click detection and dragging routine for my custom GUI but your single line of code makes it all superfluous.

This nifty thang' is a enormous time/life saver, thanks netmaestro!
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply