获取可编辑框内值
CString str;
GetDlgItemText(IDC_COMBO_BOARDID,str);
MessageBox(str);
MFC-TXT文件-创建文件+写入数据+读取数据
写入txt
CString pszFileName=filePath+"RubberFile.txt";
CStdioFile myFile;
CFileException fileException;
if(myFile.Open(pszFileName,CFile::typeText|CFile::modeCreate|CFile::modeReadWrite),&fileException)
{
CString strOrder;
strOrder.Format("%.4f,%.4f",tempVariables.RingRadius.D(),tempVariables.RubberRadius.D());
myFile.WriteString(strOrder);
}
else
{
TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause);
}
myFile.Close();
读取txt
if(myFile.Open(pszFileName,CFile::typeText|CFile::modeReadWrite),&fileException)
{
myFile.SeekToBegin();
CString str1;
myFile.ReadString(str1);
AfxMessageBox(str1);
}
else
{
TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause);
}
myFile.Close();
编辑框输入值-获取
CString pass;
GetDlgItemText(IDC_PASSWORD,pass);
参数保存和参数读取-结构体方式
typedef struct
{
int a;
int b;
float c;
}param_struct;
param_struct m_Param;
CString CCoolProgram::GetModuleDir()
{
HMODULE module = GetModuleHandle(0);
WCHAR pFileName[MAX_PATH];
GetModuleFileName(module, pFileName, MAX_PATH);
CString csFullPath(pFileName);
int nPos = csFullPath.ReverseFind( _T('\\') );
csFullPath = csFullPath.Left( nPos );
csFullPath += _T("\\Data\\");
return csFullPath;
}
CString m_Path;
m_Path = GetModuleDir();
void SaveParam()
{
CFile File;
CFileFind ff;
CString strFileName;
strFileName = g_pMainDlg->m_Path + L"Params.data";
if( ff.FindFile( strFileName ) == FALSE )
{
AfxMessageBox(L"参数文件 Params.data 找不到,系统将新建参数文件");
}
if( File.Open( strFileName, CFile::modeCreate | CFile::modeWrite ) )
{
File.Write( &g_pMainDlg->m_Param, sizeof( param_struct ) );
File.Close();
}
}
****************************************
SaveRadio(filePath + "Radio.data");
****************************************
LoadRadio(filePath + "Radio.data");
***********************************************
void LoadParam()
{
CFile File;
CFileFind ff;
CString strFileName;
strFileName = g_pMainDlg->m_Path + L"Params.data";
if ( ff.FindFile(strFileName) )
{
if (File.Open( strFileName,CFile::modeRead))
{
File.Read( &g_pMainDlg->m_Param, sizeof( param_struct ) );
File.Close();
}
else
{
AfxMessageBox(L"打开参数文件 Params.data 失败");
}
}
else
{
AfxMessageBox(L"参数文件 Params.data 找不到,系统将新建参数文件,软件启动后请重新设置参数");
if( File.Open( strFileName, CFile::modeCreate | CFile::modeWrite ) )
{
File.Write( &g_pMainDlg->m_Param, sizeof( param_struct ) );
File.Close();
}
}
}
MFC-改变焦点
GetDlgItem(IDC_EDIT_CURFLAW)->SetFocus();
MFC-路径-获得exe文件所在路径
TCHAR buf[256]={0};
DWORD dwResult = GetModuleFileName(AfxGetApp()->m_hInstance,buf,256);
CString exePath = buf;
exePath = exePath.Left(exePath.ReverseFind('\\'));
AfxMessageBox(exePath);
MFC-文件-遍历
void CfileTestDlg::BayesCategoryTest(CString &dir)
{
CFileFind fileFinder;
if(dir.Right(1)!="\\")
dir +="\\";
CString filePath = dir + _T("*.*");
BOOL bFinished = fileFinder.FindFile(filePath);该函数返回值非0 还有符合条件的文件, 0表示是最后一个文件。
while(bFinished)
{
bFinished = fileFinder.FindNextFile();
if(!fileFinder.IsDirectory() && (!fileFinder.IsDots()))
{
CString fileName = fileFinder.GetFileName();
int dotPos=fileName.ReverseFind('.');
CString fileExt=fileName.Right(fileName.GetLength()-dotPos);
if(fileExt == ".bmp")
{
CString category = fileName.Left(fileName.GetLength()-8);
}
}
else if(fileFinder.IsDirectory() && (!fileFinder.IsDots()))
{
BayesCategoryTest(fileFinder.GetFilePath(),vec);
}
}
fileFinder.Close();
}
MFC-文件夹-创建
CString m_strFolderPath="c:\\test"
if (!PathIsDirectory(m_strFolderPath) )
{
CString strMsg;
strMsg.Format ("指定路径\"%s\"不存在,是否创建?", m_strFolderPath);
if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
{
if (!CreateDirectory(m_strFolderPath, NULL ) )
{
strMsg.Format ("创建路径\"%s\"失败!是否继续?", m_strFolderPath);
if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
return;
}
}
}
MFC-文件夹-删除一个文件夹下的所有内容
void DeleteDirectoryNoEmpty(CString directory_path)
{
CFileFind finder;
CString path;
path.Format("%s\\*.*", directory_path);
BOOL bWorking = finder.FindFile(path);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDirectory() && !finder.IsDots())
{
DeleteDirectoryNoEmpty(finder.GetFilePath());
RemoveDirectory(finder.GetFilePath());
}
else
{
AfxMessageBox(finder.GetFileName());
if (finder.GetFileName() != "." && finder.GetFileName() != "..")
{
DeleteFile((HTuple)(finder.GetFilePath()));
}
}
}
}
MFC-下拉框-当前显示
GetBoardInfoToCombobox("空");
GetBoardInfoToCombobox(str_board_id);
****************************************
void CRubberDetectionDlg::GetBoardInfoToCombobox(CString currentBoardID)
{
m_CComboBox_boardInfo.ResetContent();
m_CComboBox_boardInfo.AddString("空");
CString filePath = exePath + "\\BoardInfomation\\";
filePath = filePath + "*.*";
CFileFind fileFinder;
BOOL bFinished = fileFinder.FindFile(filePath);
while (bFinished)
{
bFinished = fileFinder.FindNextFile();
CString fileName = fileFinder.GetFileName();
if (bFinished != 0 || fileFinder.GetFileName().Right(fileName.GetLength() - fileFinder.GetFileName().ReverseFind('.')))
{
if (fileFinder.IsDirectory() && (!fileFinder.IsDots()))
{
CString boardName = fileFinder.GetFileName();
int judge_tf = m_CComboBox_boardInfo.AddString(boardName);
if ((judge_tf == CB_ERR) || (judge_tf == CB_ERRSPACE))
MessageBox(_T("File ID error!"));
if (currentBoardID == boardName)
{
m_CCombBox_CStringBoardIndex = (byte)judge_tf;
}
else if (boardName == "空")
{
m_CCombBox_CStringBoardIndex = 0;
}
}
}
}
m_CComboBox_boardInfo.SetCurSel(m_CCombBox_CStringBoardIndex);
GetDlgItem(IDC_EDIT_CURFLAW)->SetFocus();
UpdateData(FALSE);
}
windows查看进程内存使用记录
“性能监视器”——
1.windows自带的工具C:\Windows\System32\perfmon.exe
2.在绘制区域右击点击“添加计数器”
3.选择“Process”中的“working Set”
4.在“选定对象的实例”中选择自己要观察的进程“XXX”
5.点击“添加”,然后确定
|