Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems posting text to edit box - need help.

Status
Not open for further replies.

pghTech

Technical User
Jul 19, 2006
37
US
I am attempting to post text to an edit box:

I created a class off of the main dialog window and was using the constructor to initialize the edit box with text:
Code:
public:
	CSnipitDlg(CWnd* pParent = NULL);   // standard constructor

Constructor:
Code:
CSnipitDlg::CSnipitDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSnipitDlg::IDD, pParent)
{
	CDialog::OnInitDialog();
	
	CWnd *Display;
	Display = GetDlgItem(IDC_APPNAME);

	Display->SetWindowTextW("Application Name");
	return;
}

I was under the impression I could call SetWindowTextW function of CWnd that would allow me to post the string. However, I am receiving the error:

Code:
"error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'const char [17]' to 'LPCTSTR'


Question 2:
If you needed to get the handle of a window, and you didn't know what it was, what is the correct method?

Thanks in advance.
 
1) Display->SetWindowTextW((LPCTSTR)"Application Name"); should do the trick.

2) You mean for the calling routine to pass to this routine? I think GetWindowLong can get it for you.
 
1) Display->SetWindowTextW((LPCTSTR)"Application Name"); should do the trick.

No it wont. LPCTSTR is either CHAR* or WCHAR* depending on UNICODE define, while "Application Name" is only a CHAR[17].

Code:
Display->SetWindowTextW(L"Application Name");

this will work, because SetWindowTextW is the unicode version of the function, so you must provide a unicode string for it.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top