Page 1 of 1
Restore user's position in a StrinGadget after SetGadgetText?
Posted: Wed Aug 07, 2024 3:00 am
by Quin
I have a StringGadget in my app that I want to update using a window timer every 250 MS. It owrks perfectly, but whenever I do this, the cursor position gets reset. I've tried this:
Code: Select all
Protected StartPos, EndPos
SendMessage_(GadgetID(#MyTextField), #EM_GETSEL, @StartPos, @EndPos)
SetGadgetText(#StrDateTime, GetDateTime())
SendMessage_(GadgetID(#MyTextField), #EM_SETSEL, StartPos, EndPos)
This works, but the correct character isn't always set. For example, I'll have to arrow over particular characters multiple times because I got thrown backwards. I don't quite understand why, as if I do this in a Win32 C application, it works correctly 100% of the time. Any tips here?
Thanks.
Re: Restore user's position in a StrinGadget after SetGadgetText?
Posted: Wed Aug 07, 2024 3:03 pm
by jacdelad
Hi Quin,
two question:
1. Before everyone posts a "works here", can you post a working example, which shows the described behaviour on your side, please?
2. Out of curiosity: Why do you need to do this (if I may ask)?
Re: Restore user's position in a StrinGadget after SetGadgetText?
Posted: Wed Aug 07, 2024 3:27 pm
by ebs
My first question/comment is that it appears you are working with two different string gadgets: #MyTextField and #StrDateTime. Is this what you intended?
Re: Restore user's position in a StrinGadget after SetGadgetText?
Posted: Wed Aug 07, 2024 4:35 pm
by Quin
jacdelad wrote: Wed Aug 07, 2024 3:03 pm
Hi Quin,
two question:
1. Before everyone posts a "works here", can you post a working example, which shows the described behaviour on your side, please?
2. Out of curiosity: Why do you need to do this (if I may ask)?
I'll get a working example done later today hopefully, if life doesn't life.

My application functions as a stopwatch, and I show the user their time remaining in a text field. However, I obviously need to update the text field whenever the time changes, which it does every 100 MS. If a user's reading the text field with their arrow keys, it shouldn't be interrupted by the field updating. SOmehow, in pure Win32 C using SendMessage and SetWindowText directly this works perfectly fine, but something about PB's StringGadget or SetGadgetText or something makes it so that the wrong character is reported when arrowing very often.
Re: Restore user's position in a StrinGadget after SetGadgetText?
Posted: Wed Aug 07, 2024 4:36 pm
by Quin
ebs wrote: Wed Aug 07, 2024 3:27 pm
My first question/comment is that it appears you are working with two different string gadgets:
#MyTextField and
#StrDateTime. Is this what you intended?
Nope, that was a find/replace error. #StrDateTime was a constant in my application that I intended to replace everywhere with #MyTextField, guess I missed a spot
