0

I have some code which strips out illegal characters from a user entered string upon the ON_EN_CHANGE call. So need to correct the curser position if any are removed.

To do so I have been attempting to use GetSel to retrieve the position, then setsel to set it as below. f is another int variable.

m_ExportDirectory.GetWindowTextA(directory);
//characters removed here
if (rem > 0) 
{
    int j;
    m_ExportDefaultName.GetSel(f, j);
    m_ExportDirectory.SetWindowTextA(directory);
    m_ExportDefaultName.SetSel(f-rem, f-rem);
}

But getsel always sets both f & j to 0. I have attempted moving its call to above the GetWindowText but with no change.

Am I doing something stupid? If not Any ideas?

Thanks

Hector
  • 1,052
  • 2
  • 8
  • 25
  • 1
    Are you calling `GetSel`/`SetSel` on another object than `SetWindowTextA` on purpose? It seems that's not what you wanted to do. – IInspectable Jul 23 '13 at 09:51
  • Ok.. I can't believe that I missed that. Tunnel vision I guess. Thanks, I'll give that a try – Hector Jul 23 '13 at 10:12

2 Answers2

1

I think the problem is that GetSel() returns the selection start and end position. You get (0,0) because no text is selected by the user.

tomi.lee.jones
  • 1,503
  • 1
  • 15
  • 20
  • According to this answer http://stackoverflow.com/questions/92671/how-do-i-reserve-caret-position-in-cedit-control It should work. There are also several other sources around the internet saying the same thing. – Hector Jul 22 '13 at 13:05
  • 1
    I 've checked that with simple program and indeed, it works. It's really hard to deduce why it is not working in your case basing on the piece of code you provided. Many times it comes down to just some type of flag not being set in the control. – tomi.lee.jones Jul 22 '13 at 15:48
0

Solved By Tims comment. Appears the issue was tiredness and stupidity on my part!

Hector
  • 1,052
  • 2
  • 8
  • 25