Click to See Complete Forum and Search --> : help with CString


Danielle Harvey
April 21st, 1999, 11:58 AM
I copied code which creates a masked edit control. To return the time in a string rather than a COleDateTime object, the author says to use

CString string = m_editCtrl.GetTimeStr();

When I then try the following code,

CClientDC cDC(this);
cDC.TextOut(10,10, string);

my program crashes at TextOut statement. What am I doing wrong? How can I convert this CString into just a char string that I can then print?

Any response any one can give me will be greatly appreciated.

lonewolf
April 21st, 1999, 01:00 PM
Not sure why your code isn't working. You may want to try using MessageBox(string) to take a look at the string before you use TextOut(). To convert a CString to a char string, I do the following:

char buff[80];
sprintf(buff,string);

Hope this helps. Best of luck.

- Mark Robison

April 21st, 1999, 01:05 PM
What is the nature of the crash? Do you get an error message?

The m_editCtrl seems like something that would be on a dialog. CDC::TextOut()
is something you would ordinarily use in a user draw window. Normally you
would not be making a CClientDC using "this" from a dialog, but from the window
you are actually going to draw in.