Cuting a window by transparent color.

Share your advanced PureBasic knowledge/code with the community.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Cuting a window by transparent color.

Post 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

rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

LOL - a classic.
Why, a classic?
I had never seen such one here in the english forums.
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

LOL. There was a little languagebarriere :D
In German is "classic=klassik" the same like "old hut".

Thank you very much.
Post Reply