Code: Select all
#NoEnv
W := 400
H := 400
Gui, +hwndHGUI +LastFound -Caption +AlwaysOnTop
Gui, Color, Black
Gui, Show, w%W% h%H%, Test
Points := [{X: W//2, Y: 0}, {X: W, Y: H//2}, {X: W//2, Y: H}, {X: 0, Y: H//2}]
HRGN1 := Rgn_CreatePolygonRgn(Points)
; HRGN1 := Rgn_CreateEllipticRgn(0, 0, W, H)
HRGN2 := Rgn_CreateEllipticRgn(100, 100, W - 100, H - 100)
Rgn_CombineRgn(HRGN, HRGN1, HRGN2, 3)
Rgn_SetWindowRgn(HGUI, HRGN)
OnMessage(0x0201, "GuiMove")
Return
; --------------------------------------------------------------------------------------------------------------------------------
GuiEscape:
ExitApp
; --------------------------------------------------------------------------------------------------------------------------------
GuiMove() {
PostMessage, 0xA1, 2
}
; ================================================================================================================================
; Regions -> msdn.microsoft.com/en-us/library/dd162913(v=vs.85).aspx
;
; Region Flags (Return Values)
; ERROR 0
; NULLREGION 1
; SIMPLEREGION 2
; COMPLEXREGION 3
;
; CombineRgn() Styles (Mode)
; RGN_AND 1
; RGN_OR 2
; RGN_XOR 3
; RGN_DIFF 4
; RGN_COPY 5
;
; PolyFill() Modes
; ALTERNATE 1
; WINDING 2
; ================================================================================================================================
Rgn_CombineRgn(ByRef HRGNC, HRGN1, HRGN2, Mode) {
HRGN := Rgn_CreateRectRgn(0, 0, 0, 0)
Result := DllCall("CombineRgn", "Ptr", HRGN, "Ptr", HRGN1, "Ptr", HRGN2, "Int", Mode, "Int")
HRGNC := Result ? HRGN : 0
Return Result
}
; ================================================================================================================================
Rgn_CreateEllipticRgn(Left, Top, Right, Bottom) {
Return DllCall("CreateEllipticRgn", "Int", Left, "Int", Top, "Int", Right, "Int", Bottom, "UPtr")
}
; ================================================================================================================================
Rgn_CreateEllipticRgnIndirect(ByRef RECT) {
Return DllCall("CreateEllipticRgnIndirect", "Ptr", &RECT, "UPtr")
}
; ================================================================================================================================
Rgn_CreatePolygonRgn(Points, FillMode := 1) {
If !IsObject(Points) || !(PtCount := Points.Length())
Return 0
VarSetCapacity(PtArray, 8 * PtCount, 0)
Addr := &PtArray
For Each, Point In Points {
Addr := NumPut(Point.X, Addr + 0, "Int")
Addr := NumPut(Point.Y, Addr + 0, "Int")
}
Return DllCall("CreatePolygonRgn", "Ptr", &PtArray, "Int", PtCount, "Int", FillMode, "UPtr")
}
; ================================================================================================================================
Rgn_CreateRectRgn(Left, Top, Right, Bottom) {
Return DllCall("CreateRectRgn", "Int", Left, "Int", Top, "Int", Right, "Int", Bottom, "UPtr")
}
; ================================================================================================================================
Rgn_CreateRectRgnIndirect(ByRef RECT) {
Return DllCall("CreateRectRgnIndirect", "Ptr", &RECT "UPtr")
}
; ================================================================================================================================
Rgn_CreateRoundRectRgn(Left, Top, Right, Bottom, RX, RY) {
Return DllCall("CreateRoundRectRgn", "Int", Left, "Int", Top, "Int", Right, "Int", Bottom, "Int", RX, "Int", RY, "UPtr")
}
; ================================================================================================================================
Rgn_GetWindowRgn(HWND, ByRef HRGNW) {
HRGN := Rgn_CreateRectRgn(0, 0, 0, 0)
Result := DllCall("GetWindowRgn", "Ptr", HWND, "Ptr", HRGN, "Int")
HRGNW := Result ? HRGN : 0
Return Result
}
; ================================================================================================================================
Rgn_GetRgnBox(HRGN, ByRef Left, ByRef Top, ByRef Right, ByRef Bottom) {
VarSetCapacity(RECT, 16, 0)
Result := DllCall("GetRgnBox", "Ptr", HRGN, "Ptr", &RECT, "Int")
Left := NumGet(RECT, 0, "Int"), Top := NumGet(RECT, 4, "Int")
Right := NumGet(RECT, 8, "Int"), Bottom := NumGet(RECT, 12, "Int")
Return Result
}
; ================================================================================================================================
Rgn_SetWindowRgn(HWND, HRGN, Redraw := True) {
Return DllCall("SetWindowRgn", "Ptr", HWND, "Ptr", HRGN, "UInt", !!Redraw, "Int")
}
; ================================================================================================================================
Rgn_DeleteRgn(HRGN) {
Return DllCall("DeleteObject", "Ptr", HRGN, "UInt")
}
; ================================================================================================================================
If you're interested you could complete the wrapper functions.