Changing value of gadget during size/move window [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Changing value of gadget during size/move window [Resolved]

Post by Kwai chang caine »

Hello at all

With this code, when i move or resize the window the counter stop :|

Code: Select all

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: Select all

#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
Last edited by Kwai chang caine on Mon Apr 04, 2016 6:45 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Changing value of gadget during size or move window

Post by RASHAD »

Using Thread

Code: Select all

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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Changing value of gadget during size or move window

Post by Kwai chang caine »

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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Changing value of gadget during size/move window [Resolv

Post by wilbert »

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: Select all

#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
Windows (x64)
Raspberry Pi OS (Arm64)
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Changing value of gadget during size/move window [Resolv

Post by Oma »

Hi!
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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Changing value of gadget during size/move window [Resolv

Post by Kwai chang caine »

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
Post Reply