📄 fileview.cpp
字号:
this->m_filetree.m_ImageList.Add(&temp_map,0x000000ff);
this->m_filetree.m_ImageList.GetImageCount();
}
if(temp_map1.LoadBitmap(IDR_BMP_OFF))
{
this->m_filetree.m_ImageList.Add(&temp_map1,0x00000001);
this->m_filetree.m_ImageList.GetImageCount();
}
}
void CFileView::OnMarkOn()
{
// TODO: Add your command handler code here
this->m_finishtxt.Add(this->m_filetree.GetItemText(this->m_filetree.GetSelectedItem()));
this->m_filetree.SetItemImage(this->m_filetree.GetSelectedItem(),0,0);
}
////这个程序是用来从目录配置文件中检查是否已阅状态的//////
bool CFileView::checkstate(CString itemname)
{
int i=0,counts;
counts=this->m_finishtxt.GetSize();
while(i<counts)
{
if(this->m_finishtxt.GetAt(i)==itemname)
return TRUE;
i++;
}
return FALSE;
}
void CFileView::OnMarkOff()
{
// TODO: Add your command handler code here
int i=0,counts;
counts=this->m_finishtxt.GetSize();
while(i<counts)
{
if(this->m_finishtxt.GetAt(i)==this->m_filetree.GetItemText(this->m_filetree.GetSelectedItem()))
{
this->m_finishtxt.RemoveAt(i,1);
this->m_filetree.SetItemImage(this->m_filetree.GetSelectedItem(),1,1);
return;
}
i++;
}
}
void CFileView::OnUpdateMarkOff(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(!this->checkstate(this->m_filetree.GetItemText(this->m_filetree.GetSelectedItem())))
pCmdUI->Enable(FALSE);
}
void CFileView::OnUpdateMarkOn(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(this->checkstate(this->m_filetree.GetItemText(this->m_filetree.GetSelectedItem())))
pCmdUI->Enable(FALSE);
}
void CFileView::OnDeletefile()
{
// TODO: Add your command handler code here
HANDLE filehandle;
WIN32_FIND_DATA finddata;
CString filepath;
filepath=this->CacuCurrentFilePath();
filehandle=::FindFirstFile(filepath,&finddata);
if(filehandle!=INVALID_HANDLE_VALUE)
{
CString msg,msg2;
msg="删除文件:"+filepath;
msg2="确认"+msg;
msg2+="?";
if(::AfxMessageBox(msg2,MB_YESNO,0)==IDYES)
{
if(::DeleteFile(filepath))
{
msg+="成功!";
::AfxMessageBox(msg);
}
else
::AfxMessageBox("不能删除该文件!");
}
this->SetTree();
}
}
CString CFileView::CacuCurrentFilePath()
{
CString Pathstr,filepath;
Pathstr=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
filepath=Pathstr+this->m_filetree.GetItemText(this->m_filetree.GetSelectedItem());
filepath+=".txt";
return filepath;
}
void CFileView::OnNoteopen()
{
// TODO: Add your command handler code here
CString filepath;
filepath=this->CacuCurrentFilePath();
HINSTANCE m_instance;
//::ShellExecute(this->m_hWnd, "open","notepad.exe", NULL, NULL, SW_SHOWNORMAL);
if(((int)(m_instance=::ShellExecute(this->m_hWnd, "open",filepath, NULL, NULL, SW_SHOWNORMAL)))<=32)
{
::AfxMessageBox("有错误发生!");
}
}
void CFileView::OnClick2open(void)
{
CFileDlg m_filedlg;
HINSTANCE m_instance;
if(m_filedlg.DoModal()==IDOK)
{
if(m_filedlg.m_selfilepath!="")
{
if(((int)(m_instance=::ShellExecute(this->m_hWnd, "open",m_filedlg.m_selfilepath, NULL, NULL, SW_SHOWNORMAL)))<=32)
{
::AfxMessageBox("有错误发生!");
}
}
else
::AfxMessageBox("你没有选择任何文件!");
}
}
void CFileView::OnRefreshme()
{
// TODO: Add your command handler code here
this->SetTree();
}
void CFileView::OnNotepad()
{
// TODO: Add your command handler code here
HINSTANCE m_instance;
if(((int)(m_instance=::ShellExecute(this->m_hWnd, "open","notepad.exe", NULL, NULL, SW_SHOWNORMAL)))<=32)
{
::AfxMessageBox("有错误发生!");
}
}
void CFileView::OnNewfile()
{
// TODO: Add your command handler code here
CNewTextDlg m_dlg;
HANDLE thandle;
LPSTR lpszData;
::OpenClipboard(NULL);
if(FALSE==::IsClipboardFormatAvailable(CF_TEXT))
{
m_dlg.m_title="点击这里输入文本标题";
m_dlg.m_text="点击这里输入文本正文";
}
else
{
m_dlg.m_title="点击这里输入文本标题";
thandle=::GetClipboardData(CF_TEXT);
lpszData = (LPSTR)GlobalLock(thandle);
CString str(lpszData);
m_dlg.m_text=str;
GlobalUnlock(thandle);
}
::CloseClipboard();
if(m_dlg.DoModal()==IDOK)
{
CString path,filename;
//CStringList * m_pSl=&(((CTipReaderApp *)::AfxGetApp())->m_config.m_pathlist);
//path=m_pSl->GetAt(m_pSl->FindIndex());
path=m_dlg.m_dirstr;
filename=path+m_dlg.m_title+".txt";
CFile m_file;
if(!m_file.Open(filename,CFile::modeCreate,NULL))
{
::AfxMessageBox("建立文件失败!");
return;
}
m_file.Close();
if(m_file.Open(filename,CFile::modeWrite,NULL))
{
CArchive ar(&m_file,CArchive::store,4096,NULL);
ar.WriteString(m_dlg.m_text);
}
else
::AfxMessageBox("写文件失败!");
m_file.Close();
this->SetTree();
}
}
void CFileView::FillComboBox()
{
int length,i;
CStringList * m_pSl=&(((CTipReaderApp *)::AfxGetApp())->m_config.m_pathlist);
length=m_pSl->GetCount();
for(i=0;i<length;i++)
{
this->m_combobox.AddString(m_pSl->GetAt(m_pSl->FindIndex(i)));
}
this->m_combobox.SetCurSel(this->m_combobox.FindString(-1,((CTipReaderApp *)::AfxGetApp())->m_config.m_path));
}
void CFileView::OnClick2sel()
{
CEditView *pEditView;
CString str,str2;
this->m_combobox.GetLBText(this->m_combobox.GetCurSel(),str);
((CTipReaderApp *)::AfxGetApp())->m_config.m_path=str;
((CTipReaderApp *)::AfxGetApp())->m_config.m_filename="NULL";
pEditView=(CEditView *) ((CSplitterWnd *)(this->GetParent()))->GetPane(0,1);
pEditView->GetEditCtrl().GetWindowText(str2);
pEditView->GetEditCtrl().SetSel(0,str2.GetLength());
pEditView->GetEditCtrl().Clear();
this->m_filetree.SetNULL();
this->SetTree();
}
void CFileView::OnCreatebewfolder()
{
// TODO: Add your command handler code here
CNewFolderDlg dlg;
CString newfolderpath;
dlg.defaultpath=CaCupath();
if(IDOK==dlg.DoModal())
{
newfolderpath=dlg.defaultpath+"\\";
if(((CTipReaderApp *)::AfxGetApp())->m_config.InsertPath(newfolderpath)==TRUE)
this->m_combobox.AddString(newfolderpath);
this->m_combobox.SetCurSel(this->m_combobox.FindString(-1,newfolderpath));
this->OnClick2sel();
}
}
CString CaCupath()
{
CString tempstr,tempstr2;
tempstr=::AfxGetApp()->m_pszHelpFilePath;
tempstr2=::AfxGetApp()->m_pszExeName;
tempstr2+=".HLP";
tempstr=tempstr.Left(tempstr.GetLength()-tempstr2.GetLength());
tempstr.TrimRight('\\');
tempstr=tempstr.Left(tempstr.ReverseFind('\\')+1);
if(tempstr.Right(1)!="\\")
tempstr+="\\";
return tempstr;
}
void CFileView::OnRemovepath()
{
// TODO: Add your command handler code here
CTipReaderApp * pApp=(CTipReaderApp *)::AfxGetApp();
pApp->m_config.RemovePath(pApp->m_config.m_path);
this->m_combobox.DeleteString(this->m_combobox.GetCurSel());
if(this->m_combobox.GetCount()>=1)
{
this->m_combobox.SetCurSel(0);
this->OnClick2sel();
}
}
void CFileView::OnUpdateRemovepath(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(this->m_combobox.GetCount()==0)
{
pCmdUI->Enable(FALSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -