|
我用vs2008建立的一个windows mobile 5.0单文档mfc程序
我是想从文件读入txt文件的字符串后,放到了一个cstring中,用drawtext输出显示到view中
下面是有关代码
//代码在一个按钮响应中,不在OnDraw中.
//获得文件路径
CFileDialog dlgFile(TRUE);
const int c_cMaxFiles = 100;
const int c_cbBuffSize = (c_cMaxFiles * (MAX_PATH + 1)) + 1;
dlgFile.GetOFN().lpstrFilter = _T("TXT File\0*.txt;\0ALL File\0*.*;\0");
dlgFile.GetOFN().lpstrFile = fileName.GetBuffer(c_cbBuffSize);
dlgFile.GetOFN().nMaxFile = c_cMaxFiles;
dlgFile.DoModal();
fileName.ReleaseBuffer();
CFile XMLFile;
char* buffer;
//打开文件
XMLFile.Open(fileName,CFile::modeReadWrite);
int nLen = XMLFile.GetLength();
buffer=new char[nLen+1];
buffer[nLen] = 0;
//读文件
XMLFile.Read(buffer,nLen);
//单字节转换成双字节
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, buffer, -1, NULL, 0);
wchar_t *pwText;
pwText = new wchar_t[dwNum];
if(!pwText)
{
delete []pwText;
}
MultiByteToWideChar (CP_ACP, 0, buffer, -1, pwText, dwNum);
//把pwText格式化到cstring对象中m_str
m_str.Format(_T("%s"), pwText);
delete []pwText;
//开始绘图
CDC* pDC = GetDC();
HDC hdc = pDC->GetSafeHdc();
RECT rect;
//得到客户区域
GetClientRect(&rect);
//这里设置断点后参数设定正常,返回n正常,但是屏幕不显示 为什么啊 ?大神们
int n = DrawText(hdc,m_str,-1,&rect,DT_CALCRECT);
//int n = ExtTextOut(hdc,0,0,ETO_OPAQUE,&rect,m_str,m_str.GetLength(),0);
|
|