void CvtkmfcDoc::OnFileOpen()
{
CString szFilters = _T("stl文档(*.stl)|*.stl|vtk文档(*.vtk)|*.vtk|所有文档(*.*)|*.*|");
CFileDialog OpenDlg(TRUE, _T("*.stl"),NULL, OFN_HIDEREADONLY, szFilters);
OpenDlg.m_ofn.lpstrTitle = (LPCTSTR) _T("Open File");
if (IDOK == OpenDlg.DoModal())
{
CString str;
CFile File;
CFileException e;
//构造文件,同时增加异常处理
if (!File.Open(OpenDlg.GetPathName(), CFile::modeRead, &e))
{
CString strErr;
strErr.Format(_T("File could not be opened %d\n"), e.m_cause);
}
str= OpenDlg.GetPathName();
char *strChar = (char*)str.GetBuffer(str.GetLength()+1);
str.ReleaseBuffer();
CString str1 ;
str1.Format(_T("%s"), strChar);
//CString suffixStr = str.substr(str.fin('.') + 1);//获取文件后缀
CMainFrame *pMain = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CvtkmfcView *pView = (CvtkmfcView *)pMain->GetActiveView();
SendMessage(pView->m_hWnd, WM_MSG3DSHowSTLMSG, WPARAM(str1.GetBuffer(str1.GetLength() + 1)), (LPARAM)(str1.GetBuffer(str1.GetLength() + 1)));
str1.ReleaseBuffer();
return;
}
{
CString szFilters = _T("stl文档(*.stl)|*.stl|vtk文档(*.vtk)|*.vtk|所有文档(*.*)|*.*|");
CFileDialog OpenDlg(TRUE, _T("*.stl"),NULL, OFN_HIDEREADONLY, szFilters);
OpenDlg.m_ofn.lpstrTitle = (LPCTSTR) _T("Open File");
if (IDOK == OpenDlg.DoModal())
{
CString str;
CFile File;
CFileException e;
//构造文件,同时增加异常处理
if (!File.Open(OpenDlg.GetPathName(), CFile::modeRead, &e))
{
CString strErr;
strErr.Format(_T("File could not be opened %d\n"), e.m_cause);
}
str= OpenDlg.GetPathName();
char *strChar = (char*)str.GetBuffer(str.GetLength()+1);
str.ReleaseBuffer();
CString str1 ;
str1.Format(_T("%s"), strChar);
//CString suffixStr = str.substr(str.fin('.') + 1);//获取文件后缀
CMainFrame *pMain = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CvtkmfcView *pView = (CvtkmfcView *)pMain->GetActiveView();
SendMessage(pView->m_hWnd, WM_MSG3DSHowSTLMSG, WPARAM(str1.GetBuffer(str1.GetLength() + 1)), (LPARAM)(str1.GetBuffer(str1.GetLength() + 1)));
str1.ReleaseBuffer();
return;
}
}
Cstring 转为String格式
LRESULT CvtkmfcView::On3DSTLResponseFunction(WPARAM wParam, LPARAM lParam)
{
CString str;
str.Format(_T("%s"), (CHAR*)wParam);
std::string path = CT2A(str);
//(LPCSTR)str.GetBuffer(str.GetLength());
readStllFunction(path);
return 0;
}