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

Post your working scripts, libraries and tools for AHK v1.1 and older
sivanagballa
Posts: 3
Joined: 15 Jun 2019, 11:07

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

15 Jun 2019, 11:52

this is pretty nice piece of code, which works. But i'm facing issue when i use multiple GUI. Both GUI are borderless. But i see shadow only for the IGUI window but not IGUI2 window. I observed that both GUI are getting same handle -> AHK GUI 0xdc0db0 IGUI2 0xdc0db0.
can some one help where i went wrong

Code: Select all


#SingleInstance Force
SetTitleMatchMode RegEx
 
Gui, +HwndIGUI2
Gui, IGUI2:-Caption +ToolWindow +Lastfound 
Gui, IGUI2:Color, FF00FF
Gui, IGUI2:Add, Text,  y10,     IGUI2:
FrameShadow(IGUI2)
;ShadowBorder(IGUI2)
Gui, IGUI2:Show, xCenter y300 AutoSize, AHK GUI2

Gui, +HwndIGUI
Gui, -Caption +ToolWindow +Lastfound -Border

Gui, Color, White
Gui, Add, Text,  y10,     Status:
Gui, Add, Text,  x+10  y10 w370 vStat, IGUI
Gui, Add, Edit,  xm  y+5 w400 vCmdEdit , Command 

Gui +Delimiter`n
;FrameShadow(IGUI)
;ShadowBorder(IGUI)
Gui, Show, xCenter y200 AutoSize, AHK GUI

ShadowBorder(handle)
{
    DllCall("user32.dll\SetClassLongPtr", "ptr", handle, "int", -26, "ptr", DllCall("user32.dll\GetClassLongPtr", "ptr", handle, "int", -26, "uptr") | 0x20000)
}

FrameShadow(handle) {
	DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
	if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
		DllCall("SetClassLong","UInt",handle,"Int",-26,"Int",DllCall("GetClassLong","UInt",handle,"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", handle, "UInt", 2, "Int*", 2, "UInt", 4)
		DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", handle, "Ptr", &_MARGINS)
	}
}
Image
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

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

15 Jun 2019, 19:27

Do not use it like that : "Gui, IGUI2:" Write your project using "Gui, New" buddy.
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, (DWM STYLE)

15 Jun 2019, 19:29

Gui, New is the key, Good luck

Code: Select all

#SingleInstance Force
SetTitleMatchMode RegEx
 
Gui, New
Gui, +HwndIGUI2
Gui, -Caption -ToolWindow +Lastfound -Border
Gui, Color, FF00FF
Gui, Add, Text,  y10,     IGUI2:
Gui, Add, Edit,  xm  y+5 w400 vCmdEdit , Command 
Gui, Show, Center w300 h300 y300, AHK GUI2
FrameShadow(IGUI2)


Gui, New
Gui, +HwndIGUI
Gui, -Caption -ToolWindow +Lastfound -Border
Gui, Color, White
Gui, Add, Text,  y10,     Status:
Gui, Add, Text,  x+10  y10 w370 vStat, IGUI
Gui, Add, Edit,  xm  y+5 w400 vCmdEdit , Command 
Gui, Show, xCenter y200 AutoSize, AHK GUI
FrameShadow(IGUI)
return

ShadowBorder(handle)
{
    DllCall("user32.dll\SetClassLongPtr", "ptr", handle, "int", -26, "ptr", DllCall("user32.dll\GetClassLongPtr", "ptr", handle, "int", -26, "uptr") | 0x20000)
}

FrameShadow(handle) {
	DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
	if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
		DllCall("SetClassLong","UInt",handle,"Int",-26,"Int",DllCall("GetClassLong","UInt",handle,"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", handle, "UInt", 2, "Int*", 2, "UInt", 4)
		DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", handle, "Ptr", &_MARGINS)
	}
}
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
sivanagballa
Posts: 3
Joined: 15 Jun 2019, 11:07

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

16 Jun 2019, 06:23

thanks a lot @@Klark92 . It worked
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

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

16 Jun 2019, 06:48

Code: Select all

...
Gui, IGUI2:+HwndIGUI2 ; <<<<< you need to specify the GUI name here
Gui, IGUI2:-Caption +ToolWindow +Lastfound
...
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

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

16 Jun 2019, 19:05

just me wrote:
16 Jun 2019, 06:48

Code: Select all

...
Gui, IGUI2:+HwndIGUI2 ; <<<<< you need to specify the GUI name here
Gui, IGUI2:-Caption +ToolWindow +Lastfound
...
Hmm I didnt see that wrong. I think its because i'm never using it like that :)
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
ysan
Posts: 4
Joined: 27 May 2020, 04:53

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

27 May 2020, 05:03

just me wrote:
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")
}
?
Hi

Though it's an old topic , sorry to ask but I'm very new on AHK .

Is there anybody kind to help a noob with this pb :

I'm using a AHK script for context menu to make them fluent under windows 10 and work nice :

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
#Persistent
SetWinDelay, 0
DetectHiddenWindows on

ConvertToBGRfromRGB(RGB) { 
    BGR := SubStr(RGB, -1, 2) SubStr(RGB, 1, 4) 
    Return BGR 
    }

global EVENT_SYSTEM_MENUPOPUPSTART := 0x0006

OnPopupMenu(hWinEventHook, event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime) {
     bgrColor := "220022"
     SetAcrylicGlassEffect(bgrColor, 100, ahk_id, hWnd)
    }

SetAcrylicGlassEffect(thisColor, thisAlpha, ahk_id, hWnd) {
    SetWinDelay, 0
    initialAlpha := thisAlpha
    If (thisAlpha<16)
       thisAlpha := 16
    Else If (thisAlpha>125)
        thisAlpha :=20
        thisColor := ConvertToBGRfromRGB(thisColor)
        thisAlpha := Format("{1:#x}", thisAlpha)
        gradient_color := thisAlpha . thisColor
        Static init, accent_state := 4, ver := DllCall("GetVersion") & 0xff < 10
        Static pad := A_PtrSize = 8 ? 4 : 0, WCA_ACCENT_POLICY := 19
        accent_size := VarSetCapacity(ACCENT_POLICY, 16, 0)
        NumPut(accent_state, ACCENT_POLICY, 0, "int")
        If (RegExMatch(gradient_color, "0x[[:xdigit:]]{8}"))
            NumPut(gradient_color, ACCENT_POLICY, 8, "int")
            VarSetCapacity(WINCOMPATTRDATA, 4 + pad + A_PtrSize + 4 + pad, 0)
            && NumPut(WCA_ACCENT_POLICY, WINCOMPATTRDATA, 0, "int")
            && NumPut(&ACCENT_POLICY, WINCOMPATTRDATA, 4 + pad, "ptr")
            && NumPut(accent_size, WINCOMPATTRDATA, 4 + pad + A_PtrSize, "uint")
        If !(DllCall("user32\SetWindowCompositionAttribute", "ptr", hWnd, "ptr", &WINCOMPATTRDATA))
        Return
    SetWinDelay, 0
    thisOpacity := (initialAlpha<16) ? 60 + initialAlpha*9 : 250
    Return
    }

hWinEventHook := DllCall("SetWinEventHook", "UInt", EVENT_SYSTEM_MENUPOPUPSTART, "UInt", EVENT_SYSTEM_MENUPOPUPSTART, "Ptr", 0, "Ptr", (lpfnWinEventProc := RegisterCallback("OnPopupMenu", "")), "UInt", 0, "UInt", 0, "UInt", WINEVENT_OUTOFCONTEXT := 0x0000 | WINEVENT_SKIPOWNPROCESS := 0x0002)

OnExit("AtExit")
 AtExit(){
WinSet, Transparent, 255, ahk_id %hWnd%
    global hWinEventHook, lpfnWinEventProc
    if (hWinEventHook)
        DllCall("UnhookWinEvent", "Ptr", hWinEventHook), hWinEventHook := 0
    if (lpfnWinEventProc)
        DllCall("GlobalFree", "Ptr", lpfnWinEventProc, "Ptr"), lpfnWinEventProc := 0    
    return 0
    }
What I'd like is to get context menus ( desktop and all pop up windows on taskbar for example ) having BOTH acrylic effect and such Drop Shadow as Justme gave as example .

Windows 10 native drop shadow on context menus are too thin in my taste .

Is it possible to combine in one script the 2 with justme's one to apply on Windows 10 context menus ?

Thanks for your advices

Best regards
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

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

27 May 2020, 06:13

Just a side note: https://www.autohotkey.com/boards/viewtopic.php?t=63643 . That is the source of your function, which is something based on AHK_TaskBar_SetAttr by jNizM. [just for future reference]

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
ysan
Posts: 4
Joined: 27 May 2020, 04:53

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

27 May 2020, 06:48

Thanks for reference Marius , I had this script from a guy on a forum
ysan
Posts: 4
Joined: 27 May 2020, 04:53

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

17 Jul 2020, 07:41

@joedf

Hi Joe , as you told me for some help on github ( Stahky topic ) , could you please when having time give an eye on this topic and my previous post to see how I could set dorp shadow to context menu with script I posted ?

Thanks !

Best regards
User avatar
joedf
Posts: 8972
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

17 Jul 2020, 09:16

Sure, I will take a look and do some testing. :+1:

EDIT: you want to apply this effect to all context menus? Also, dont use ahk_id, hWnd in your function definitions. I think you'll want just hwnd, since you want to past just the handle not a wintitle string.
Also, I don't think that hook is working. You might want to look at possibly another way here: https://www.autohotkey.com/boards/viewtopic.php?p=290862#p290862

EDIT2: nevermind, i've fixed the hook:

Code: Select all

WINEVENT_SKIPOWNPROCESS := 0x0002
WINEVENT_OUTOFCONTEXT := 0x0000
; https://docs.microsoft.com/en-us/windows/win32/winauto/event-constants
EVENT_SYSTEM_MENUPOPUPSTART := 0x0006

hWinEventHook := DllCall("SetWinEventHook"
	,"UInt", EVENT_SYSTEM_MENUPOPUPSTART
	,"UInt", EVENT_SYSTEM_MENUPOPUPSTART
	,"Ptr", 0
	,"Ptr", (lpfnWinEventProc := RegisterCallback("OnPopupMenu", ""))
	,"UInt", 0
	,"UInt", 0
	,"UInt", WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS )
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
ysan
Posts: 4
Joined: 27 May 2020, 04:53

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

19 Jul 2020, 09:02

Thank you for reply , do you think possible then to add drop shadow ( more accented than windows native one ) at least on context menu desktop keeping the same time the blur script ?
User avatar
joedf
Posts: 8972
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

19 Jul 2020, 18:06

I'm not sure you can apply drop-shadows to context-menus this way. Perhaps, you'll want to consider a custom solution with GDI+.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

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

09 Aug 2023, 08:35

DRocks wrote:
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")
}
;================================================================================
Can someone provide an example of how to use this? I don't get what we're supposed to do with the return value of ClassStyle?
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

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

09 Aug 2023, 09:22

Does the SetAcrylicGlassEffect() function only work as admin? Currently this doesn't work for my context menu's but I can see it's TRYING to do "something"...
image.png
image.png (33.58 KiB) Viewed 1803 times
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

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

09 Aug 2023, 16:49

The function doesn't apply to menus.... As far as I know.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
jamsbone
Posts: 1
Joined: 01 Nov 2023, 21:10

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

01 Nov 2023, 21:16

just me's approach works flawless for me, :thumbup: and DRocks' example helps, thanks guys !
just me wrote:
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")
}
?
think
Posts: 136
Joined: 09 Feb 2014, 05:20

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

12 Dec 2023, 13:18

Great function. But it doesn't work correctly if Gui, +resize option is added to window. Any idea how to further improve it?
william_ahk
Posts: 498
Joined: 03 Dec 2018, 20:02

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

08 Feb 2024, 12:01

Can someone translate this to v2?
XMCQCX
Posts: 234
Joined: 14 Oct 2020, 23:44

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

26 Feb 2024, 16:24

@william_ahk
My attempt to convert it to v2. It's working, but I lack knowledge about address+offset. It was mostly done with the v2 converter, reading the documentation, ChatGPT/Copilot and trial and error.

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2.0

g := Gui('-Caption')
g.SetFont('s30')
g.Add('Text',, 'GUI with rounded corners`npositioned at the bottom right.')
FrameShadow(g.hwnd)

g.Show('Hide')
WinGetPos(,, &gW, &gH, g)
g.Show('x' A_ScreenWidth - gW - 15 'y' A_ScreenHeight - gH - 75)
SetTimer((*) => ExitApp(), -5000)

; Credits Klark92
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=29117&hilit=FrameShadow

FrameShadow(hwnd)
{
    DllCall("dwmapi.dll\DwmIsCompositionEnabled", "int*", &dwmEnabled:=0)
    
    if !dwmEnabled {
        DllCall("user32.dll\SetClassLongPtr", "ptr", hwnd, "int", -26, "ptr", DllCall("user32.dll\GetClassLongPtr", "ptr", hwnd, "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")
        */
        margins := Buffer(16, 0)    
        NumPut("int", 1, "int", 1, "int", 1, "int", 1, margins) ; <= converted from v1 above. I'm not sure about this.

        DllCall("dwmapi.dll\DwmSetWindowAttribute", "ptr", hwnd, "Int", 2, "Int*", 2, "Int", 4)
        DllCall("dwmapi.dll\DwmExtendFrameIntoClientArea", "ptr", hwnd, "ptr", margins)
    }
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 122 guests