SetButtonPixmap() ?

BlitzMax Forums/BlitzMax GUI Programming/SetButtonPixmap() ?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Non-rinky-dink version. You could easily convert this to use images:
Const GWL_STYLE:Int=-16
Const BM_SETIMAGE:Int=247
Const BS_BITMAP:Int=128
Const BS_ICON:Int=64
Const IMAGE_BITMAP:Int=0

Function SetButtonColor(button:TGadget,r,g,b)
	hbutton=QueryGadget(button,QUERY_HWND)
	SetWindowLong hbutton,GWL_STYLE,GetWindowLong(hbutton,GWL_STYLE)|BS_BITMAP
	w=GadgetWidth(button)-4
	h=GadgetHeight(button)-4
	pixels:TBank=CreateBank(w*h*4)
	For y=0 To h-1
		For x=0 To w-1
			PokeByte pixels,4*(y*w+x)+0,r
			PokeByte pixels,4*(y*w+x)+1,g
			PokeByte pixels,4*(y*w+x)+2,b
			PokeByte pixels,4*(y*w+x)+3,0
		Next
	Next
	i=CreateBitmap(w,h,1,32,pixels.buf())
	If Not i Return
	oldimage=SendMessageA(hbutton,BM_SETIMAGE,IMAGE_BITMAP,i)
	If oldimage DeleteObject(oldimage)
	Return True
End Function