Page 1 of 1

Posted: Sun Jan 12, 2003 10:56 pm
by BackupUser
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?

Posted: Sun Jan 12, 2003 11:46 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

Try UpdateWindow_(GadgetID(xxx)), it should do the trick

Fred - AlphaSND

Posted: Sun Jan 12, 2003 11:56 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

or:

RedrawWindow_(WindowID(),0,0,1)

--Kale

Getting used to PureBasic and falling in Love! :)

Posted: Mon Jan 13, 2003 2:38 am
by BackupUser
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:

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

Posted: Mon Jan 13, 2003 12:16 pm
by BackupUser
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.

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
Thanks again, Geoff

(edited to add indenting)