EditorGadget with thread not show cursor [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

EditorGadget with thread not show cursor [Resolved]

Post by Kwai chang caine »

Hello at all,

In this code, i have a strange behaviour :shock:
The cursor don't appears at the end of the text in the editorGadget, then i have good write a SetActiveGadget(1) :?:

After one hour to simplify my big code, i have find the problem, but i not understand why :shock:
If the SetActiveGadget(1) is into the second thread that not works, and if he is in the main thread, that works :shock:
Uncomment the line 36 to show the cursor :wink:

Code: Select all

Global a

Procedure Thread(*Value)
 
 Repeat
  
  If a
   
   a = #False
   
   For i = 1 To 10
    
    If Text$ <> ""
     Text$ + #CRLF$
    EndIf
    
    Text$ + "kcc hello"
    
   Next 
   
   SetGadgetText(1, Text$)
   SendMessage_(GadgetID(1), #EM_SETSEL, -1, -1)
   SetActiveGadget(1) ; <====== This SetActiveGadget not works in the THREAD
   
  EndIf
  
 ForEver
 
EndProcedure

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) 
EditorGadget(1, 10, 10, 492, 364)
CreateThread(@Thread(), 0)

a = #True
; SetActiveGadget(1) ; Uncomment this line, this time the cursor appear at the end of the text

Repeat 
 Select WaitWindowEvent() 
  Case #PB_Event_CloseWindow 
   Break 
 EndSelect 
ForEver 
Someone have an idea why ?

Have a good day
Last edited by Kwai chang caine on Sat Nov 21, 2020 9:37 am, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: EditorGadget with thread not show cursor

Post by Little John »

Code: Select all

SetActiveGadget(1) ; <====== This SetActiveGadget not works in the THREAD
This is the general rule: Everything that is related to the GUI should be done in the main code, but not in a thread.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget with thread not show cursor

Post by Kwai chang caine »

Aaaah Ok !!!!!
I know it's impossible to open window in a thread, but not what you learning to me now :oops:
Thanks a lot LITTLE JOHN for your quick help 8)

Have a very good day
ImageThe happiness is a road...
Not a destination
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: EditorGadget with thread not show cursor [Resolved]

Post by Little John »

You are welcome!
And if you really want a thread to change something in the GUI, use PostEvent() in the thread for passing the repective information to the main code. And then the main code actually has to change the GUI.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget with thread not show cursor [Resolved]

Post by Kwai chang caine »

Super idea MASTER :idea:
I keep it for the next need :D
You have see.... i have not put this question in the bug section :mrgreen: :wink: :lol:
Again thanks LITTLE JOHN for your precious help 8)
ImageThe happiness is a road...
Not a destination
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: EditorGadget with thread not show cursor [Resolved]

Post by Little John »

Kwai chang caine wrote:You have see.... i have not put this question in the bug section :mrgreen: :wink: :lol:
Image :lol:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget with thread not show cursor [Resolved]

Post by Kwai chang caine »

:lol: :lol: 8)
ImageThe happiness is a road...
Not a destination
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: EditorGadget with thread not show cursor [Resolved]

Post by mk-soft »

Forgotten ...

Show Signatur 'ThreadToGUI'
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget with thread not show cursor [Resolved]

Post by Kwai chang caine »

Aaaah yes !!!
You have already plan to deal with this kind of problem :shock: :wink:
Thanks a lot for the link, that can be usefull a day 8)
ImageThe happiness is a road...
Not a destination
Post Reply