I use them for color dialogs. When the user presses the button, a color dialog is opened. The button is then set to a solid color image of the selected color.
I also use them with an arrow image sometimes, like to move terrain layers up and down in the stack.
Here's some code to do it:
I also use them with an arrow image sometimes, like to move terrain layers up and down in the stack.
Here's some code to do it:
Function SetButtonImage(button,image) hbutton=QueryObject(button,1) flags=GetWindowLong(hbutton,GWL_STYLE) If image If Not (BS_BITMAP And flags) SetWindowLong hbutton,GWL_STYLE,flags+BS_BITMAP EndIf Else If (BS_BITMAP And flags) SetWindowLong hbutton,GWL_STYLE,flags-BS_BITMAP Return EndIf w=ImageWidth(image) h=ImageHeight(image) ibuffer=ImageBuffer(image) LockBuffer ibuffer pixels=CreateBank(w*h*4) For y=0 To h-1 For x=0 To w-1 PokeInt pixels,4*(y*w+x)+0,ReadPixelFast(x,y,ibuffer) Next Next UnlockBuffer ibuffer i=CreateBitmap(w,h,1,32,pixels) FreeBank pixels If Not i Return oldimage=SendMessage(hbutton,BM_SETIMAGE,IMAGE_BITMAP,i) If oldimage DeleteObject(oldimage) Return True End Function
Function SetButtonColor(button,r,g,b) hbutton=QueryObject(button,1) flags=GetWindowLong(hbutton,GWL_STYLE) If Not (BS_BITMAP And flags) SetWindowLong hbutton,GWL_STYLE,flags+BS_BITMAP EndIf w=GadgetWidth(button)-4 h=GadgetHeight(button)-4 pixels=CreateBank(w*h*4) For y=0 To h-1 For x=0 To w-1 PokeInt pixels,4*(y*w+x)+0,RGB(r,g,b) Next Next i=CreateBitmap(w,h,1,32,pixels) FreeBank pixels If Not i Return oldimage=SendMessage(hbutton,BM_SETIMAGE,IMAGE_BITMAP,i) If oldimage DeleteObject(oldimage) Return True End Function