0

I have a CEdit-Box containing some text, which is being refreshed by a thread every ~0.25 seconds. The problem is that everytime the text is being refreshed, a possible selection of text is being erased.

I found 2 ways to avoid this so far:

My implementation right now (1) :

Use quite a passage of logic in order to assure that the text is actually really changing, and not just refreshing itself with the exact same string. This is kind of avoiding the problem, but it feels very clunky to be honest.

Another idea (2) :

Every cycle, before the text is being refreshed, we need to grab the selection we currently have, store it, and try to reconstruct it after our text has been refreshed. However, I don't know how this would turn out if the new text doesn't contain our old string at all. I guess the functionality is implemented in WTL, but I don't think this is a very good approach.

Is there any other way? Something like a control setting which would do something like this?

Sossenbinder
  • 4,852
  • 5
  • 35
  • 78
  • How should your program react if following situation arises (capital letters represent the selection): Actual text: "heLLo", new text "World". What should be selected in the new text? – Jabberwocky Dec 11 '15 at 07:37
  • Actually nothing, yeah... Seems like this would go a lot deeper than I thought it would. Probably gonna stick to my current solution. – Sossenbinder Dec 11 '15 at 07:44
  • 1
    The current solution looks OK to me. – Jabberwocky Dec 11 '15 at 07:47
  • Actually it is, yes. I just thought there might be some handy option provided by WTL already. – Sossenbinder Dec 11 '15 at 07:49
  • I would re-think your entire approach. Why would you let your users to select anything in that box if it is overwritten four times a second? What could they possibly do with that selection??? – Vlad Feinstein Dec 11 '15 at 12:26
  • *"I have a CEdit-Box containing some text, which is being refreshed by a thread every ~0.25 seconds."* - That makes it look totally not ok. Windows have thread affinity. Unless you don't care about correctness, you should only ever modify a window from its owning thread. – IInspectable Dec 11 '15 at 12:31
  • @VladFeinstein I don't really know, but someone might want to get the text inside the box and copy it. I just don't want to leave any eventualities open. – Sossenbinder Dec 11 '15 at 12:52
  • @IInspectable I see your point. I guess I picked my words a little wrong. The threads I was referring to are only collection threads, which my main thread cycles from time to time, to check whether changes have to be applied. My bad – Sossenbinder Dec 11 '15 at 12:52
  • 1
    For "Copy" you have options: copy the selection automatically, on selection change, then you don't need to restore it for the user to select a "Copy" menu. I would also block the updates for the duration of active selection (mouse down state), or else this is turning into a game: try to select XXX while I am changing text around :) – Vlad Feinstein Dec 11 '15 at 16:45

0 Answers0