Skip to content

Instantly share code, notes, and snippets.

@maz-1
Last active January 27, 2018 07:58
Show Gist options
  • Save maz-1/3b42fb686092a68a01bb107ade3d46b5 to your computer and use it in GitHub Desktop.
Save maz-1/3b42fb686092a68a01bb107ade3d46b5 to your computer and use it in GitHub Desktop.
;https://autohotkey.com/boards/viewtopic.php?t=3144
#NoEnv
#SingleInstance, Force
SetWinDelay, -1
SetBatchLines, -1
#include <gdip>
Global HMain, XMain, YMain, HChild, XChild, YChild
Scaling_Ratio:=A_ScreenDPI/96
;Titlebar 28
;Width and Height should be multiples of 4
WinW:=300
WinH:=300
; ----------------------------------------------------------------------------------------------------------------------
; Main GUI
Gui, Main: New, +LastFound -Caption -Border +HwndHMain +LabelGui +E0x80000 +AlwaysOnTop
FrameShadow(HMain)
Gui, Color, 000000
;WinSet, TransColor, 000000
pToken := Gdip_Startup()
w:=WinW*Scaling_Ratio
h:=WinH*Scaling_Ratio
hbm := CreateDIBSection(w,h)
hdc := GetDC(HMain)
mdc := CreateCompatibleDC(hdc)
obm := SelectObject(mdc, hbm)
pGraphics := Gdip_GraphicsFromHDC(mdc)
;https://msdn.microsoft.com/en-us/library/windows/desktop/ms534173(v=vs.85).aspx
Gdip_SetSmoothingMode(pGraphics, 4)
;https://msdn.microsoft.com/en-us/library/windows/desktop/ms535810(v=vs.85).aspx
Gdip_SetInterpolationMode(pGraphics, 4)
;Setformat Integer,H
;border & fill color
PenWidth:=Scaling_Ratio
;FillColor:=0x7f00b7ee
;Get color via dwm api
VarSetCapacity(vcolor,28)
VarSetCapacity(vsubend,16)
DllCall("dwmapi\DwmGetColorizationColor", "UInt", &vcolor, "UInt", &vsubend)
FillColor:=NumGet(vcolor,0)
FillColor:=(FillColor&0x00ffffff)|0x9f000000
VarSetCapacity(vcolor,0)
VarSetCapacity(vsubend,0)
;Dimmer ∈ [0,2]
;Dimmer < 1 : Dimmer
;Dimmer > 1 : Brighter
Dimmer:=0.9
If (Dimmer < 1 && Dimmer >= 0)
{
BorderR:=Round(((FillColor & 0x00ff0000)//0x10000)*Dimmer)*0x10000
BorderG:=Round(((FillColor & 0x0000ff00)//0x100)*Dimmer)*0x100
BorderB:=Round(((FillColor & 0x000000ff))*Dimmer)
BorderColor:=0xff000000+BorderR+BorderG+BorderB
}
Else If (Dimmer > 1 && Dimmer <= 2)
{
BorderR:=Round(0xff*(Dimmer-1)+((FillColor & 0x00ff0000)//0x10000)*(2-Dimmer))*0x10000
BorderG:=Round(0xff*(Dimmer-1)+((FillColor & 0x0000ff00)//0x100)*(2-Dimmer))*0x100
BorderB:=Round(0xff*(Dimmer-1)+((FillColor & 0x000000ff))*(2-Dimmer))
BorderColor:=0xff000000+BorderR+BorderG+BorderB
}
Else
BorderColor:=FillColor | 0xff000000
pBrush:=Gdip_BrushCreateSolid(FillColor)
pPen:=Gdip_CreatePen(BorderColor, PenWidth)
Shift_Factor:=Round(PenWidth/4-Floor(PenWidth/4))
DrawX:=PenWidth/2, DrawY:=PenWidth/2
DrawW:=w-PenWidth-Shift_Factor, DrawH:=h-PenWidth-Shift_Factor, DrawR:=Scaling_Ratio*5
;Rectangle
Gdip_FillRectangle(pGraphics, pBrush, DrawX, DrawY, DrawW, DrawH)
Gdip_DrawRectangle(pGraphics, pPen, DrawX, DrawY, DrawW, DrawH)
;Rounded Rectangle
;Gdip_FillRoundedRectangle(pGraphics, pBrush, DrawX, DrawY, DrawW, DrawH, DrawR)
;Gdip_DrawRoundedRectangle(pGraphics, pPen, DrawX, DrawY, DrawW, DrawH, DrawR)
UpdateLayeredWindow(HMain, mdc, (A_ScreenWidth-w)//2, (A_ScreenHeight-h)//2, w,h)
;clean up
Gdip_DeletePen(pPen)
Gdip_DeleteBrush(pBrush)
DeleteObject(hbm)
DeleteDC(mdc)
ReleaseDC(hdc, HMain)
Gdip_DeleteGraphics(pGraphics)
Gdip_Shutdown(pToken)
; ----------------------------------------------------------------------------------------------------------------------
; Child GUI
Gui, Child: New, -Caption +LastFound -Border +HwndHChild +OwnerMain
;FrameShadow(HChild)
Gui, Margin, 0, 0
Gui, Color, 123456
Gui, Add, ListView, x10 y10 w200 h200, Colum1|Colum2 ; <----- This control can't be seen
Loop, 10
LV_Add("", "Col1 " . A_Index, "Col2 " . A_Index)
Gui, Add, Edit, x+10 yp w50, Edit
Gui, Add, Button, xp y+10 wp gClicked, Button
WinSet, TransColor, 123456
; ----------------------------------------------------------------------------------------------------------------------
Gui, Main: Show, w%WinW% h%WinH%
EnableBlur(hMain)
WinGetPos, XMain, YMain, W, H, ahk_id %HMain%
XChild := XMain + PenWidth, YChild := YMain + 28*Scaling_Ratio + PenWidth
Gui, Child: Show, x%XChild% y%YChild%
;XChild := XMain, YChild := YMain, W_Child := W/Scaling_Ratio, H_Child := H/Scaling_Ratio
;Gui, Child: Show, x%XChild% y%YChild% w%W_Child% h%H_Child%
OnMessage(0x0201, "WM_LBUTTONDOWN")
OnMessage(0x0216, "WM_MOVING")
OnMessage(0x0232, "WM_EXITSIZEMOVE")
Return
Clicked:
Gui, +OwnDialogs
MsgBox, Bingo!
Return
GuiEscape:
ExitApp
WM_LBUTTONDOWN() {
If (A_Gui = "Main")
PostMessage, 0xA1, 2, 0, , ahk_id %HMain%
}
WM_EXITSIZEMOVE() {
If (A_Gui = "Main")
WinActivate, ahk_id %HChild%
WinActivate, ahk_id %HMain%
}
WM_MOVING(W, L) {
If (A_Gui = "Main") {
DX := NumGet(L + 0, 0, "Int") - XMain, DY := NumGet(L + 0, 4, "Int") - YMain
WinMove, ahk_id %HChild%, , % (XChild += DX), % (YChild += DY)
XMain += DX, YMain += DY
}
}
EnableBlur(hWnd)
{
; WindowCompositionAttribute
WCA_ACCENT_POLICY := 19
; AccentState
ACCENT_DISABLED := 0,
ACCENT_ENABLE_GRADIENT := 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT := 2
ACCENT_ENABLE_BLURBEHIND := 3
ACCENT_INVALID_STATE := 4
accentStructSize := VarSetCapacity(AccentPolicy, 4*4, 0)
NumPut(ACCENT_ENABLE_BLURBEHIND, AccentPolicy, 0, "UInt")
padding := A_PtrSize == 8 ? 4 : 0
VarSetCapacity(WindowCompositionAttributeData, 4 + padding + A_PtrSize + 4 + padding)
NumPut(WCA_ACCENT_POLICY, WindowCompositionAttributeData, 0, "UInt")
NumPut(&AccentPolicy, WindowCompositionAttributeData, 4 + padding, "Ptr")
NumPut(accentStructSize, WindowCompositionAttributeData, 4 + padding + A_PtrSize, "UInt")
DllCall("SetWindowCompositionAttribute", "Ptr", hWnd, "Ptr", &WindowCompositionAttributeData)
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment