Help with OnDraw Fn

nutty boy's Avatar, Join Date: Apr 2007
Light Poster
Hi Guys
I wrore a simple VC "single document" interface program with MS VS_2005
when i wrote the following code

Code:
void CFirstView::OnDraw(CDC* pDC)
{
	CFirstDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
      CString hello_string="Hi This is my 1st Document View";
	// TODO: add draw code for native data here
	pDC->TextOutW(0,0,hello_string,hello_string.GetLength());
	
}
and copiled my program i get the error message below

Code:
c:\documents and settings\falcon eyes\my documents\visual studio 2005\projects\first\first\firstview.cpp(54) 
:error C2440:'initializing' : cannot convert from 'const char [32]' to 'ATL::CStringT<BaseType,StringTraits>'
1>with
1>[
1>BaseType=wchar_t,
1>StringTraits=StrTraitMFC_DLL<wchar_t>
1>]
1>Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1>with
1>[
1>BaseType=wchar_t,
1>StringTraits=StrTraitMFC_DLL<wchar_t>
does any one know why i'm getting an error message and what's the solution

Last edited by shabbir; 15Apr2007 at 08:34.. Reason: Code formating.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You need to be providing the TCHAR

There are 2 way to get out of it.
1. Have the hello_string declared as TCHAR array
2. Instead of passing the CString use the GetBuffer function to have the char array and then after the function returns use the ReleaseBuffer.
0
nutty boy's Avatar, Join Date: Apr 2007
Light Poster
Hi shabbir
1st thanks for ur reply 2nd could u please give me more details
what u mean by TCHAR array if u have any document about that or any usefull websites link

and how can i declare my string as TCHAR array

alsow

could u pls write the code for how to pass a string using the GetBuffer
Forgiveme i'm still learning how to program
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
TCHAR is nothing but declaring char array. Something Like TCHAR *str ="Your string"; or even TCHAR str[] ="Your String";

For GetBuffer it should be something like
Code:
CString hello_string="Hi This is my 1st Document View";
pDC->TextOutW(0,0,hello_string.GetBuffer(),hello_string.GetLength()  );
hello_string.ReleaseBuffer();
I thought I was clear enough with the above post and so not gave any example.
0
nutty boy's Avatar, Join Date: Apr 2007
Light Poster
thanks for concern
0
nutty boy's Avatar, Join Date: Apr 2007
Light Poster
Pls shabbir
when i wrote the code

TCHAR hello_string="Hi This is my 1st Document View";
// TODO: add draw code for native data here
pDC->TextOutW(0,0,hello_string,32);
I got this error message

error C2440: 'initializing' : cannot convert from 'const char [32]' to 'TCHAR'
is there's some wrong i did
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try making the TCHAR const or as of now you can go for something like const char as well because you dont need to confuse what is T there.
0
nutty boy's Avatar, Join Date: Apr 2007
Light Poster
I changed the properties of my project as below
General -> charcter set -> not set
and i used TextOutA function and it works although there's warnning message
Thanks