Code archives/BlitzPlus Gui/skinnable windows

This code has been declared by its author to be Public Domain code.

Download source code

skinnable windows by dan_upright2003
setup the two .decls files and then pass the function your window handle, an image (which should be the same size as the window) and a mask colour and it'll make the window shape match the non-masked areas of the image
user32.decls:
----
.lib "user32.dll"

SetWindowRgn%(hWnd%, hRgn%, bRedraw%)
----

gdi32.decls:
----
.lib "gdi32.dll"

CreateRectRgn%(X1%, Y1%, X2%, Y2%)
CombineRgn%(hDestRgn%, hSrcRgn1%, hSrcRgn2%, nCombineMode%)
DeleteObject%(hObject%)
----

and the blitz function:
----
Function skin_window(window, img, r, g, b)

	w = ImageWidth(img)
	h = ImageHeight(img)
	LockBuffer ImageBuffer(img)
	mask = (255 Shl 24) + (r Shl 16) + (g Shl 8) + b

	hWnd = QueryObject(window, 1)
	hRgn = CreateRectRgn(0, 0, w, h)
	For y = 0 To h - 1
		For x = 0 To w - 1
			pixel = ReadPixelFast(x, y, ImageBuffer(img))
			If pixel = mask
				hTempRgn = CreateRectRgn(x, y, x + 1, y + 1)
				CombineRgn(hRgn, hRgn, hTempRgn, 3)
				DeleteObject(hTempRgn)
			EndIf
		Next
	Next
	UnlockBuffer ImageBuffer(img)
	
	SetWindowRgn(hWnd, hRgn, True)
	DeleteObject(hRgn)

End Function

Comments

None.

Code Archives Forum