Restore user's position in a StrinGadget after SetGadgetText?

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Restore user's position in a StrinGadget after SetGadgetText?

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Restore user's position in a StrinGadget after SetGadgetText?

Post 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)?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Re: Restore user's position in a StrinGadget after SetGadgetText?

Post 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?
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Restore user's position in a StrinGadget after SetGadgetText?

Post 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.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Restore user's position in a StrinGadget after SetGadgetText?

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