Refresh a window

Just starting out? Need help? Post your questions and find answers here.
Julien
User
User
Posts: 17
Joined: Fri Apr 25, 2003 6:08 pm
Location: France

Refresh a window

Post by Julien »

Hello :)
How Refresh a window which contains gadget? :?:
So that the text is show.

Thanks

My code is


If OpenWindow(5,0, 204, 185, 94, #PB_Window_SystemMenu | #PB_Window_TitleBar , "1")
If CreateGadgetList(WindowID())

TextGadget(1, 10, 60, 160, 15, "My text is hiden")

EndIf
EndIf





For k=1 To 200
MoveWindow(0,k)
Delay(5)
ActivateWindow()

Next k




For k=1 To 125
MoveWindow(k,200)
Delay(5)
ActivateWindow()
Next k

Delay(2000)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

--Kale

Image
Julien
User
User
Posts: 17
Joined: Fri Apr 25, 2003 6:08 pm
Location: France

Post by Julien »

This code no works in XP home

RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE)

RedrawWindow_(WindowID(), 0, 0, 7)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The window can only be refreshed, if it's messages are processed. That
only happens, if you call WindowEvent() or WaitWindowEvent()

That's the way it works, those Redraw commands are not really needed.

Just insert something like that:

Code: Select all

Repeat
  Event.l = WaitWindowEvent()
Until Event = #PB_EventCloseWindow  ; <- User clicked the [x]
(Maybe we should put this thing in the manual somewhere, as it seems to
that more people don't know that)

Timo
quidquid Latine dictum sit altum videtur
Julien
User
User
Posts: 17
Joined: Fri Apr 25, 2003 6:08 pm
Location: France

Post by Julien »

Sorry but i dont understand,
I want to move the window , but the gadget are not Refresh !
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Julien wrote:Sorry but i dont understand,
I want to move the window , but the gadget are not Refresh !
If your application does not give control to the OS (Windows), its messages are not processed, and no redraw is done on the window surface.

Code: Select all

If OpenWindow(5,0, 204, 185, 94, #PB_Window_SystemMenu | #PB_Window_TitleBar , "1")
  If CreateGadgetList(WindowID())
    
    TextGadget(1, 10, 60, 160, 15, "My text is hiden")
    
  EndIf
EndIf

For k=1 To 200
  MoveWindow(0,k)
  WindowEvent()
  Delay(5)
Next k

For k=1 To 125
  MoveWindow(k,200)
  WindowEvent()
  Delay(5)
Next k

Delay(2000)
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Try:

UpdateWindow_(hWnd)

:?:

So, something like this works fine here:

Code: Select all

If OpenWindow(5,0, 204, 185, 94, #PB_Window_SystemMenu | #PB_Window_TitleBar , "1") 
  If CreateGadgetList(WindowID()) 
  ButtonGadget(1,0,0,185,30,"Hello World",0)
  TextGadget(2, 10, 60, 160, 15, "My text is hiden") 
  EndIf 
EndIf 

For k=1 To 200 
  MoveWindow(0,k) 
  Delay(5) 
  UpdateWindow_(WindowID(5))
Next k 

For k=1 To 125 
  MoveWindow(k,200) 
  Delay(5) 
  UpdateWindow_(WindowID(5))
Next k 

Delay(2000)
Edit:
When I run the code with WindowEvent() instead of UpdateWindow_() here with Debugger on, the TextGadget is shown some seconds after programstart, but with UpdateWindow immediately. No idea, why.
%1>>1+1*1/1-1!1|1&1<<$1=1
Julien
User
User
Posts: 17
Joined: Fri Apr 25, 2003 6:08 pm
Location: France

Post by Julien »

:D Thanks for you Help, i am new in the programation purebasic,
UpdateWindow_(WindowID(5)) work fine
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I'm sorry Froggerprogger, but that is not a good solution.

First of all, this only updates the client area, the window top will look quite
ugly, if you move some other window over it.

This functiony just bypasses all of PB's own message handling, wich,
doesn't cause any problems right now, but it may very well be a problem
in future versions. As Danilo allready said, they change internal stuff if
it's neccessary without telling everybody, so maybe some day, all your
code just stops working right, and you don't know why.

Why don't you yust use PB's own functions for this? This way you can be
sure, it will work forever.

If you don't want to use WaitWindowEvent(), but only just update the
window, use this:

Code: Select all

While WindowEvent(): Wend
This just processes all messages in the queue, and does all neccesary updating.

BTW: If you include a close Button on top of your window
(#PB_Window_SystemMenu flag), you should always check, if the user
pressed it. What else would it be there for?

the UpdateWindow_() function doesn't check that, but you can easily check
it wit WindowEvent().
Something like this is a good way here:

Code: Select all

Procedure PBUpdateWindows()
  Repeat
    Event.l = WindowEvent()
    If Event = #PB_EventCloseWindow
      End
      ; or some other action to do
    Endif
  Until Event = 0
EndProcedure
You should always check for things like that, so no events are lost. If there
is a button on your Window, and pressing it has no effect, the user may
think the program is hung and close it with TaskManager.

Hum, that's just my opinion, if you want, use UpdateWindow_(), but IMHO,
it's not a good way.

Timo
quidquid Latine dictum sit altum videtur
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

@freak
I always work with a WindowEvent()+Delay(x)-loop or WaitWindowEvent()-loop and select-case all messages with them or use a window-callback-procedure.

But some days ago I had a big problem with creating a window and then playing a movie on a part of it, where the whole background of the main-window was an ImageGadget. The film started automatically immediately after program start.
The problem now was, that after about one second playback the movie could not be seen anymore (but heard), until I moved the MainWindow MANUALLY with the mouse. Even if I delayed the playback-start for seconds, the problem wasn't solved. I tried using CreateWindowEx_() for a child-window for the movie. Works, but solved not the problem.
I tried hard and tried a lot of stuff with SendMessage_() in combinations with ActivateWindow() (sometimes the API-commands had influence to the PB-intern-Window-commands vice versa, they changed the active PB-Window)- No way. (BTW: in the main loop there was WindowEvent() with Delay(15))
-> the only way to solve this problem under XP and Win2000 - leaving all logic behind - was just to insert a simple & comfortable UpdateWindow_() followed by an ActivateGadget() once after the Movie started.
OK, perhaps it's not the right way (I have to learn a lot more about Windows' internal work), but it was THE solution.

BTW: I recognized UpdateWindow_() works only child-intern, so I used it on the parent window -> all childs are updated, too. (at least the movie - window)

And try out the one thing, I said in my posting above
UpdateWindow_() even works better than WindowEvent(), because while the Window is behind the Debugger-Window, it is NOT updated via WindowEvent() here, I don't know why. UpdateWindow_() works fine.
Until now.
%1>>1+1*1/1-1!1|1&1<<$1=1
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Just process ALL messages as Freak said, there is realy no need for API here, this is the basic event coding in PB.

Code: Select all

If OpenWindow(5,0, 204, 185, 94, #PB_Window_SystemMenu | #PB_Window_TitleBar , "1") 
  If CreateGadgetList(WindowID()) 
    
    TextGadget(1, 1, 60, 160, 15, "My text is hiden") 
    
  EndIf 
EndIf 

For k=1 To 200 
  MoveWindow(0,k) 
  While WindowEvent(): Wend 
  Delay(5) 
Next k 

For k=1 To 125 
  MoveWindow(k,200) 
  While WindowEvent(): Wend 
  Delay(5) 
Next k 

Delay(2000)
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Julien wrote::D Thanks for you Help, i am new in the programation purebasic,
UpdateWindow_(WindowID(5)) work fine
It does not work fine Julien, you MUST process the window messages if you use a window in your application.
There is realy no other correct way to do it.
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

freak wrote: BTW: If you include a close Button on top of your window
(#PB_Window_SystemMenu flag), you should always check, if the user
pressed it. What else would it be there for?
Yes, if you write a windows app, make sure it works as a normal windows app. The close box is there to klick with the mouse, so users will klick it....and try to make your application work both with shortcut keys AND mouse, like every professional windows app.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Of course, I cannot handle Window-Events with UpdateWindow.
But UpdateWindow updates the window better than WindowEvent does.

Here's an example:
Just run the code with debugger ON and move the Debugger-Window around above the gadgets of the Program-Window.
There you can toggle the UpdateWindow-call ON/OFF with a button and see, what I mean.

Code: Select all

If OpenWindow(1,200, 200, 185, 330, #PB_Window_SystemMenu | #PB_Window_TitleBar , "UpdateWindow_() - Test") 
  If CreateGadgetList(WindowID()) 
    ButtonGadget(1,0,0,185,45,"Klick me to toggle UpdateWindow ON/OFF",#PB_Button_MultiLine) 
    act.s = "not active"
    TextGadget(2, 0, 60, 185, 50, "UpdateWindow_() is " + act, #PB_Text_Border) 
    Frame3DGadget(3, 0, 128, 185, 30, "Debugger on ?? ") 
    TextGadget(4, 0, 165, 185, 55, "Just move the Debugger-Window around over me.", #PB_Text_Border) 
    SpinGadget(5,0,230,185,25,1,100)
    SetGadgetState(5, 123456) 
    StringGadget(6, 0, 260, 185, 25, "move it move it !") 
    TrackBarGadget(7, 0, 290, 185, 24, 200, 400) 
  EndIf 

  Repeat
    If toggle : UpdateWindow_(WindowID(1)) : EndIf
    Delay(1) 
    getevent = WindowEvent()
    If getevent = #PB_EventGadget And EventGadgetID() = 1
        toggle!1
        If toggle : act = "active" : Else : act ="not active" : EndIf
        SetGadgetText(2,"UpdateWindow_() is " + act)
    EndIf
  Until getevent = #PB_Event_CloseWindow
EndIf 
With UpdateWindow enabled the window is immediately repainted and the program looks more stable.
btw: I cannot see an effect on the CPU.

basta! :wink:
ok why not to use it ?
%1>>1+1*1/1-1!1|1&1<<$1=1
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Your event loop is wrong, you put a delay in the processing of the events, so you make the window repaint slow.
this works much better, and eat much less CPU time

Code: Select all

If OpenWindow(1,200, 200, 185, 330, #PB_Window_SystemMenu | #PB_Window_TitleBar , "UpdateWindow_() - Test") 
  If CreateGadgetList(WindowID()) 
    ButtonGadget(1,0,0,185,45,"Klick me to toggle UpdateWindow ON/OFF",#PB_Button_MultiLine) 
    act.s = "not active" 
    TextGadget(2, 0, 60, 185, 50, "UpdateWindow_() is " + act, #PB_Text_Border) 
    Frame3DGadget(3, 0, 128, 185, 30, "Debugger on ?? ") 
    TextGadget(4, 0, 165, 185, 55, "Just move the Debugger-Window around over me.", #PB_Text_Border) 
    SpinGadget(5,0,230,185,25,1,100) 
    SetGadgetState(5, 123456) 
    StringGadget(6, 0, 260, 185, 25, "move it move it !") 
    TrackBarGadget(7, 0, 290, 185, 24, 200, 400) 
  EndIf 

  Repeat 
    ;If toggle : UpdateWindow_(WindowID(1)) : EndIf 
    ;Delay(1) 
    getevent = WaitWindowEvent() 
    If getevent = #PB_EventGadget And EventGadgetID() = 1 
        toggle!1 
        If toggle : act = "active" : Else : act ="not active" : EndIf 
        SetGadgetText(2,"UpdateWindow_() is " + act) 
    EndIf 
  Until getevent = #PB_Event_CloseWindow 
EndIf
And here a version with WindowEvent()
Your app must get the events as quickly as possible, always....

Code: Select all

If OpenWindow(1,200, 200, 185, 330, #PB_Window_SystemMenu | #PB_Window_TitleBar , "UpdateWindow_() - Test")
  If CreateGadgetList(WindowID())
    ButtonGadget(1,0,0,185,45,"Klick me to toggle UpdateWindow ON/OFF",#PB_Button_MultiLine)
    act.s = "not active"
    TextGadget(2, 0, 60, 185, 50, "UpdateWindow_() is " + act, #PB_Text_Border)
    Frame3DGadget(3, 0, 128, 185, 30, "Debugger on ?? ")
    TextGadget(4, 0, 165, 185, 55, "Just move the Debugger-Window around over me.", #PB_Text_Border)
    SpinGadget(5,0,230,185,25,1,100)
    SetGadgetState(5, 123456)
    StringGadget(6, 0, 260, 185, 25, "move it move it !")
    TrackBarGadget(7, 0, 290, 185, 24, 200, 400)
  EndIf
  
  Repeat
    If toggle : UpdateWindow_(WindowID(1)) : EndIf
    Delay(1)
    Repeat
      getevent = WindowEvent()
      If getevent = #PB_EventGadget And EventGadgetID() = 1
        toggle!1
        If toggle : act = "active" : Else : act ="not active" : EndIf
        SetGadgetText(2,"UpdateWindow_() is " + act)
      ElseIf getevent = #PB_Event_CloseWindow
        End
      EndIf
    Until getevent = 0
  ForEver 
EndIf
Post Reply