At the beginning, it can add shadows, but after activating the window several times,
the shadows will disappear.
FrameShadow(): Drop Shadow On Borderless Window, (DWM STYLE)
https://www.autohotkey.com/boards/viewtopic.php?f=6&p=264108#p264108
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include, Gdip_All.ahk
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Width :=300, Height := 200
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
;pBrush := Gdip_BrushCreateSolid(0xFF0000ff)
pBrush := Gdip_BrushCreateSolid(0xFF00BFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, 300, 200)
Gdip_DeleteBrush(pBrush)
UpdateLayeredWindow(hwnd1, hdc, 500, 300, Width, Height)
;DropShadow_just_me(hwnd1)
FrameShadow(hwnd1)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Return
FrameShadow(HGui)
{ ;add shadow to Gui
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)
}
}
;================================================================================
; 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")
}
Exit:
Gdip_Shutdown(pToken)
ExitApp
Return
Esc::
ExitApp
return