This code demonstrate to cut a window by transparent color.
Attention: It works only with Windows 2000 and XP.
Right mouseclick is closing the window.
Code: Select all
; Cuting a window by transparent color.
; 2005 Hroudtwolf
; PureBasic-Lounge.de & Englisch PureBasic forums
Declare CutOnTransparenceColor(win,color)
#WS_EX_LAYERED = $00080000
Enumeration
#Window
#image
EndEnumeration
If CreateImage (#image,200,200)
If StartDrawing (ImageOutput(#image))
Box (0,0,200,200,RGB(255,0,255))
DrawingMode(4)
For x=1 To 80
Circle (99,99,x,RGB(255,255-x,0))
Next x
DrawingMode(0)
Circle (60,70,20,RGB(255,0,255))
Circle (139,70,20,RGB(255,0,255))
Ellipse(99, 120, 60, 20 ,RGB(255,0,255))
StopDrawing()
EndIf
EndIf
If OpenWindow(#Window, 0, 0, 200, 200, "Transparente Farbe", #PB_Window_ScreenCentered|#WS_POPUP)
;----------------------------------------------------------------
; Setzen des Hintergundbildes
hBrush = CreatePatternBrush_(ImageID (#image))
SetClassLong_(WindowID(#Window), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(#Window), #Null, #True)
;----------------------------------------------------------------
CutOnTransparenceColor(#Window,RGB(255,0,255)) ; Die Farbe rgb (255,0,255) auf transparent setzen
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow Or EventID=#WM_RBUTTONDOWN
Quit = 1
EndIf
If EventID = #WM_LBUTTONDOWN
SendMessage_(WindowID(#Window),#WM_NCLBUTTONDOWN, #HTCAPTION,0)
EndIf
Until Quit = 1
EndIf
End
Procedure CutOnTransparenceColor(win,color)
Library = LoadLibrary_("user32.dll")
If Library
adress = GetProcAddress_(Library ,"SetLayeredWindowAttributes")
If adress
SetWindowLong_(WindowID(win),#GWL_EXSTYLE,GetWindowLong_(WindowID(win),#GWL_EXSTYLE)|#WS_EX_LAYERED)
CallFunctionFast(adress ,WindowID(win),color,0,1)
EndIf
FreeLibrary_(Library )
EndIf
EndProcedure