Page 1 of 1

Thread in linux

Posted: Thu May 19, 2016 6:26 pm
by mestnyi
departs error purebasic 531

Code: Select all

Procedure MouseEvent( );*Gadget )
  Protected DesktopMouseX = DesktopMouseX()
  Protected DesktopMouseY = DesktopMouseY()
  
  ProcedureReturn
EndProcedure


Procedure ClickState()
 Protected MouseEvent = MouseEvent( )
   Debug "Thread"
EndProcedure


;-
Structure ThreadStruct
  Window.i
  Thread.i
  Delay.i
EndStructure

Procedure ThreadCallBack( *This.ThreadStruct )
  With *This
    While IsWindow( \Window )
      Delay(\Delay)
      ClickState()
    Wend 
    
    KillThread(\Thread)
  EndWith
EndProcedure

Procedure Activate( MainWindow, Delay )
  Protected *Thread.ThreadStruct = AllocateMemory( SizeOf( ThreadStruct ))
  *Thread\Thread = CreateThread( @ThreadCallBack(), *Thread ) 
  *Thread\Window = MainWindow
  *Thread\Delay = Delay
EndProcedure


OpenWindow(10, 30, 30, 250, 150, "demo",#PB_Window_SystemMenu)

Activate( 10,15 )

While IsWindow(10)
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      CloseWindow( EventWindow() )
  EndSelect
Wend

; IDE Options = PureBasic 5.42 LTS (Linux - x86)
; CursorPosition = 34
; FirstLine = 26
; Folding = --
; EnableUnicode
; EnableXP

Re: Thread in linux

Posted: Fri May 20, 2016 3:58 pm
by mk-soft
"DesktopMouseXY" work only on Main-scope. Some window and gadget functions don´t work into a threads. Use PostEvents.

Re: Thread in linux

Posted: Fri May 20, 2016 4:32 pm
by mestnyi
"DesktopMouseXY" work only on Main-scope. Some window and gadget functions don´t work into a threads. Use PostEvents.
Thank you very much, so really works, thanks again. :)