This is an extremely simple window skinning example.
If a PB Pro can follow up and tell me if the code is redundant or bad, please let me know so I can see where to improve it.

Code: Select all
; Skinny example
; PB 4.51 (x86)
; by Nituvious @ 2/21/2011
;IncludeFile "WinAPI.pbi"
Procedure OpenTransparentWindow(transColor, x, y, width, height) ;-- Create an invisible, borderless, and transparent window
; HideWindow(winResult, 0) after gadgets have been placed. Otherwise you may see flicker.
; I do not know if this works on all versions of windows or just Vista / 7
; I have only tested on both x86 and x64 Windows 7
winResult = OpenWindow(#PB_Any, 1, 1, 1, 1, "",#PB_Window_BorderLess| #PB_Window_Invisible)
SetWindowColor(winResult,transColor)
SetWindowLongPtr_(WindowID(winResult),#GWL_EXSTYLE, #WS_EX_LAYERED) ; -- According to the MSDN, this function will work with both x86 and x64 ( http://msdn.microsoft.com/en-us/library/ms644898(v=VS.85).aspx )
SetWindowPos_(WindowID(winResult),#Null, x, y, width, height, #Null) ; -- Must redraw window, according to the MSDN
SetLayeredWindowAttributes_(WindowID(winResult),transColor,#Null,#LWA_COLORKEY)
ProcedureReturn winResult
EndProcedure
Procedure TransparentTextGadget(hwnd.l, x, y, string.s, Font.l, Color.l) ;-- Create Text without a background
; TextGadget() seem's to leave holes behind everything
; It is probably better practice to remove the StartDrawing(WindowOutput(hwnd)) from this procedure
; and instead place it within the main loop. I do not know if keeping it within a Procedure would hinder performance.
StartDrawing(WindowOutput(hwnd))
If Font.l <> #Null
DrawingFont(FontID(Font.l))
EndIf
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(x, y, string.s,Color.l)
StopDrawing()
EndProcedure
Enumeration 1
#Window_Font
#Window_SkinPNG
#Window_Skin
#Window_Close
EndEnumeration
UsePNGImageDecoder()
LoadFont(#Window_Font, "Gabriola", 24)
LoadImage(#Window_SkinPNG,"C:\skin.png")
MyWindow = OpenTransparentWindow(RGB(255,0,0), 450,200, 400,200)
ImageGadget(#Window_Skin,0,0,200,200,ImageID(#Window_SkinPNG)) : DisableGadget(#Window_Skin,1) ; <-- borderless image gadget is our "skin", for some reason things act strangely if the gadget does not get disabled
Frame3DGadget(#PB_Any,5, 26, 135,40,"")
ButtonGadget(#Window_Close, 330,25, 15,15,"X")
HideWindow(MyWindow, 0) ; <-- no flashy here
Repeat : Delay(1)
eventID = WaitWindowEvent(1)
If eventID = #PB_Event_Gadget
Select EventGadget()
Case #Window_Close
eventID = #PB_Event_CloseWindow
EndSelect
EndIf
TransparentTextGadget(MyWindow, 10, 20, "Hello World!", #Window_Font, RGB(250,0,0))
Until eventID = #PB_Event_CloseWindow