SetDlgItemTextW problem
-
I am using VC++ and want to display UNICODE String on a Dialog box Doing it like this : CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf); and HWND hWnd is declared in .h File The problem is even though code compiles fine but nothing gets displayed.
Suneet.03 wrote:
CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf);
CString
,strcpy()
are not handling unicode... useCStringW
andwcscpy_s()
instead, and of course, when using literals, type them with a prepending**L**
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
CString str=_T("name"); SetDlgItemText(IDC_BTN_RESET,str);
works fine :) does that solve it?sonsam wrote:
CString str=_T("name");
no. this instead :
CString str = L"Name";
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I guess UNICODE is not defined else
Suneet.03 wrote:
CString str="Name";
will not compile.
spsharma wrote:
CString str="Name"; will not compile
:confused: sure it will, and it does ! but it doesn't work properly if UNICODE and _UNICODE are not defined...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
spsharma wrote:
CString str="Name"; will not compile
:confused: sure it will, and it does ! but it doesn't work properly if UNICODE and _UNICODE are not defined...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Suneet.03 wrote:
CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf);
CString
,strcpy()
are not handling unicode... useCStringW
andwcscpy_s()
instead, and of course, when using literals, type them with a prepending**L**
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
The data is not Unicode until the call to
mbstowcs(...)
at which pointbuf
(a Unicode/wide character buffer) should contain Unicode data. At that point, theCString
andstrcpy(...)
are no longer involved. Most ANSI/MBCS applications are capable of handling Unicode data and vice-versa simpy by using/omitting theL
prefix on strings to indicate a wide/narrow string and using the appropriateW
/A
suffix on the Win32 API. Your application configuration (UNICODE
#define
d or not) mostly indicates the default character width and version of the Win32 API to link with. There is something else going on... Peace! -- modified at 7:49 Monday 16th July, 2007 (Posted before complete...)-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
I am using VC++ and want to display UNICODE String on a Dialog box Doing it like this : CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf); and HWND hWnd is declared in .h File The problem is even though code compiles fine but nothing gets displayed.
Assuming that
pc_char
is a suitablechar
buffer, the conversion to Unicode looks OK from here. I would try a few things... 1: Remove theCString
usage - it is not necessary and only adds time and another point for exception handling.LPCTSTR pcData = "Name";
wchar_t wcaBuf[255];::mbstowcs( wcaBuf, cpData, ::_tcslen( cpData ) );
::SetDlgItemTextW( hWnd, IDC_VIEW , wcaBuf );
// HWND hWndView = ::GetDlgItem( hWnd, IDC_VIEW ); //::SetWindowTextW( hWndView, wcaBuf );
2: Make sure that the conversion to Unicode was successful by checking the return value from
mbstowcs(...)
3: Check the return value ofSetDlgItemTextW(...)
, and maybe try usingSetWindowTextW(...)
by first obtaining theHWND
of theIDC_VIEW
control. 4: This may be a stupid question, but are you sure thatIDC_VIEW
is a "text-able" control (edit, button, static/label, drop-list combobox)? Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
I am using VC++ and want to display UNICODE String on a Dialog box Doing it like this : CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf); and HWND hWnd is declared in .h File The problem is even though code compiles fine but nothing gets displayed.
Wow. Alot of discussion and 1-voting on this thread :) Isn't this sufficient? CStringW str=L"Name"; SetDlgItemTextW(hWnd,IDC_VIEW,str);
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
I am using VC++ and want to display UNICODE String on a Dialog box Doing it like this : CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf); and HWND hWnd is declared in .h File The problem is even though code compiles fine but nothing gets displayed.
or this CStringW str("Name"); SetDlgItemTextW(hWnd,IDC_VIEW,str);
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
or this CStringW str("Name"); SetDlgItemTextW(hWnd,IDC_VIEW,str);
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
Or this:
SetDlgItemTextW( hWnd, IDC_VIEW, L"Name" );
:P Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Or this:
SetDlgItemTextW( hWnd, IDC_VIEW, L"Name" );
:P Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles:doh: ;P
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
I am using VC++ and want to display UNICODE String on a Dialog box Doing it like this : CString str="Name"; wchar_t buf[255]; strcpy(pc_char1,str); mbstowcs(buf,pc_char1,str.GetLength()+1); SetDlgItemTextW(hWnd,IDC_VIEW,buf); and HWND hWnd is declared in .h File The problem is even though code compiles fine but nothing gets displayed.