FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

11 Mar 2017, 20:33

I was looking for this... :angel:
ONLY TESTED ON WIN7, Maybe you guys can help me out...

Image

Code: Select all

Gui, +HwndHGui -Caption
FrameShadow(HGui)
Gui, Add, Button, x10 y130 w100 h30, Minimize
Gui, Add, Button, x365 y130 w100 h30, Exit
Gui, Add, GroupBox, x10 y10 w455 h110, GroupBox
Gui, Add, Edit, x20 y30 w435 h80 +Multi, Edit
Gui, Show, Center w475 h166, Frame Shadow Test
Return

ButtonExit:
GuiClose:
ExitApp

ButtonMinimize:
WinMinimize, A
return

FrameShadow(HGui) {
	DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
	if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
		DllCall("SetClassLong","UInt",HGui,"Int",-26,"Int",DllCall("GetClassLong","UInt",HGui,"Int",-26)|0x20000)
	else {
		VarSetCapacity(_MARGINS,16)
		NumPut(1,&_MARGINS,0,"UInt")
		NumPut(1,&_MARGINS,4,"UInt")
		NumPut(1,&_MARGINS,8,"UInt")
		NumPut(1,&_MARGINS,12,"UInt")
		DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", HGui, "UInt", 2, "Int*", 2, "UInt", 4)
		DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", HGui, "Ptr", &_MARGINS)
	}
}

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static init := OnMessage(0x0201, "WM_LBUTTONDOWN")
	PostMessage, 0xA1, 2,,, A
}
Last edited by Klark92 on 18 Mar 2017, 13:34, edited 2 times in total.
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: FrameShadow(): Drop Shadow On Borderless Window

12 Mar 2017, 02:42

Image

Works fine on win10 ;)
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: FrameShadow(): Drop Shadow On Borderless Window

12 Mar 2017, 08:44

Thanks, I actually want a real shadow with layered window but Im still searching...(only got working c# code)
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
User avatar
moefr01
Posts: 115
Joined: 25 Nov 2015, 09:01
Location: Germany

Re: FrameShadow(): Drop Shadow On Borderless Window

14 Mar 2017, 13:43

@Klark92
Thanks for your awesome code :thumbup:
tested on win 10 x64... works fine, but if you add a picture for the background it will show an ugly 1-pixel border around the whole window, changing its color if window is active or not. Playing around with the numput-values from -1, 0, 1 showed me a partial borderless window or unfortunately without a shadow (all numputs=0). You can set 3 numputs with 0 and the last numput with 1 to show the shadow, but always with that horrible 1-pixel line. Moving or oversizing the background-pic didn't work.
Any hint?
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: FrameShadow(): Drop Shadow On Borderless Window

14 Mar 2017, 13:56

It cannot be fixed with any function in dwm manager, if you look at any shadowed window (e.g : Total 360 Security), they have extra hidden window in process, it is shadow layer...

I have c# code that it makes shadow around main window and it works perfect with dragging :

Image
Image

So I was coverting c# code to ahk but there are gdiplus.dll's complex functions... Im stuck :)
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: FrameShadow(): Drop Shadow On Borderless Window

15 Mar 2017, 15:28

np dude. keep waiting, it is on the way :) (I'm working on docking class)

Image
Image
Image
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

13 Apr 2017, 02:58

I added your example in my github repo for useful gui examples
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

13 Apr 2017, 11:24

If you have C# code that is a pain to implement it in AHK, we can use CLR to make the code executable from AHK.
If you want help, lemme know.

I would defo like something like this myself, but what I would personally like to see is something that can add a coloured border around a window (eg green for all OK, red for a problem).
If it works for parented windows (ie add a colored border to an AHK Gui that is embedded in another AHK Gui) then that would be great
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

13 Apr 2017, 14:11

thanks jnizm :P ,
Yes evilc, ahk is not good for event handling, threading... only we can dock shadow to a window, childs are not supported
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

13 Apr 2017, 14:19

If someone posts some C# or a SLN, I can show you how to package it so that it can be used from AHK.
Or you can see here for a simplish example.
You don't need to build a DLL though, it can also be done with dynamic compilation (C# source as an AHK string).
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

10 May 2017, 12:21

Thanks for a great function. However if basic shadow is used (_ISENABLED=0) then all next opened windows are affected and have a wrong shadow. See the example below (press minimize button).
Is it possible to cancel shadow to default for other windows?

Code: Select all

Gui, +HwndHGui -Caption
FrameShadow(HGui)
Gui, Add, Button, x10 y130 w100 h30, Minimize
Gui, Add, Button, x365 y130 w100 h30, Exit
Gui, Add, GroupBox, x10 y10 w455 h110, GroupBox
Gui, Add, Edit, x20 y30 w435 h80 +Multi, Edit
Gui, Show, Center w475 h166, Frame Shadow Test
Return

ButtonExit:
GuiClose:
ExitApp

ButtonMinimize:
gui, destroy
gui, add, edit, w300 h300
gui, show

return

FrameShadow(HGui) {
	DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
	_ISENABLED:=0
	if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
		DllCall("SetClassLong","UInt",HGui,"Int",-26,"Int",DllCall("GetClassLong","UInt",HGui,"Int",-26)|0x20000)
	else {
		VarSetCapacity(_MARGINS,16)
		NumPut(1,&_MARGINS,0,"UInt")
		NumPut(1,&_MARGINS,4,"UInt")
		NumPut(1,&_MARGINS,8,"UInt")
		NumPut(1,&_MARGINS,12,"UInt")
		DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", HGui, "UInt", 2, "Int*", 2, "UInt", 4)
		DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", HGui, "Ptr", &_MARGINS)
	}
}

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static init := OnMessage(0x0201, "WM_LBUTTONDOWN")
	PostMessage, 0xA1, 2,,, A
}
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

11 May 2017, 13:47

think wrote:Thanks for a great function. However if basic shadow is used (_ISENABLED=0) then all next opened windows are affected and have a wrong shadow. See the example below (press minimize button).
Is it possible to cancel shadow to default for other windows?
I tested and I didnt see any problem ? new opening window is affecting ?
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

11 May 2017, 14:33

It's visible in Win10. Try adding gui, -caption under Winminimize routine in my example. You see that new windows will have the same basic shadow. Normal (non borderless) windows will have both shadows which is visible in Win10. In Win7 you can see the shadow is a little darker.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

17 Feb 2019, 18:18

Hello, I am trying to solve the problem early mentionned by "think".


I am on Win10 like him and when setting the Gui Shadow it will affect all other windows linked to my AHK script.
Does anyone have a solution to only affect the hwnd of the window that calls the function?


Thanks in advance

Code: Select all

Gui, +HwndHGui -Caption
FrameShadow(HGui)
Gui, Add, Button, x10 y130 w100 h30, Minimize
Gui, Add, Button, x365 y130 w100 h30, Exit
Gui, Add, GroupBox, x10 y10 w455 h110, GroupBox
Gui, Add, Edit, x20 y30 w435 h80 +Multi, Edit
Gui, Show, Center w475 h166, Frame Shadow Test
Return

ButtonExit:
GuiClose:
ExitApp

ButtonMinimize:
WinMinimize, A
return

FrameShadow(HGui) {
	DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
	if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
		DllCall("SetClassLong","UInt",HGui,"Int",-26,"Int",DllCall("GetClassLong","UInt",HGui,"Int",-26)|0x20000)
	else {
		VarSetCapacity(_MARGINS,16)
		NumPut(1,&_MARGINS,0,"UInt")
		NumPut(1,&_MARGINS,4,"UInt")
		NumPut(1,&_MARGINS,8,"UInt")
		NumPut(1,&_MARGINS,12,"UInt")
		DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", HGui, "UInt", 2, "Int*", 2, "UInt", 4)
		DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", HGui, "Ptr", &_MARGINS)
	}
}

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static init := OnMessage(0x0201, "WM_LBUTTONDOWN")
	PostMessage, 0xA1, 2,,, A
}
just me
Posts: 9449
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

18 Feb 2019, 05:43

Code: Select all

#NoEnv
CS_DROPSHADOW := 0x00020000
ClassStyle := GetGuiClassStyle()
Gui, New, +hwndHGUI
SetGuiClassStyle(HGUI, ClassStyle | CS_DROPSHADOW)
Gui, Show, x100 y100 w250 h200, Test 1
SetGuiClassStyle(HGUI, ClassStyle)
Gui, New
Gui, Show, x400 y100 w250 h200, Test 2
Gui, New, +hwndHGUI
SetGuiClassStyle(HGUI, ClassStyle | CS_DROPSHADOW)
Gui, Show, x700 y100 w250 h200, Test 3
SetGuiClassStyle(HGUI, ClassStyle)
Return

GuiClose:
GuiEscape:
ExitApp

GetGuiClassStyle() {
   Gui, GetGuiClassStyleGUI:Add, Text
   Module := DllCall("GetModuleHandle", "Ptr", 0, "UPtr")
   VarSetCapacity(WNDCLASS, A_PtrSize * 10, 0)
   ClassStyle := DllCall("GetClassInfo", "Ptr", Module, "Str", "AutoHotkeyGUI", "Ptr", &WNDCLASS, "UInt")
                 ? NumGet(WNDCLASS, "Int")
                 : ""
   Gui, GetGuiClassStyleGUI:Destroy
   Return ClassStyle
}

SetGuiClassStyle(HGUI, Style) {
   Return DllCall("SetClassLong" . (A_PtrSize = 8 ? "Ptr" : ""), "Ptr", HGUI, "Int", -26, "Ptr", Style, "UInt")
}
?
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

18 Feb 2019, 08:21

just me wrote:
18 Feb 2019, 05:43
?
Just Me, how long have you been coding?
You always find good solutions!

Look at this example code I adapted from your code, it works as I intended with these settings:

Code: Select all

#SingleInstance, Force ; Prevent double execution of this script
#NoEnv

CS_DROPSHADOW := 0x00020000
ClassStyle := GetGuiClassStyle()
WM_LBUTTONDOWN := 0x201
OnMessage(WM_LBUTTONDOWN, "Move_Window") ; WM_LBUTTONDOWN = 0x201

Gui, New, +hwndHGUI
Gui, Show, x100 y100 w800 h400, Main Window			; Normal window, no style change involved

Gui, New, +hwndHGUI -Caption +AlwaysOnTop
SetGuiClassStyle(HGUI, ClassStyle | CS_DROPSHADOW)	; pop-up window meant to be owned by main window
Gui, Add, Text,x0 y0 , no caption`npop-up
Gui, Show, x115 y140 w120 h100, Pop-up 1
SetGuiClassStyle(HGUI, ClassStyle)

Gui, New, +hwndHGUI +AlwaysOnTop
;SetGuiClassStyle(HGUI, ClassStyle | CS_DROPSHADOW)	; <<<<<-------- WORKS WHEN NOT CALLING THIS ! 	NICE
Gui, Show, x400 y140 w250 h200, other regular window	; other window generated in a commun AHK script
;SetGuiClassStyle(HGUI, ClassStyle)

Return

GuiClose:
GuiEscape:
ExitApp

GetGuiClassStyle() {
	Gui, GetGuiClassStyleGUI:Add, Text
	Module := DllCall("GetModuleHandle", "Ptr", 0, "UPtr")
	VarSetCapacity(WNDCLASS, A_PtrSize * 10, 0)
	ClassStyle := DllCall("GetClassInfo", "Ptr", Module, "Str", "AutoHotkeyGUI", "Ptr", &WNDCLASS, "UInt")
                 ? NumGet(WNDCLASS, "Int")
                 : ""
	Gui, GetGuiClassStyleGUI:Destroy
	Return ClassStyle
}

SetGuiClassStyle(HGUI, Style) {
	Return DllCall("SetClassLong" . (A_PtrSize = 8 ? "Ptr" : ""), "Ptr", HGUI, "Int", -26, "Ptr", Style, "UInt")
}

Move_Window() {
	postmessage,0xA1,2,,,A
}
Thank you very much! :dance:

If I understand the process you went through, you are enabling it on some window and by recalling it without the CS_Dropshadow hex it removes it?

EDIT: that line you wrote... ClassStyle := GetGuiClassStyle() is this what we call function binding?? Nevermind, you jsut stored the response of the function to remember it ok!
just me
Posts: 9449
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

18 Feb 2019, 09:02

Hi,

AHK registers its own window classes. The class for AHK Gui windows is AutoHotkeyGUI. You can assign some predefines styles to window classes: Window Class Styles. This styles can be retrieved by GetClassLong(Ptr)() or GetClassInfo(). If you call one of this functions you'll find that AHK sets the CS_DBLCLKS (0x0008) style bit for the AUtoHotkeyGUI class. This value is stored in ClassStyle to be able to reset the style bits to the default later.

Now you call SetClassLong(Ptr)() to add the style CS_DROPSHADOW (0x00020000), show the window the first time while the sytyle is assigned, and remove the style immediately afterwards by setting the default style bits.

That's all.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

18 Feb 2019, 09:17

Awesome, thank you so much for the help to solve my problem and the explanations.

I made a function out of your two if any one else wants to experiment here it is:

Code: Select all

;================================================================================
; https://www.autohotkey.com/boards/viewtopic.php?f=6&p=264108#p264108
;--------------------------------------------------------------------------------
DropShadow_just_me(HGUI:="", Style:="", GetGuiClassStyle:="", SetGuiClassStyle:="") {
;--------------------------------------------------------------------------------
	
	if (GetGuiClassStyle) {
		ClassStyle:=GetGuiClassStyle()
		return ClassStyle
	}
	
	if (SetGuiClassStyle) {
		SetGuiClassStyle(HGUI, Style) 
	}
	
}

GetGuiClassStyle() {
	Gui, GetGuiClassStyleGUI:Add, Text
	Module := DllCall("GetModuleHandle", "Ptr", 0, "UPtr")
	VarSetCapacity(WNDCLASS, A_PtrSize * 10, 0)
	ClassStyle := DllCall("GetClassInfo", "Ptr", Module, "Str", "AutoHotkeyGUI", "Ptr", &WNDCLASS, "UInt")
                 ? NumGet(WNDCLASS, "Int")
                 : ""
	Gui, GetGuiClassStyleGUI:Destroy
	Return ClassStyle
}
SetGuiClassStyle(HGUI, Style) {
	Return DllCall("SetClassLong" . (A_PtrSize = 8 ? "Ptr" : ""), "Ptr", HGUI, "Int", -26, "Ptr", Style, "UInt")
}
;================================================================================
johnsonttc
Posts: 7
Joined: 08 Feb 2018, 02:48

Re: FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)

15 Mar 2019, 02:03

couldnt see any shawdow with the script
wanted to make every window to have drop shadows in win10 just like win7 but failed

any suggestion pls?


EDIT sorry, my fault... pls ignore it

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 60 guests