WinFX-Lib (incl. "click-through" Window) - [Windows Source]

Share your advanced PureBasic knowledge/code with the community.
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

WinFX-Lib (incl. "click-through" Window) - [Windows Source]

Post by PureLust »

Hallo there,

inspired by this Thread in the german forum, where Xaby was looking for a not clickable "Overlay-Window", I had a look at it to find out, if and how this could be realized.
And ... finally I've made it.
Image
To get a "not clickable" Window it has to be set into a so called "layered & transparency Mode", so it will be shown on the Desktop, but all Events will go right though to the Window beneath.
I could have well used such a function some times, but (up to now) I was not aware, that this could even be realized :mrgreen: (I have not seen any dues about that so far).

But ... as I've already said, I made it at the end, and so I put it together with some other Window-Effects (which I needed sometimes) into an Include and build a small Lib out of them.
Except from the "click-through" Mode, there is nothing really new stuff (just known Gimmicks like "Hide from TaskBar" and "Window-Transparency"), but still things, someone may need sometimes and which will be asked for her in the forum from time to time (mostly by PB-Newcomer).

I've uploaded 3 Files on my WebSpace for you:
- the Lib itself (implemented as .pbi - Doc is within the Source)
- an executable Demo to have a quick look what you can do with WinFX.
- as well as the Source of the Demo-Program.
- Further I've uploaded the complete bunch as a ZIP-file (thanks to ts-soft for the hint). :roll:
Image
Within the Demo (Picture above) you can nicely see how you can control the beneath Browser-Window THROUGH the on-top Window (after you've switched on the "Click-Through"-Mode).

Attached some rudimentary infos about the included functions (for more infos, please have a look at the Source):
[color=#0000FF]WinFX_ClickThrough(WinNr, State = #True)[/color] wrote:turns the window into "click-through" Mode
In the "click-through" Mode all Mouse-Events (mouse-movement, clicks, hoover, ...) will go right through the Window to the window underneath.
That means, that the window will not receive any mouse-events from now on.
So keep that in mind, when you turn a window in "click-through" Mode and include a facility to close the window and/or react on userinput, rather than by Window-Events.
Note: For this effect, the window will be turned into "layered Mode".
For more details and limitations on that, see "additional Infos" in the "File description Header" above.
[color=#0000FF]WinFX_HideFromTaskBar(WinNr, State = #True, AutoUnHide = #True)[/color] wrote:Hides a window from the Taskbar, or brings it back on.
[color=#0000FF]WinFX_Transparency(WinNr, Level, SkinningColor = #WinFX_NoSkinning)[/color] wrote:Turns on the transparency effect for a window and sets its opacity to the given "Level"
If you set the "SkinningColor", this Color will be used to set an AlphaKey on that window, so it will be transparent on all Pixels which will have the given Color.
Note: For this effect, the window will be turned into "layered Mode".
For more details and limitations on that, see "additional Infos" in the "File description Header" above.
[color=#0000FF]WinFX_TurnOffLayer(WinNr)[/color] wrote:Turns off the "layered Mode" of the window and switches it back to "normal" mode.
This turns off any WinFX-Effect that will need the window to be in "layered Mode".
The following functions are affected by this: WinFX_ClickThrough() & WinFX_Transparency()
Note: For more informations about the "layered-Mode", see "additional Infos" in the "File description Header" above.
As you can see - nothing really new (except from the "Click-Through"-Effect), but maybe there is the one or another of you, who may have some need for it. ;)

Greetz and have fun, PL.

[Edit]: Added downloadlink for ZIP-File
[Edit 2]: Added window skinning Option to WinFX_Transparency().
Last edited by PureLust on Wed Oct 06, 2010 5:41 pm, edited 2 times in total.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

Re: WinFX-Lib (incl. "click-through" Window) - [Windows Sour

Post by Rings »

moved, as it comes with source.

[edit] removed private source [/Edit]
SPAMINATOR NR.1
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: WinFX-Lib (incl. "click-through" Window) - [Windows Sour

Post by PureLust »

Thanks to an idea from bobobo, I've expanded WinFX_Transparency() with support for window skinning (color-keying).

Newest Versions and Demo (see screenshot) already uploaded.

As requested by rings, here is the actual source (just cropped of some internal Header-Informations).
(The code underneath may not represent the latest version in the future - so please see download-links above to get the latest Version):

Include: WinFX_Lib.pbi

Code: Select all

;{ ----- File description Header : WinFX - Library -----

;======================================================================================================================
;
; This Files Name....:  Lib_WinFX.pbi

; additional Infos ..:  Some WinFX-Functions will turn the Window in a - so called - "layered Mode"
;                       If a Window is in that state, it may not be seen on some ScreenShots (depends on the Method which is used to make the ScreenShot).
;                       Further a layered Window could slow down the Screenrefesh of the Desktop (sometimes dramatically on old systems with slow Grafikcards).
;                       The Layered-Mode of a Window will be switched of automatically by the WinFX-Functions, if it's not needed anymore.
;                       (special behavior for WinFX_Transparency() - see Parameter: Level=-1 for additional info)
;                       To turn a window back to "normal" mode by yourself, please see WinFX_TurnOffLayer()
;
; PB-Version .............:  PB 4.51  ->  x86 - tested   |   x64 - not yet tested
; supported Functionality :  x86            - yes
;                            x64            - not tested, should work
;                            EnableExplicit - yes
;                            Threadsave     - not tested, should work
;                            Unicode        - not tested, should work
;                          
; Supported Platform .....:  Windows (should work on all Windows-Versions from Win2000 to Win7)
; uses OS-API-calls ......:  yes
; Tested on Systems ......:  WinXP-32Bit
;
;}=====================================================================================================================

CompilerIf Defined(INCLUDE_WinFXLib, #PB_Constant) = #False
;{ ----- Constants
	#INCLUDE_WinFXLib = #True
	#WinFX_NoSkinning = -1
;}
;{ ----- Variables
	Define WinFX_EXStyleState = 0
;}
;{ ----- Procedures
Procedure	WinFX_HideFromTaskBar(WinNr, State = #True, AutoUnHide = #True)
	;{ ----- Proc-Description Header
	; =============================================================================================
	; 	Procedure Name ....:  WinFX_HideFromTaskBar()
	; 	Description .......:  Hides a window from the Taskbar, or brings it back on.
	;
	; 	Syntax ............:  Procedure WinFX_HideFromTaskBar(WinNr, State = #True, AutoUnHide = #True)
	; 	Parameter(s) ......:  WinNr .... - The PB Window-Number of a Window
	; 	                      State .... = #True (default value) - the Window will be hidden from the Taskbar.
	; 	                                   #False - the Window will be brought back to the Taskbar.
	;                        AutoUnHide = #True (default value) - the window will be unhidden at the end (see "additional Info" for more details)
	;                                   = #False - the Window will not be unhidden at the end, so after calling this function, the window will be hidden (invisible).
	;  additional Info ...:  To enable the WinFX_HideFromTaskBar()-effect, the window has to be invisible (in hidden mode).
	;                        So WinFX_HideFromTaskBar() will auto-hide the window, before it sets this effect.
	;                        After the effect is set, the window will be unhidden by default (see the "AutoUnHide"-Parameter for more details)
	;                        So, if you not want to let your window become visible, make sure to set the "AutoUnHide"-Parameter to #False.
	;
	; 	Return value(s) ...:  Nothing
	;} ==============================================================================
	
	If IsWindow(WinNr)
		HideWindow(WinNr,#True)
		If State
			SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
		Else
			SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & ~#WS_EX_TOOLWINDOW)
		EndIf
		If AutoUnHide
			HideWindow(WinNr,#False)
		EndIf
	EndIf
EndProcedure
Procedure	WinFX_TurnOffLayer(WinNr)
	;{ ----- Proc-Description Header
	; =============================================================================================
	; 	Procedure Name ....:  WinFX_TurnOffLayer()
	; 	Description .......:  Turns off the "layered Mode" of the window and switches it back to "normal" mode.
	;                        This turns off any WinFX-Effect that will need the window to be in "layered Mode".
	;                        The following functions are affected by this: WinFX_ClickThrough()
	;                                                                      WinFX_Transparency()
	;                        Note: For more informations about the "layered-Mode", see "additional Infos" in the "File description Header" above.
	;
	; 	Syntax ............:  WinFX_TurnOffLayer(WinNr)
	; 	Parameter(s) ......:  WinNr  - The PB Window-Number of a Window
	; 	Return value(s) ...:  Nothing
	;} ==============================================================================
	
	Shared  WinFX_EXStyleState
	If IsWindow(WinNr)
		WinFX_EXStyleState = 0
		SetLayeredWindowAttributes_(WindowID(WinNr), #Null, #Null, #LWA_ALPHA)
		SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & ~#WS_EX_LAYERED  & ~#WS_EX_TRANSPARENT)
	EndIf
EndProcedure
Procedure	WinFX_ClickThrough(WinNr, State = #True)
	;{ ----- Proc-Description Header
	; =============================================================================================
	; 	Procedure Name ....:  WinFX_ClickThrough()
	; 	Description .......:  turns the window into "click-through" Mode
	; 	                      In the "click-through" Mode all Mouse-Events (mouse-movement, clicks, hoover, ...) will go right through the Window to the window underneath.
	;                        That means, that the window will not receive any mouse-events from now on.
	;                        So keep that in mind, when you turn a window in "click-through" Mode and include a facility to close the window and/or react on userinput, rather than by Window-Events.
	;                        Note: For this effect, the window will be turned into "layered Mode".
	;                              For more details and limitations on that, see "additional Infos" in the "File description Header" above.
	;
	; 	Syntax ............:  WinFX_ClickThrough(WinNr, State = #True)
	; 	Parameter(s) ......:  WinNr  - The PB Window-Number of a Window
	; 	                      State  - With the State, you can turn the "click-through" Mode on and off.
	; 	                               #True (or any other value other than 0) - will turn the Effect on.
	; 	                               #False - will turn the Effect off.
	; 	                               The Default-Value is: #True
	; 	Return value(s) ...:  Nothing
	;} ==============================================================================
	
	Shared WinFX_EXStyleState
	If IsWindow(WinNr)
		If State
			WinFX_EXStyleState = WinFX_EXStyleState | #WS_EX_TRANSPARENT
			SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) | #WS_EX_LAYERED | #WS_EX_TRANSPARENT)
			If Not WinFX_EXStyleState & #WS_EX_LAYERED
				SetLayeredWindowAttributes_(WindowID(WinNr), #Null, 255, #LWA_ALPHA)
			EndIf
		Else
			SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & ~#WS_EX_TRANSPARENT)
			WinFX_EXStyleState = WinFX_EXStyleState & ~#WS_EX_TRANSPARENT
			If Not WinFX_EXStyleState
				WinFX_TurnOffLayer(WinNr)
			EndIf
		EndIf
	EndIf
EndProcedure
Procedure	WinFX_Transparency(WinNr, Level, SkinningColor = #WinFX_NoSkinning)
	;{ ----- Proc-Description Header
	; =============================================================================================
	; 	Procedure Name ....:  WinFX_Transparency()
	; 	Description .......:  Turns on the transparency effect for a window and sets its opacity to the given "Level"
	;                        If you set the "SkinningColor", this Color will be used to set an AlphaKey on that window, so it will be transparent on all Pixels which will have the given Color.
	;                        Note: For this effect, the window will be turned into "layered Mode".
	;                              For more details and limitations on that, see "additional Infos" in the "File description Header" above.
	; 	
	; 	Syntax ............:  WinFX_Transparency(WinNr, Level, SkinningColor = #WinFX_NoSkinning)
	; 	Parameter(s) ......:  WinNr  - The PB Window-Number of a Window
	; 	                      Level  - The transparency-level To be set
	; 	                               Level could be -1 or within the ranges from -1 0-100
	; 	                               Where 0 will result in a not transparent window, while 100 will result in a fully transparent window
	; 	                               Even If you set the transparency Level to 0, the Window will stay in layered mode (even though it has no transparency at all on Level 0)
	; 	                               -1 : will set the transparency Level To 0, will disable skinning as well and will TURN OFF the layered mode (if it is not used by any other WinFX-Effect)
	;                        SkinningColor - enables the skinning function
	;                                 by setting a SkinningColor, this color will be used as an AlphaKey to skin the window.
	;                                 That means, that the Pixels of a Window will be totally transparent, which fits the given SkinningColor.
	;                                 On these (transparent) Pixels, all Events will pathed through the beneath window, eventhough the "Click-Through" Mode is not aktivated.
	;                                 Note: If you plan to skin a Window, it's recommended to use a borderless Window.
	; 	Return value(s) ...:  Nothing
	;} ==============================================================================
	
	Shared WinFX_EXStyleState
	If IsWindow(WinNr) And level >= -1 And level < 101
		
		If Level < 0
			WinFX_EXStyleState = WinFX_EXStyleState & ~#WS_EX_LAYERED
			Level = 0
			If Not WinFX_EXStyleState
				WinFX_TurnOffLayer(WinNr)
			EndIf
		Else
			If Not WinFX_EXStyleState 
				SetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE,GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) | #WS_EX_LAYERED)
			EndIf
			WinFX_EXStyleState = WinFX_EXStyleState | #WS_EX_LAYERED
		EndIf
		If SkinningColor = #WinFX_NoSkinning
			SetLayeredWindowAttributes_(WindowID(WinNr), #Null, 255*(100-level)/100, #LWA_ALPHA)
		Else
			SetLayeredWindowAttributes_(WindowID(WinNr), SkinningColor, 255*(100-level)/100, #LWA_ALPHA | #LWA_COLORKEY)
		EndIf
	EndIf 
EndProcedure
Procedure	WinFX_GetTaskBarState(WinNr)
	; Returns #True, if Window is hidden from Taskbar
	If IsWindow(WinNr)
		ProcedureReturn ((GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & #WS_EX_TOOLWINDOW) Or #False)		; Will return #True or False instead of a value
	EndIf
EndProcedure
Procedure	WinFX_GetLayerState(WinNr)
	; Returns #True, if Window is in "layered Mode"
	If IsWindow(WinNr)
		ProcedureReturn ((GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & #WS_EX_LAYERED) Or #False)			; Will return #True or False instead of a value
	EndIf
EndProcedure
Procedure	WinFX_GetClickThroughState(WinNr)
	; Returns #True, if Window is in "click-through Mode"
	If IsWindow(WinNr)
 		ProcedureReturn ((GetWindowLong_(WindowID(WinNr),#GWL_EXSTYLE) & #WS_EX_TRANSPARENT) Or #False)		; Will return #True or False instead of a value
	EndIf
EndProcedure
;}
CompilerEndIf
Demo-Code to test WinFX-Lib:

Code: Select all

;{ ----- File description Header : Testprogram for the WinFX-Library -----

;======================================================================================================================
;
; This Files Name....:  WinFX-Demo.pb
; Description .......:  This file contains some testcode, to test the WinFX-Library (1/1)
;
; Includes ..........: 1
; Included Files ....: Lib_WinFX.pbi
;
; PB-Version .............:  PB 4.51  ->  x86 - tested   |   x64 - not yet tested, should work
; supported Funktionality :  x86            - yes
;                            x64            - not tested, should work
;                            EnableExplicit - yes
;                            Threadsave     - not tested, should work
;                            Unicode        - not tested, should work
;                          
; Supported Platform .....:  Windows (should work on all Windows-Versions from Win2000 to Win7)
; uses OS-API-calls ......:  No, but included Lib does.
; Tested on Systems ......:  WinXP-32Bit
;}=====================================================================================================================

EnableExplicit

;{ ----- Includes
XIncludeFile "..\includes\Lib_WinFX.pbi"			; File available at: http://www.bmi-online.de/public/PB-Sources/includes/Lib_WinFX.pbi
;}
;{ ----- Enumerations
Enumeration	;{ Windows
	#Win_Main
	#Win_FX
EndEnumeration ;}
Enumeration	;{ Gadgets
	; Gadgets für Main-Window
	#GadChB_Transparency
	#GadTrB_Transparency
	#GadTex_TransparencyValue
	#GadChB_Skinning
	#GadChB_HideFromTaskbar
	#GadChB_ClickThrough
	#GadBtn_TurnOffLayer
	#GadLiI_WinMainEvents
	#GadLiI_WinFXEvents
	#GadWeb_ClickThroughTest
	; Gadgets for WinFX-Window
	#GadImg_BackGround
	#GadStr_Info1
	#GadStr_Info2
	#GadStr_Info3
	#GadStr_Info4
	#GadStr_Info5
	#GadStr_Info6
	#GadStr_Info7
	#GadStr_Info8
	#GadStr_Info9
	#GadStr_Info10
	#GadStr_Info11
	#GadStr_Info12
	#GadStr_Info13
	#GadStr_State1
	#GadStr_State2
	#GadStr_State3

EndEnumeration	;}
;} End of Enumerations
;{ ----- Declarations
#WinBGColor = $ffaaaa
Define	Event, Gadget
Define	StatusChanged
;}
;{ ----- Procedures
Procedure	OpenMainWindow(WinNr)		; Open the Main-Window and add some Gadget
	Protected	ProcReturnValue = #False
	Protected	WinWidth		= 850
	Protected	WinHeight	= 540
	Protected	WinXPos		= (DesktopWidth(0) - WinWidth) / 2 - 120
	Protected	WinYPos		= (DesktopHeight(0) - WinHeight) / 2 - 40
	If OpenWindow(WinNr, WinXPos, WinYPos, WinWidth, WinHeight, "Main-Window  |  WinFX Test-Program", #PB_Window_SystemMenu)
		CheckBoxGadget(#GadChB_Transparency		,  10,   5, 115, 24,"Transparency effect")
		TrackBarGadget(#GadTrB_Transparency		, 129,   5, 300, 24, 0, 100)
		TextGadget(#GadTex_TransparencyValue	, 440,   5,  50, 24, "", #PB_Text_Center)
		CheckBoxGadget(#GadChB_Skinning			,  10,  35, 115, 24,"Window skinning")
		CheckBoxGadget(#GadChB_HideFromTaskbar	,  10,  65, 115, 24,"Hide from TaskBar")
		CheckBoxGadget(#GadChB_ClickThrough		,  10,  95, 115, 24,"Click-Through Mode")
		ButtonGadget(#GadBtn_TurnOffLayer		,  10, 127, 115, 24,"Turn off 'layered' Mode")
		ListIconGadget(#GadLiI_WinMainEvents	,  10, 160, 115, (WinHeight - 170)/2, "Events: Main", 94)
		ListIconGadget(#GadLiI_WinFXEvents		,  10, 165 + GadgetHeight(#GadLiI_WinMainEvents), 115, WinHeight - 170 - GadgetHeight(#GadLiI_WinMainEvents), "Events: WinFX", 94)
		WebGadget(#GadWeb_ClickThroughTest		, 130,  35, WinWidth - 135, WinHeight - 40,"http://www.purebasic.fr/german/search.php?search_id=active_topics")
		SetGadgetState(#GadTrB_Transparency, 30)
		DisableGadget(#GadTrB_Transparency, #True)
		ProcReturnValue = #True
	EndIf
	ProcedureReturn ProcReturnValue
EndProcedure
Procedure	OpenFXWindow(WinNr)		; Open the WinFX-Window. Ths Window will be affected by the WinFX-effects
	Protected	ProcReturnValue = #False
	Protected	Counter
	Protected	TextColor2	= $664444
	Protected	GadgetColor	= $ff9999
	Protected	GadgetYPos	= 20
; 	Protected	WinColor		= $ffaaaa
	Protected	WinWidth		= 850
	Protected	WinHeight	= 540
	Protected	WinXPos		= (DesktopWidth(0) - WinWidth) / 2 + 120
	Protected	WinYPos		= (DesktopHeight(0) - WinHeight) / 2 + 40
	If OpenWindow(WinNr, WinXPos, WinYPos, WinWidth, WinHeight, "WinFX-Window  |  This window will be effected by WinFX", #PB_Window_SystemMenu)
		
		; Creating Image and Gadget for Background
		If CreateImage(0, WinWidth, WinHeight+10)
			If StartDrawing(ImageOutput(0))
				Box(0,0, WinWidth, WinHeight+10, #WinBGColor)
				StopDrawing()
			EndIf
			ImageGadget(#GadImg_BackGround, 0, 0, WinWidth, WinHeight+10, ImageID(0))
			DisableGadget(#GadImg_BackGround, #True)
		EndIf
		
		StringGadget(#GadStr_Info1 , 20,  GadgetYPos, WinWidth-40, 40, "This Window will be affected by the WinFX-Functions.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 50
		StringGadget(#GadStr_Info2 , 20,  GadgetYPos, WinWidth-40, 22, "Use the Buttons in the window beneath left, to change the WinFX-Effects for this window.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 35
		StringGadget(#GadStr_Info3 , 20,  GadgetYPos, WinWidth-40, 22, "'Transparency effect' will turn on/off the windows-transparency (change the level with the slider).", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 35
		StringGadget(#GadStr_Info4 , 20,  GadgetYPos, WinWidth-40, 22, "'Hide from TaskBar' will change the Window into a ToolWindow to hide it from the Taskbar.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info5 , 20,  GadgetYPos, WinWidth-40, 22, "     Note: This causes a slightly change in design an functionality.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 35
		StringGadget(#GadStr_Info6 , 20,  GadgetYPos, WinWidth-40, 22, "'Click-Through Mode' will turn the window into a 'click-through' state.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info7 , 20,  GadgetYPos, WinWidth-40, 22, "     In this state, all clicks and events will go directly through it to the window beneath.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info8 , 20,  GadgetYPos, WinWidth-40, 22, "     So - referring to MouseEvents - the window just doesn't exists anymore.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info9 , 20,  GadgetYPos, WinWidth-40, 22, "     Use the Webgadet in the window beneath to see, that even the mousepointer changes.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info10, 20,  GadgetYPos, WinWidth-40, 25, "     (The Events-Lists on the left will show all the Events, the windows will receive.)", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 35
		StringGadget(#GadStr_Info11, 20,  GadgetYPos, WinWidth-40, 25, "'Turn off layered Mode' turns off all effects that needs a 'layered' Window.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 23
		StringGadget(#GadStr_Info12, 20,  GadgetYPos, WinWidth-40, 25, "     Note: The 'Transparency effect' and the 'click-through' effect need a 'layered' window.", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 45
		StringGadget(#GadStr_Info13, 20,  GadgetYPos, WinWidth-40, 25, "Results from:", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 35
		StringGadget(#GadStr_state1, 20,  GadgetYPos, WinWidth-40, 25, "", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 30
		StringGadget(#GadStr_State2, 20,  GadgetYPos, WinWidth-40, 25, "", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 30
		StringGadget(#GadStr_State3, 20,  GadgetYPos, WinWidth-40, 25, "", #PB_String_ReadOnly | #PB_String_BorderLess) : GadgetYPos + 30
		
		SetGadgetColor(#GadStr_Info5, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_Info7, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_Info8, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_Info9, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_Info10, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_Info12, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_State1, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_State2, #PB_Gadget_FrontColor, TextColor2)
		SetGadgetColor(#GadStr_State3, #PB_Gadget_FrontColor, TextColor2)
		
		SetGadgetColor(#GadStr_Info1, #PB_Gadget_BackColor, GadgetColor)
		SetGadgetFont(#GadStr_Info1, FontID(1))
		For Counter = #GadStr_Info2 To #GadStr_State3
			SetGadgetColor(Counter, #PB_Gadget_BackColor, #WinBGColor)
			SetGadgetFont(Counter, FontID(0))
		Next
		SetGadgetFont(#GadStr_State1, FontID(2))
		SetGadgetFont(#GadStr_State2, FontID(2))
		SetGadgetFont(#GadStr_State3, FontID(2))

		StickyWindow(#Win_FX, #True)

		ProcReturnValue = #True
	EndIf
	ProcedureReturn ProcReturnValue
EndProcedure
Procedure	UpdateStatus()
	
	; Update Slider-Value, shown in the TextGadget
	SetGadgetText(#GadTex_TransparencyValue, Str(GetGadgetState(#GadTrB_Transparency)))
	
	; Now we use the WinFX_Get...-Functions to update the info in the WinFX-Window
	
	If WinFX_GetLayerState(#Win_FX)
		SetGadgetText(#GadStr_State1, "    WinFX_GetLayerState() = #True                 >  'Transparency effect' or 'click-through' Mode is active.")
	Else
		SetGadgetText(#GadStr_State1, "    WinFX_GetLayerState() = #False               >  No effect that needs a 'layered' Window is active.")
	EndIf	
	
	If WinFX_GetTaskBarState(#Win_FX)
		SetGadgetText(#GadStr_State2, "    WinFX_GetTaskBarState() = #True            >  Window is hidden from TaskBar.")
	Else
		SetGadgetText(#GadStr_State2, "    WinFX_GetTaskBarState() = #False           >  Window is NOT hidden from TaskBar.")
	EndIf	
	
	If WinFX_GetClickThroughState(#Win_FX)
		SetGadgetText(#GadStr_State3, "    WinFX_GetClickThroughState() = #True    >  Window in 'click-through' Mode. Window will pass through all events")
	Else
		SetGadgetText(#GadStr_State3, "    WinFX_GetClickThroughState() = #False   >  Window in 'normal' Mode. Window will catch events as usual.")
	EndIf	
	
EndProcedure
;} 
;{ ----- Loading Fonts
If Not LoadFont(0, "Arial", 14) Or Not LoadFont(1, "Arial", 25) Or Not LoadFont(2, "Arial Narrow", 14)
	MessageRequester("Attention!","Could not load Font !!!")
	End
EndIf
;}

ExamineDesktops()

; ===== Main =====

If OpenMainWindow(#Win_Main)
	If OpenFXWindow(#Win_FX)
		
		UpdateStatus()
		
		;{ ----- Event-Loop -----
		Repeat
			Event = WaitWindowEvent()
			
			; ----- aufgetretene Events in Eventliste des jeweiligen Fensters eintragen
			If EventWindow() = #Win_Main
				If Event <> 15 And Event <> 275
					AddGadgetItem(#GadLiI_WinMainEvents,0,Str(ElapsedMilliseconds())+", "+Str(Event))
				EndIf
			Else
				AddGadgetItem(#GadLiI_WinFXEvents,0,Str(ElapsedMilliseconds())+", "+Str(Event))
			EndIf
			
			; ----- Gadget-Events auswerten
			If Event = #PB_Event_Gadget
				StatusChanged = #True
				Select	EventGadget()
						
					Case	#GadChB_Transparency		;{ ----- CheckBox - Status of Transparency effect changed
						
						If GetGadgetState(#GadChB_Transparency) = #PB_Checkbox_Checked
							If GetGadgetState(#GadChB_Skinning) = #PB_Checkbox_Checked
								WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency), #WinBGColor)
							Else
								WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency), #WinFX_NoSkinning)
							EndIf
 							DisableGadget(#GadTrB_Transparency, #False)
						Else
							If GetGadgetState(#GadChB_Skinning) = #PB_Checkbox_Checked
								WinFX_Transparency(#Win_FX, 0, #WinBGColor)
							Else
								WinFX_Transparency(#Win_FX, -1)
							EndIf
 							DisableGadget(#GadTrB_Transparency, #True)
						EndIf
						;}
					Case	#GadTrB_Transparency		;{ ----- TrackBar - Value of Transparency changed
						
						If GetGadgetState(#GadChB_Skinning) = #PB_Checkbox_Checked
							WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency), #WinBGColor)
						Else
							WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency), #WinFX_NoSkinning)
						EndIf
						;}
					Case	#GadChB_Skinning			;{ ----- CheckBox - Color-Keying (Skinning) aktivated
						
						If GetGadgetState(#GadChB_Skinning) = #PB_Checkbox_Checked
							If GetGadgetState(#GadChB_Transparency) = #PB_Checkbox_Checked
								WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency), #WinBGColor)
							Else
								WinFX_Transparency(#Win_FX, 0, #WinBGColor)
							EndIf
						Else
							If GetGadgetState(#GadChB_Transparency) = #PB_Checkbox_Checked
								WinFX_Transparency(#Win_FX, GetGadgetState(#GadTrB_Transparency))
							Else
								WinFX_Transparency(#Win_FX, -1)
							EndIf
						EndIf
						;}
					Case	#GadChB_HideFromTaskbar	;{ ----- Status for Hide-from-TaskBar changed
						
						If GetGadgetState(#GadChB_HideFromTaskbar) = #PB_Checkbox_Checked
							WinFX_HideFromTaskBar(#Win_FX, #True)
						Else
							WinFX_HideFromTaskBar(#Win_FX, #False)
						EndIf
						;}
					Case	#GadChB_ClickThrough		;{ ----- Status for "click-through" Mode changed
						
						If GetGadgetState(#GadChB_ClickThrough) = #PB_Checkbox_Checked
							WinFX_ClickThrough(#Win_FX, #True)
						Else
							WinFX_ClickThrough(#Win_FX, #False)
						EndIf
						;}
					Case	#GadBtn_TurnOffLayer		;{ ----- Button pressed: "Turn of Layer Mode"
						
						WinFX_TurnOffLayer(#Win_FX)
						SetGadgetState(#GadChB_ClickThrough, #PB_Checkbox_Unchecked)
						SetGadgetState(#GadChB_Transparency, #PB_Checkbox_Unchecked)
						DisableGadget(#GadTrB_Transparency, #True)
						;}
					Default
						StatusChanged = #False
				EndSelect
				If StatusChanged
					UpdateStatus()
				EndIf
			EndIf
			
		Until Event = #PB_Event_CloseWindow
		;}
		
	EndIf
EndIf
Have fun with it. :wink:
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
User avatar
idle
Always Here
Always Here
Posts: 5089
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: WinFX-Lib (incl. "click-through" Window) - [Windows Sour

Post by idle »

Thanks
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: WinFX-Lib (incl. "click-through" Window) - [Windows Sour

Post by Dude »

I know I'm 7 years late, but this click-through code is fantastic! Thank you! :shock: :D
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5350
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: WinFX-Lib (incl. "click-through" Window) - [Windows Sour

Post by Kwai chang caine »

+1
I have not see it :oops:
Thanks 8)
ImageThe happiness is a road...
Not a destination
Post Reply