I want to create a gray overlay with a rectangle inside to highlight whatever is in the rectangle. I've got it working with an eclipse: But I fail to create a rectangle cut out.
Here's my code:
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#include %A_ScriptDir%
#Include, lib\Gdip_All.ahk
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Width :=1400, Height := 1050
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)
Gdip_SetSmoothingMode(G, 4)
; Create Overlay
pBrush := Gdip_BrushCreateSolid(0x70c3c3c3)
Gdip_FillRectangle(G, pBrush, 0, 0, 1000, 1000)
; Create clip path
pPath := Gdip_CreatePath(1)
Gdip_AddPathEllipse(pPath, 100, 100, 100, 100)
; Apply clip path
Gdip_SetClipPath(G, pPath, 0)
Gdip_GraphicsClear(G)
; Show
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
SelectObject(hdc, obm)
; Clear
DeleteObject(hbm)
Gdip_DeleteGraphics(G)
Return
ESC::
Exit:
Gdip_Shutdown(pToken)
ExitApp
Return