I couldn't resist.
Code: Select all
EnableExplicit
Enumeration
#MainWindow
#ButtonWindow
EndEnumeration
Enumeration
#xImage
#oImage
EndEnumeration
Enumeration
#Toolbar
#TBB1
#TBB2
#TBB3
EndEnumeration
Enumeration
#myImageButton
EndEnumeration
Procedure MakeImages()
CreateImage(#xImage, 24, 24)
StartDrawing(ImageOutput(#xImage))
Box(0, 0, 24, 24, $F0F0F0)
LineXY(0,0, 23,23, $0000FF)
LineXY(0,23, 23,0, $0000FF)
StopDrawing()
CreateImage(#oImage, 24, 24)
StartDrawing(ImageOutput(#oImage))
Box(0, 0, 24, 24, $F0F0F0)
DrawingMode(#PB_2DDrawing_Outlined)
Circle(12, 12, 4, $0000FF)
StopDrawing()
EndProcedure
Procedure PinWindow(hWnd, Event, wParam, lParam)
If Event = #WM_WINDOWPOSCHANGED
ResizeWindow(#ButtonWindow,
WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
#PB_Ignore, #PB_Ignore)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
MakeImages(); Because I want to use ButtonImageGadget()
OpenWindow(#MainWindow, 10, 10, 300, 300, "",#PB_Window_SizeGadget|#PB_Window_SystemMenu)
CreateToolBar(#Toolbar, WindowID(#MainWindow))
ToolBarStandardButton(#TBB1, #PB_ToolBarIcon_New)
ToolBarStandardButton(#TBB2, #PB_ToolBarIcon_Open)
ToolBarStandardButton(#TBB3, #PB_ToolBarIcon_Save)
OpenWindow(#ButtonWindow,
WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
24, 24,"", #PB_Window_BorderLess, WindowID(#MainWindow))
ButtonImageGadget(#myImageButton, 0, 1, 24, 24, ImageID(#oImage), #PB_Button_Toggle)
SetGadgetAttribute(#myImageButton, #PB_Button_PressedImage, ImageID(#xImage))
WindowBounds(#MainWindow, GadgetWidth(#myImageButton)+4+#TBB3*24, GadgetHeight(#myImageButton)+4, #PB_Ignore, #PB_Ignore)
SetWindowCallback(@PinWindow(), #MainWindow); 'synchronize' #ButtonWindow with #MainWindow
Define Quit.i=#False
Define Event.i
Define EventGadget.i
Define EventType.i
Repeat
Event=WaitWindowEvent()
EventGadget=EventGadget()
EventType=EventType()
Select Event
Case #PB_Event_Gadget
Select EventGadget
Case #myImageButton
SetActiveWindow(#MainWindow)
Select GetGadgetState(#myImageButton)
Case 0
; Do what you want
Case 1
;Do what you want
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
End
This works for me, as it did before PB v5.x.
when the button is pressed.