21.09.2025, 05:07 AM
Hey Gary,
The DWM detects the custom region and disables theming for that window to avoid conflicts with shaped windows and falls back to the classic look for the frame/title bar. This is a known Win32 limitation when using SetWindowRgn.
Here, try this other version, this time using GDI+ , as long as you keep enough margin the sizing cursors will activate.
The DWM detects the custom region and disables theming for that window to avoid conflicts with shaped windows and falls back to the classic look for the frame/title bar. This is a known Win32 limitation when using SetWindowRgn.
Here, try this other version, this time using GDI+ , as long as you keep enough margin the sizing cursors will activate.
Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "gdipDash0713.inc" '<-replace with Jose or you own GDI+ include file.
CALLBACK FUNCTION DlgMain()
STATIC captionHigh AS LONG
STATIC keyColor AS LONG
LOCAL hBrushBg, hBrushKey AS DWORD
LOCAL lwide, lhigh, clientWide, clientHigh AS LONG
LOCAL rcWindow AS RECT
LOCAL rcHoleClient AS RECT
LOCAL rcClient AS RECT
LOCAL ps AS PAINTSTRUCT
LOCAL hDC AS DWORD
LOCAL frameX, frameY AS LONG
SELECT CASE AS LONG CB.MSG
CASE %WM_INITDIALOG
captionHigh = GetSystemMetrics(%SM_CYCAPTION)
frameX = GetSystemMetrics(%SM_CXFRAME)
frameY = GetSystemMetrics(%SM_CYFRAME)
keyColor = RGB(255, 0, 255) ' <-use Magenta as key color
SetWindowPos CB.HNDL, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOSIZE OR %SWP_NOMOVE
SetLayeredWindowAttributes CB.HNDL, keyColor, 0, %LWA_COLORKEY
'-force repaint
InvalidateRect CB.HNDL, BYVAL %NULL, %TRUE
CASE %WM_SIZE
InvalidateRect CB.HNDL, BYVAL %NULL, %TRUE
CASE %WM_ERASEBKGND
FUNCTION = 1 :EXIT FUNCTION
CASE %WM_PAINT
hDC = BeginPaint(CB.HNDL, ps)
DIALOG GET SIZE CB.HNDL TO lwide, lhigh
DIALOG GET CLIENT CB.HNDL TO clientWide, clientHigh
GetClientRect CB.HNDL, rcClient
'-calc hole in window coordinates
' note: tweak your margins, left +10, right -25, bottom -25 to allow cursor hit testing
SetRect rcWindow, 10, (lhigh - clientHigh) + captionHigh * 2, lwide - 25, lhigh - captionHigh - 25
'-convert our hole to client coordinates
SetRect rcHoleClient, rcWindow.nLeft - frameX, rcWindow.nTop - (captionHigh + frameY), rcWindow.nRight - frameX, rcWindow.nBottom - (captionHigh + frameY)
'-fill entire client with system dialog background color
hBrushBg = CreateSolidBrush(GetSysColor(%COLOR_3DFACE))
FillRect hDC, rcClient, hBrushBg
DeleteObject hBrushBg
'-now fill hole with key color for transparency
hBrushKey = CreateSolidBrush(keyColor)
FillRect hDC, rcHoleClient, hBrushKey
DeleteObject hBrushKey
EndPaint CB.HNDL, ps
FUNCTION = 0 :EXIT FUNCTION
END SELECT
END FUNCTION
'--------------------------------------------------------------------------------------------------
'
'--------------------------------------------------------------------------------------------------
FUNCTION PBMAIN() AS LONG
LOCAL hDlg AS LONG
LOCAL token AS DWORD
'-start GDI+
IF StartGDIplus(BYREF token) THEN
MSGBOX "Failed to start GDI+", , "Error"
EXIT FUNCTION
END IF
DIALOG NEW PIXELS, 0, "Square Hole Demo", , , 496, 160, %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CAPTION OR %WS_THICKFRAME, %WS_EX_LAYERED TO hDlg
DIALOG SHOW MODAL hDlg, CALL DlgMain
'-stop GDI+
StopGDIplus token
END FUNCTION