Page 1 of 1

Cuting a window by transparent color.

Posted: Wed Nov 02, 2005 12:14 am
by Hroudtwolf
Code updated For 5.20+

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


Posted: Wed Nov 02, 2005 3:53 am
by rsts
LOL - a classic.

Just one day late - or maybe 3 weeks early (Thanksgiving?).

Nice one.

edit -
The more I play with it the more I like it.

Posted: Wed Nov 02, 2005 12:50 pm
by Hroudtwolf
LOL - a classic.
Why, a classic?
I had never seen such one here in the english forums.

Posted: Wed Nov 02, 2005 2:34 pm
by ebs
Hroudtwolf wrote:
LOL - a classic.
Why, a classic?
I had never seen such one here in the english forums.
I'm pretty sure he meant "classic" as a compliment, as in:

:arrow: Belonging to the highest rank or class.

:arrow: Serving as the established model or standard: a classic example of colonial architecture.

:arrow: Having lasting significance or worth; enduring.

:arrow: Adhering or conforming to established standards and principles: a classic piece of research.

:arrow: Formal, refined, and restrained in style.

:arrow: Simple and harmonious; elegant: the classic cut of a suit; the classic lines of a clipper ship.


It's very cool!

Regards,
Eric

Posted: Wed Nov 02, 2005 3:10 pm
by rsts
Hroudtwolf wrote:
LOL - a classic.
Why, a classic?
I had never seen such one here in the english forums.
Yes - I meant classic as in something that will endure and I can use over and over.

A very fine piece of code - thanks for sharing it.

Posted: Wed Nov 02, 2005 11:07 pm
by Hroudtwolf
LOL. There was a little languagebarriere :D
In German is "classic=klassik" the same like "old hut".

Thank you very much.