Window skin
BlitzPlus Forums/BlitzPlus Programming/Window skin| 
 | ||
| Hi ! Please, look at the following code... Is there a better method to skin my window ? I've used Dan_upright function from the code archive. Is there also a method to skin the button ? Thanks ! 
Global Win1
Global Button1
Function CreateWin1()
	Win1 = CreateWindow("Window1",252,204,300,200,Desktop(),0)
	Button1 = CreateButton("Exit",100,80,100,40,Win1,0)
	SetGadgetLayout Button1,1,0,1,0
	Img = LoadImage ("skin.png")
	MaskImage img,255,0,255
	skin_window(win1, img, 255, 0, 255)
	
	Canvas1 = CreateCanvas (0,0,300,200,win1,0)
	SetBuffer CanvasBuffer(Canvas1)
	DrawImage img,0,0
	FlipCanvas (Canvas1)
	
End Function
; ------------
; skinnable windows by dan_upright
; see http://www.blitzbasic.com/codearcs/codearcs.php?code=784 for more informations about the decls files
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
; ----------------
CreateWin1()
bQuit = False
Repeat bQuit = False
	WaitEvent()
	If EventSource()= button1 Then Exit
Forever
image :   |