Help with OnDraw Fn

Light Poster
15Apr2007,03:34   #1
nutty boy's Avatar
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.
Go4Expert Founder
15Apr2007,08:36   #2
shabbir's Avatar
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.
Light Poster
16Apr2007,01:46   #3
nutty boy's Avatar
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
Go4Expert Founder
16Apr2007,06:10   #4
shabbir's Avatar
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.
Light Poster
17Apr2007,02:11   #5
nutty boy's Avatar
thanks for concern
Light Poster
17Apr2007,02:30   #6
nutty boy's Avatar
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
Go4Expert Founder
17Apr2007,06:17   #7
shabbir's Avatar
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.
Light Poster
19Apr2007,05:35   #8
nutty boy's Avatar
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