Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Help with OnDraw Fn (http://www.go4expert.com/forums/help-ondraw-fn-t3869/)

nutty boy 15Apr2007 03:34

Help with OnDraw Fn
 
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

shabbir 15Apr2007 08:36

Re: Help with OnDraw Fn
 
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.

nutty boy 16Apr2007 01:46

Re: Help with OnDraw Fn
 
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

shabbir 16Apr2007 06:10

Re: Help with OnDraw Fn
 
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.

nutty boy 17Apr2007 02:11

Re: Help with OnDraw Fn
 
thanks for concern

nutty boy 17Apr2007 02:30

Re: Help with OnDraw Fn
 
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

shabbir 17Apr2007 06:17

Re: Help with OnDraw Fn
 
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.

nutty boy 19Apr2007 05:35

Re: Help with OnDraw Fn
 
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


All times are GMT +5.5. The time now is 16:20.