📄 mainfrm.cpp
字号:
}
CHARRANGE cr;
edit.GetSel(cr);
icrEditView->SetParseCookieZeroFromGivenLine(edit.LineFromChar(cr.cpMin)); //粘贴时需重置解析缓冲区
edit.ReplaceSel(str, TRUE);
if(cr.cpMax != cr.cpMin)
{
icrEditView->ReCalcCursorPostion();
}
}
void CMainFrame::OnEditSelectall()
{
// TODO: Add your command handler code here
CCodeManagerView *icrEditView = (CCodeManagerView *)GetActiveView();
CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
CWnd *pWnd = GetFocus();
if(pWnd->m_hWnd != editctrl.m_hWnd)
{
CString str;
pWnd->GetWindowText(str);
CHARRANGE ichCharRange;
ichCharRange.cpMax = str.GetLength();
ichCharRange.cpMin = 0;
pWnd->SendMessage(EM_EXSETSEL, 0, (LPARAM)&ichCharRange);
return;
}
editctrl.SetSel(0, -1);
editctrl.SetFocus();
editctrl.PostMessage( WM_PAINT, 0, 0 );
}
void CMainFrame::OnEditfind()
{
// TODO: Add your command handler code here
if(!m_pFindDialog)
m_pFindDialog = new CFind(this);
else
{
m_pFindDialog->ShowWindow(SW_SHOW);
m_pFindDialog->SetFocus();
return;
}
m_pFindDialog->Create(IDD_FIND, this);
m_pFindDialog->ShowWindow(SW_SHOW);
return;
}
void CMainFrame::OnEditrepeat()
{
// TODO: Add your command handler code here
/* CWinApp *app = AfxGetApp();
CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
CCodeManagerView *icrEditView=(CCodeManagerView *)GetActiveView();
CString strEdit;
mainfrm->m_wndToolBar.m_comboboxFind.GetWindowText(strEdit);
//CString strEdit = app->GetProfileString(_T("CFind"), _T("str"), _T(""));
BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
if(strEdit.IsEmpty())
return;
int dwFlags = 0;
if(bCase)
dwFlags|=FR_MATCHCASE;
if(bWholeWord)
dwFlags|=FR_WHOLEWORD;
CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
CHARRANGE cr;
edit.GetSel(cr);
FINDTEXTEX *ft = new FINDTEXTEX[1];
ft->chrg.cpMin = cr.cpMin-1;
ft->chrg.cpMax = -1;// search through end of the text
TCHAR *t = new TCHAR[strEdit.GetLength()+1];
strcpy(t, strEdit);
ft->lpstrText = t;
mainfrm->m_wndToolBar.m_comboboxFind.AddToMRU(strEdit);
app->WriteProfileString(_T("CFind"), _T("str"), strEdit);
icrEditView->ShowWindow(SW_HIDE);
int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
if(nPos!=-1) {
edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
icrEditView->SetFocus();
SetFocus();
icrEditView->ShowWindow(SW_SHOW);
}
else {
icrEditView->ShowWindow(SW_SHOW);
CString strShow;
strShow.Format(_T("Cannot find the string: \"%s\", search again from the end?"), strEdit);
if(MessageBox(strShow,_T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
{
icrEditView->ShowWindow(SW_HIDE);
edit.SetSel(0, -1);
icrEditView->ShowWindow(SW_SHOW);
CHARRANGE cr;
edit.GetSel(cr);
edit.SetSel(cr.cpMax, cr.cpMax);
OnEditrepeat();
if(t)
delete t;
if(ft)
delete ft;
return;
}
}
if(t)
delete t;
if(ft)
delete ft; */
}
void CMainFrame::OnEditrepeatnext()
{
// TODO: Add your command handler code here
/* CWinApp *app = AfxGetApp();
CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
CIcrEditView *icrEditView=(CIcrEditView *)GetActiveView();
CString strEdit;
mainfrm->m_wndToolBar.m_comboboxFind.GetWindowText(strEdit);
//CString strEdit = app->GetProfileString(_T("CFind"), _T("str"), _T(""));
BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
if(strEdit.IsEmpty())
return;
int dwFlags = 0;
if(bCase)
dwFlags|=FR_MATCHCASE;
if(bWholeWord)
dwFlags|=FR_WHOLEWORD;
dwFlags|=FR_DOWN;;
CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
CHARRANGE cr;
edit.GetSel(cr);
FINDTEXTEX *ft = new FINDTEXTEX[1];
ft->chrg.cpMin = cr.cpMin+1;
ft->chrg.cpMax = -1;// search through end of the text
TCHAR *t = new TCHAR[strEdit.GetLength()+1];
strcpy(t, strEdit);
ft->lpstrText = t;
mainfrm->m_wndToolBar.m_comboboxFind.AddToMRU(strEdit);
app->WriteProfileString(_T("CFind"), _T("str"), strEdit);
icrEditView->ShowWindow(SW_HIDE);
int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
if(nPos!=-1) {
edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
icrEditView->SetFocus();
SetFocus();
icrEditView->ShowWindow(SW_SHOW);
}
else {
icrEditView->ShowWindow(SW_SHOW);
CString strShow;
strShow.Format(_T("Cannot find the string: \"%s\", search again from the beginning?"), strEdit);
if(MessageBox(strShow, _T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
{
edit.SetSel(0, 0);
OnEditrepeatnext();
if(t)
delete t;
if(ft)
delete ft;
return;
}
}
if(t)
delete t;
if(ft)
delete ft; */
}
void CMainFrame::OnEditselectall()
{
CCodeManagerView *icrEditView = (CCodeManagerView *)GetActiveView();
CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
CWnd *pWnd = GetFocus();
if(pWnd->m_hWnd != editctrl.m_hWnd)
{
CString str;
pWnd->GetWindowText(str);
CHARRANGE ichCharRange;
ichCharRange.cpMax = str.GetLength();
ichCharRange.cpMin = 0;
pWnd->SendMessage(EM_EXSETSEL, 0, (LPARAM)&ichCharRange);
return;
}
editctrl.SetSel(0, -1);
editctrl.SetFocus();
editctrl.PostMessage( WM_PAINT, 0, 0 );
}
void CMainFrame::OnEditreplace()
{
// TODO: Add your command handler code here
if(!m_pReplaceDialog)
m_pReplaceDialog = new CReplace(this);
else
{
m_pReplaceDialog->ShowWindow(SW_SHOW);
m_pReplaceDialog->SetFocus();
return;
}
m_pReplaceDialog->Create(IDD_REPLACE, this);
m_pReplaceDialog->ShowWindow(SW_SHOW);
return;
}
void CMainFrame::OnFileMysaveAs()
{
if(m_strFileName.IsEmpty())
{
CFileDialog fd(TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER|OFN_NOCHANGEDIR, "*.*|*.*||");
if(fd.DoModal()==IDCANCEL)
return;
m_strFileName = fd.GetPathName();
}
else
{
CString strFileName = m_strFileName;
int nPos= strFileName.ReverseFind('\\');
strFileName = strFileName.Right(strFileName.GetLength()-nPos-1);
CFileDialog fd(TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER|OFN_NOCHANGEDIR, "*.*|*.*||");
wsprintf(fd.m_ofn.lpstrFile, strFileName);
if(fd.DoModal()==IDCANCEL)
return;
m_strFileName = fd.GetPathName();
}
SaveContext();
}
void CMainFrame::OnViewFloat()
{
m_Fs = !m_Fs;
if(m_Fs)
dlg->ShowWindow(SW_SHOW);
else
dlg->ShowWindow(SW_HIDE);
}
void CMainFrame::OnUpdateViewFloat(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_Fs);
}
void CMainFrame::OnViewFont()
{
CCodeManagerView *icrEditView = (CCodeManagerView *)GetActiveView();
CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
BOOL bModify = edit.GetModify();
edit.ShowWindow(SW_HIDE);
CString strText;
EDITSTREAM stream;
stream.dwCookie = (DWORD)&strText;
stream.pfnCallback = EditStreamCallbackOut;
edit.StreamOut(SF_TEXT, stream);
CHARFORMAT cr;
if(strText.IsEmpty())
{
strText = _T(" ");
edit.SetSel(0, 1);
cr = icrEditView->GetCharFormatSelection();
edit.SetSel(0, 0);
}
else
{
CHARRANGE range;
edit.GetSel(range);
int ntemp;
if(range.cpMax < range.cpMin)
{
ntemp = range.cpMax;
range.cpMax = range.cpMin;
range.cpMin = ntemp;
}
if(range.cpMax == range.cpMin)
{
if(range.cpMin == 0)
{
edit.SetSel(0, 1);
}
else
{
edit.SetSel(range.cpMin-1, range.cpMin);
}
cr = icrEditView->GetCharFormatSelection();
edit.SetSel(range.cpMin, range.cpMin);
}
else
{
cr = icrEditView->GetCharFormatSelection();
}
}
edit.ShowWindow(SW_SHOW);
CFontDialog dlg(cr, CF_BOTH|CF_NOOEMFONTS);
if (dlg.DoModal() == IDOK)
{
CHARFORMAT cr;
dlg.GetCharFormat(cr);
LockWindowUpdate();
icrEditView->SetWindowText(_T(""));
icrEditView->SetSynEditViewFont(*dlg.m_cf.lpLogFont);
icrEditView->SetWindowText(strText);
edit.SetModify(bModify);
UnlockWindowUpdate();
}
}
LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
return m_tIcon.OnTrayNotification(wParam,lParam);
}
void CMainFrame::OnShow()
{
::SetForegroundWindow(this->m_hWnd);
if(IsIconic())
ShowWindow(SW_SHOWNORMAL);
}
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(wParam == SC_MINIMIZE)
{
if(m_bMini)
{
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
return 0;
}
}
if(wParam == SC_CLOSE)
m_bCloseRe = TRUE;
return CFrameWnd::WindowProc(message, wParam, lParam);
}
void CMainFrame::OnAppExit()
{
m_bCloseRe = FALSE;
SendMessage(WM_CLOSE);
}
int CMainFrame::SaveConfigure()
{//保存配置文件内容
CStdioFile f;
CFileException e;
try
{
if(f.Open("Configure.cig", CFile::modeWrite | CFile::modeCreate, &e)) //打开了一个文件
{
CString str,sstr;
str.Format("%d %d %d %d", m_bIcon, m_bMini, m_bClose, m_bStyle);
str += "\n";
f.WriteString(str);
str.Empty();
sstr.Empty();
for(int i = 0; i < m_nFileNum; i++)
{
str.Format("%s", NewFileExp[i]);
sstr += str;
sstr += ";";
}
sstr += "\n";
f.WriteString(sstr);
}
else
{
MessageBox("保存配置文件出错,请重试!");
return 1;
}
}
catch(CFileException e)
{
MessageBox("保存配置文件出错,请重试!");
return 1;
}
return 0;
}
int CMainFrame::ReadConfigure()
{
CStdioFile f;
CFileException e;
// CString tt = "123";
// int d = tt;
try
{
if(f.Open("Configure.cig", CFile::modeRead, &e)) //打开了一个文件
{
CString str,sstr;
f.ReadString(sstr);
f.ReadString(str);
if(sstr.IsEmpty() || str.IsEmpty() || sstr.GetLength() < 7)
return 1;
m_bIcon = sstr.GetAt(0) - 48;
m_bMini = sstr.GetAt(2) - 48;
m_bClose = sstr.GetAt(4) - 48;
m_bStyle = sstr.GetAt(6) - 48;
/* if(str.GetAt(0) == '1')
m_bIcon = TRUE;
else
m_bIcon = FALSE;*/
//对需要过滤的文件类型读到NewFileExp
str.TrimLeft();
str.TrimRight();
if(!str.IsEmpty())
{
CString str2 = str;
int num = 0, i, j = 0, k = 0;
for(i = 0; i < str.GetLength(); i++)
if(str.GetAt(i) == ';')
num++;
m_nFileNum = num;
NewFileExp = new CString[num];
for(i = 0; i < str.GetLength(); i++)
{
if(str.GetAt(i) == ' ')
continue;
if(str.GetAt(i) == ';')
{
str2.SetAt(j, '\0');
NewFileExp[k] = str2;
k++;
j = 0;
continue;
}
str2.SetAt(j, str.GetAt(i));
j++;
}
}
}
else
{
MessageBox("读取配置文件出错,请重试!");
return 1;
}
}
catch(CFileException e)
{
MessageBox("读取配置文件出错,请重试!");
return 1;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -