1. 文件操作
文件操作主要使用CFileFind类,声明对象后使用函数FindFile加上搜索文件夹得地址和文件类型,最后通过函数FindNextFileW()函数递推文件夹下的文件,使用GetFileName();函数得到文件的名字,其中还有关于Combox的操作和CString的操作也很有用。
2. CEdit的操作
// TODO: 在此添加控件通知处理程序代码 UpdateData(TRUE); CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT13);
if(m_FileCheck) { pEdit-> SetReadOnly(FALSE); pEdit->SetFocus(); //光标定位到该控件中 pEdit->SetSel(0,m_FileName.GetLength());//选中,从零到字符长度 }else { pEdit-> SetReadOnly(TRUE); FlushFile(); } UpdateData(FALSE);
在使用CEdit控件之后才能SetReadOnly()函数,动态改变编辑状态。
3. CListBox操作
m_list.ResetContent(); //清空list
//add items CString Step=_T(""); CString strConfigPath = FilesPath(m_FileName); int num = GetPrivateProfileInt(_T("NUM"),_T("num"),0,strConfigPath.GetBuffer(strConfigPath.GetLength())); for(int i = 0; i < num; i++) { Step.Format(_T("Step%d"),i+1); m_list.AddString(Step);// 向list中增加条目 } m_list.SendMessage(WM_VSCROLL,SB_PAGEDOWN,0); //将list中的条目定位到底部
操作注释很详细,其中GetPrivateProfileInt()很有意思,为在文件中找到指定条目的值
写的话是 ::WritePrivateProfileString(Step,_T("R4"),R4_Value,FAdress);
4. 在线程中使用UpdateData()函数
通过发送消息:pThis->SendMessage(WM_UPDATEDATA, TRUE);
需要做的准备在头文件中添加
#define WM_UPDATEDATA WM_USER + 5
LRESULT OnUpdateData(WPARAM wParam, LPARAM lParam); //消息函数声明
在主文件主添加消息映射
BEGIN_MESSAGE_MAP(CArmControlDlg, CDialog)
ON_MESSAGE(WM_UPDATEDATA, OnUpdateData)
END_MESSAGE_MAP()
这也是自己添加消息响应函数的模板。
5. 键盘响应函数
重载 CDialog::PreTranslateMessage(pMsg);
BOOL CArmControlDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message ==WM_KEYDOWN) { int nVirtKey = (int)pMsg->wParam; if (nVirtKey==VK_RETURN) { flag_order = 1;
return TRUE; }else if(nVirtKey==VK_A) { MoveType = LEFT; return TRUE; }
return CDialog::PreTranslateMessage(pMsg);
}
其中在头文件中的声明为虚函数
virtual BOOL PreTranslateMessage(MSG* pMsg);