ImageButton control, without DirectX

BlitzPlus Forums/BlitzPlus Programming/ImageButton control, without DirectX

JoshK(Posted 2005) [#1]
This will create an imagebutton control using only API commands, no DirectX:

Const LR_LOADFROMFILE=16
Const IMAGE_BUTTON=0
Const GWL_STYLE=-16
Const BS_BITMAP=128
Const BM_SETIMAGE=247

win=CreateWindow("",200,200,400,300)
CreateImageButton("C:\Program Files\BlitzPlus\samples\mak\blitzlogo.bmp",0,0,ClientWidth(win),ClientHeight(win),win)

Repeat
Until WaitEvent()=$803

Function CreateImageButton(imagefile$,x,y,width,height,group)
i=LoadImageA(0,imagefile$,IMAGE_BITMAP,0,0,LR_LOADFROMFILE)
If Not i Return
button=CreateButton("",x,y,width,height,group)
hbutton=QueryObject(button,1)
flags=GetWindowLong(hbutton,GWL_STYLE)+BS_BITMAP
SetWindowLong hbutton,GWL_STYLE,flags
SendMessage(hbutton,BM_SETIMAGE,IMAGE_BITMAP,i)
Return button
End Function



xmlspy(Posted 2005) [#2]
LoadImageA not found - Doesn't work with the loadimage blitz command either.


NetGamer(Posted 2005) [#3]
Use LoadImage or api_LoadImage as defined in the user32.decls file found on this site.
api_LoadImage% (hInst%, lpsz$, un1%, n1%, n2%, un2%) : "LoadImageA"



xmlspy(Posted 2005) [#4]
Yep, works! Nice job.