It is currently Wed Oct 28, 2020 9:53 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Changing value of gadget during size/move window [Resolved]
PostPosted: Mon Apr 04, 2016 4:11 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4746
Location: Lyon - France
Hello at all

With this code, when i move or resize the window the counter stop :|
Code:
OpenWindow(0, 100, 100, 200, 200, "Change during move", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
TextGadget(0, 10, 10, 100, 20, "")

Repeat 
                                                       
 Evenement = WaitWindowEvent(100)
 
 i + 1
 SetGadgetText(0, "Texte number " + Trim(Str(i)))

Until Evenement = #PB_Event_CloseWindow
So i if i add a timer, this time that works :D
Code:
#Timer1 = 1

Procedure CallBack(hWnd, Msg, wParam, lParam)
 
 Static i
 
 Select Msg

  Case #WM_TIMER

    If wParam = #Timer1
     
     i + 1
     SetGadgetText(0, "Texte number " + Trim(Str(i)))
     
    EndIf
 
  EndSelect
 
EndProcedure

OpenWindow(0, 100, 100, 200, 200, "Change during move", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
TextGadget(0, 10, 10, 100, 20, "")

SetTimer_(WindowID(0), #Timer1, 500, @CallBack()) ; envoie un evenement toutes les 500 millisecondes

Repeat 
                                                       
 Evenement = WindowEvent()
 Delay(1)

Until Evenement = #PB_Event_CloseWindow
Have you a way, for not using a timer, and have the same behavior ?

Have a good day

_________________
ImageThe happiness is a road...
Not a destination


Last edited by Kwai chang caine on Mon Apr 04, 2016 6:45 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Changing value of gadget during size or move window
PostPosted: Mon Apr 04, 2016 6:35 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3708
Using Thread
Code:
Procedure Counter(para)
  Repeat
   i + 1
   SetGadgetText(0, "Texte number " + Trim(Str(i)))
   Delay(50)
  ForEver
EndProcedure

OpenWindow(0, 100, 100, 200, 200, "Change during move", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
TextGadget(0, 10, 10, 100, 20, "")

thread = CreateThread(@Counter(), 35)

Repeat
                                                       
 Evenement = WaitWindowEvent(0)
 
Until Evenement = #PB_Event_CloseWindow

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Changing value of gadget during size or move window
PostPosted: Mon Apr 04, 2016 6:44 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4746
Location: Lyon - France
Hello RASHAD :D

Yes i have forgotten thread :oops:
I try to adapt your code into mine

Thanks a lot
Have a very good day

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Changing value of gadget during size/move window [Resolv
PostPosted: Mon Apr 04, 2016 7:08 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3683
Location: Netherlands
I wouldn't recommend to update a gui element from outside the main thread.
It may work on Windows but is definitely not a safe cross platform solution.

A timer isn't that bad but I don't see why you would use a Windows api call SetTimer_() when PB offers the same functionality with less code.

The code below is cross platform compatible
Code:
#Timer1 = 1

Procedure Timer1CallBack()
  Static i
 
  i + 1
  SetGadgetText(0, "Texte number " + Trim(Str(i)))
 
EndProcedure

OpenWindow(0, 100, 100, 200, 200, "Change during move", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
TextGadget(0, 10, 10, 100, 20, "")

AddWindowTimer(0, #Timer1, 500)
BindEvent(#PB_Event_Timer, @Timer1Callback(), 0, #Timer1)

Repeat 
                                                       
 Evenement = WindowEvent()
 Delay(1)

Until Evenement = #PB_Event_CloseWindow

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Changing value of gadget during size/move window [Resolv
PostPosted: Mon Apr 04, 2016 7:27 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 26, 2014 9:17 am
Posts: 312
Location: Germany
Hi!
Quote:
With this code, when i move or resize the window the counter stop ...
Just for clarification: not on Linux. Here the event loop 'keeps on moving'.

Regards, Charly

_________________
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de


Top
 Profile  
Reply with quote  
 Post subject: Re: Changing value of gadget during size/move window [Resolv
PostPosted: Mon Apr 04, 2016 7:35 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4746
Location: Lyon - France
Quote:
why you would use a Windows api call SetTimer_() when PB offers the same functionality with less code.

Simply because, i have not again the habit to use bindevent and not know use it :oops:
I'm on smartphone now, i test all the codes tomorrow
Thanks a lot WILBERT for your help 8)

@Oma
Thanks for the information

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: nsstudios and 54 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye