Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

CEdit::GetSel - I have an MBCS application that seems to be reporting position in wide chars not bytes

$
0
0

How does CEdit determine its internal behavior from the containing application? Is it at creation time, in which case IsWindowUnicode returning false would suggest it should return position in BYTES not wchar_t as I understand it.

I am maintaining a large legacy application build using MBCS. On a system with Japanese as the system locale I have an issue where the selection position of an edit control is being returned incorrectly.

Code Snippet
          • CEditpEdit = state->GetEdit() ;
        • auto hWnd = pEdit->GetSafeHwnd() ;
        • if ( hWnd )
      • {
      •     ::SendMessageA(hWndEM_GETSEL, (WPARAM)&nStart, (LPARAM)&nEnd) ;
    •     TCHAR buffer[128];
    •     ::SendMessageA(hWndWM_GETTEXT, (WPARAM)_countof(buffer), (LPARAM)&buffer);
  1.     _RPT4(_CRT_WARN"String '%s' selection [%d,%d], unicode? %s",buffernStartnEnd, (::IsWindowUnicode(hWnd)) ? "True" : "False");
  2. }
  3. With the Carat at the end of the string this produces the output

    String '未定義' selection [3,3], unicode? False

    What on earth can be going on?

    I have built a little test application and that works as I would expect producing the output

    String '未定義' selection [6,6], unicode? False




    Viewing all articles
    Browse latest Browse all 15302

    Latest Images

    Trending Articles



    Latest Images

    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>