Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code is
C++
CString  mytext = "Hello";
((CEdit *)  GetDlgItem(IDC_EDITTITLE7))->SetWindowText(mytext);
Posted
Updated 8-Apr-15 23:57pm
v3

The string "Hello" is an ANSI string. With Unicode builds, you must use a wide string by prefixing the string with the letter L. To be independant of the the Unicode setting, you can use the _T() macros which will set the prefix if necessary:
CString  mytext = _T("Hello");
 
Share this answer
 
Comments
CPallini 9-Apr-15 6:20am    
5.
Member 11482033 9-Apr-15 6:38am    
I tried your suggestion but I'm getting ..

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: ...diaformat Latest 30-12-2014\Debug\LipsTimeCodeApplication.exe
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winocc.cpp
Line: 245
Jochen Arndt 9-Apr-15 6:51am    
The line contains: ASSERT(::IsWindow(m_hWnd))

Possible reasons:
GetDlgItem(IDC_EDITTITLE7) returns NULL because there is no item with the passed ID or the control window has not been created (the CEdit class may exist but the window itself has not been created or creation failed).

So you should check first if the item exists:

CWnd *pWnd = GetDlgItem(IDC_EDITTITLE7);
ASSERT(pWnd);
if (pWnd)
pWnd->SetWindowText(mystring);

If you get now an assertion in your source file, the item does not exist.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900