Restored from previous forum. Originally posted by geoff.
I have a window in which I have drawn some graphics and also added a button gadget.
I have written a procedure to redraw the window when the window receives a WM_PAINT message, for example when the window ceases to be covered with something else.
But when the window is redrawn I lose the button. What do I include in the redraw procedure to restore the button and/or other gadgets in the window?
I can use ResizeGadget() keeping the size as it was. This works but doesn't seem the right way to do this. What I need is a command like Redraw_All_Gadgets_In_Gadget_List_for_this_window()
What is the right way to do this?
Repaint Gadgets
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> I have written a procedure to redraw the window when the window
> receives a WM_PAINT message, for example when the window ceases to
> be covered with something else.
I've always done it with a CallBack like this:
> I have written a procedure to redraw the window when the window
> receives a WM_PAINT message, for example when the window ceases to
> be covered with something else.
I've always done it with a CallBack like this:
Code: Select all
Procedure DrawRoutine()
StartDrawing(WindowOutput())
Line(50,50,300,10)
StopDrawing()
EndProcedure
;
Procedure MyWindowCallback(WindowID,Message,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
If message=#WM_PAINT
DrawRoutine()
EndIf
ProcedureReturn Result
EndProcedure
;
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
ButtonGadget(0,10,10,50,20,"test")
DrawRoutine() ; Draw initial line.
SetWindowCallback(@MyWindowCallback())
Repeat
ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
EndIf
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by geoff.
Thank you all.
Kale's solution is the one which works for me.
Here is PB's code with 2 lines added in case it helps others. If you leave out Kale's RedrawWindow_() line then the box() graphic overwrites the button.
PB's original code works because his graphic does not overwrite the button.
Fred's UpdateWindow() doesn't seem to redraw the button.
Thanks again, Geoff
(edited to add indenting)
Thank you all.
Kale's solution is the one which works for me.
Here is PB's code with 2 lines added in case it helps others. If you leave out Kale's RedrawWindow_() line then the box() graphic overwrites the button.
PB's original code works because his graphic does not overwrite the button.
Fred's UpdateWindow() doesn't seem to redraw the button.
Code: Select all
Procedure DrawRoutine()
StartDrawing(WindowOutput())
Box(0,0,100,100); overwrite button
Line(50,50,300,10)
RedrawWindow_(WindowID(),0,0,1); redraws the button
; UpdateWindow_(GadgetID(0)); does not redraw button
StopDrawing()
EndProcedure
;
Procedure MyWindowCallback(WindowID,Message,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
If message=#WM_PAINT
DrawRoutine()
EndIf
ProcedureReturn Result
EndProcedure
;
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
ButtonGadget(0,10,10,50,20,"test")
DrawRoutine() ; Draw initial line.
SetWindowCallback(@MyWindowCallback())
Repeat
ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
EndIf
(edited to add indenting)