return;
}
while (f.ReadString(str_77))
{
if (!strText.IsEmpty())
strText += "\r\n";
strText += str_77;
}
SetDlgItemText(IDC_EDIT1, strText);
m_strPath = fileDlg1.GetPathName();
m_strFileName = f.GetFileName();
SetWindowText(m_strFileName + _T("-Блокнот"));
}
}
if (uRes == IDNO)
{
CFileDialog fileDlg(TRUE, _T(".txt"), NULL,
OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST,
_T("All Files (*.*) |*.*| Text Files(*.txt) | *.txt| Word Files(*.doc) |*.doc|"));
if (fileDlg.DoModal() == IDOK)
{
if (!f.Open(fileDlg.GetPathName(), CFile::modeRead | CFile::typeText))
{
MessageBox("Не могу открыть файл");
return;
}
while (f.ReadString(str_77))
{
if (!strText.IsEmpty())
strText += "\r\n";
strText += str_77;
}
SetDlgItemText(IDC_EDIT1, strText);
m_strPath = fileDlg.GetPathName();
m_strFileName = f.GetFileName();
SetWindowText(m_strFileName + _T("-Блокнот"));
}
}
}
}
void CMenuDlg::OnSoxranit()//Сохранить-------------------------------
{
if (m_strPath == _T("Безымянный") )
OnSoxranitkak();
else
{
CStdioFile file;
if (!file.Open(m_strFileName
, CFile::modeCreate | CFile::modeWrite | CFile::typeText))
{
AfxMessageBox(_T("Не могу открыть файл."));
return;
}
CEdit *pEditor = (CEdit *)GetDlgItem(IDC_EDIT1);
int nLines = pEditor->GetLineCount();
CString str;
for (int i = 0; i < nLines; i++)
{
int nLen = pEditor->LineLength(pEditor->LineIndex(i));
pEditor->GetLine(i, str.GetBuffer(nLen), nLen);
str.ReleaseBuffer(nLen);
if (i > 0)
str = _T("\n") + str;
file.WriteString(str);
}
}
}
void CMenuDlg::OnSoxranitkak()//Сохранитькак------------------------
{
CString str_77, strText;
CFileDialog fileDlg(FALSE,_T(".txt"),NULL,NULL,"Text Files(*.txt) | *.txt|",NULL);
if(fileDlg.DoModal() == IDOK)
{
//path = fileDlg.GetPathName();
CStdioFile f;
if(!f.Open(fileDlg.GetPathName(), CFile::modeCreate | CFile::modeWrite))
{
MessageBox("Не могу сохранить файл");
return;
}
/*while (f.ReadString(str_77))
{
if (!strText.IsEmpty())
strText += "\r\n";
strText += str_77;
}
SetDlgItemText(IDC_EDIT1, strText);
m_strPath = fileDlg.GetPathName();
m_strFileName = f.GetFileName();
SetWindowText(m_strFileName + _T("-Блокнот(Alexa)"));*/
CEdit *pEditor = (CEdit *)GetDlgItem(IDC_EDIT1);
int nLines = pEditor->GetLineCount();
CString str;
for (int i = 0; i < nLines; i++)
{
int nLen = pEditor->LineLength(pEditor->LineIndex(i));
pEditor->GetLine(i, str.GetBuffer(nLen), nLen);
str.ReleaseBuffer(nLen);
if (i > 0)
str = _T("\n") + str;
f.WriteString(str);
}
m_strPath = fileDlg.GetPathName();
m_strFileName = f.GetFileName();
SetWindowText(m_strFileName + _T(" - Блокнот"));
}
}
void CMenuDlg::OnWremja()//Время---------------------------------------
{
CEdit *pmyEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
CString str, str2, str3;
int nashalo, konec;
CTime time = CTime::GetCurrentTime();
UpdateData();
str = time.Format(_T("%H:%M %d.%m.%Y"));
pmyEdit->GetSel(nashalo, konec);
GetDlgItemText(IDC_EDIT1, str3);
str3.Insert(konec, str);
SetDlgItemText(IDC_EDIT1, str3);
pmyEdit->SetSel(nashalo + 17, konec + 17);
}
void CMenuDlg::OnWidelitwse()//Выделитьвсе---------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->SetSel(0,-1);
mEdit->SetFocus();
}
void CMenuDlg::OnShrift() //Шрифт-----------------------------------------------
{
LOGFONT lfText;
m_fontText.GetLogFont(&lfText);
CFontDialog fontDlg(&lfText);
if (fontDlg.DoModal())
{fontDlg.GetCurrentFont(&lfText);
m_fontText.DeleteObject();
m_fontText.CreateFontIndirect(&lfText);
m_Edit1.SetFont(&m_fontText);}
}
void CMenuDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (IsWindow(m_wndStatusBar.m_hWnd))
{
m_wndStatusBar.MoveWindow(0, 0, 0, 0);
CRect rect;
m_wndStatusBar.GetClientRect(&rect);
int nParts[] = {rect.right - 200, - 1};
m_wndStatusBar.SetParts(sizeof(nParts)/sizeof(nParts[0]), nParts);
CString strPartsStatusBar;
strPartsStatusBar.Format(_T("Строка %d, столбец %d"), m_nStrStatusBar, m_nStolbetsStatusBar);
}
CWnd *pEdit = GetDlgItem(IDC_EDIT1);
if (pEdit != NULL)
{
CRect rcClient;
GetClientRect(rcClient);
rcClient.InflateRect(-2, -2, -2, -20);
pEdit->MoveWindow(rcClient);
if(IsWindow(m_Edit1.m_hWnd))
{
m_wndStatusBar.MoveWindow(0, 0, 0, 0);
CRect clientRect1;
CRect clientRStatusBar1;
GetClientRect(clientRect1);
m_wndStatusBar.GetClientRect(clientRStatusBar1);
CRect cx = clientRect1;
cx.bottom = clientRect1.bottom - clientRStatusBar1.Height();
m_Edit1.MoveWindow(cx);
}
CMenu* pMenu = GetMenu()->GetSubMenu(3);
UINT state = pMenu->GetMenuState(1, MF_BYPOSITION);
if (nType == SIZE_MINIMIZED && state & MF_CHECKED)
{
ShowWindow(SW_HIDE);
Shell_NotifyIcon(NIM_ADD, &m_nidTray);
//m_uTimer = SetTimer(1, 500, NULL);
nIcon = 0;
}/*
static UINT rgIconID[] =
{
IDI_ICON1, IDI_ICON2, IDI_ICON3, IDI_ICON4
};
nIcon++;
if (nIcon == 4) nIcon = 0;
m_nidTray.hIcon = AfxGetApp()->LoadIcon(rgIconID[nIcon]);
Shell_NotifyIcon(NIM_MODIFY, &m_nidTray);
*/
}
}
void CMenuDlg::Onblokn()//МодальноеокноОблокноте---------------
{
mein dlg;
if (dlg.DoModal() == IDOK)
{
Beep(1500,300);
}
}
void CMenuDlg::OnUdalit()//Удалить---------------------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->Clear();
mEdit->SetFocus();
}
void CMenuDlg::OnWirezat()//Вырезать-----------------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->Cut();
mEdit->SetFocus();
}
void CMenuDlg::OnKopirowat()//Копировать--------------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->Copy();
mEdit->SetFocus();
}
void CMenuDlg::OnWstawit()//Вставить-------------------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->Paste();
mEdit->SetFocus();
}
Void CMenuDlg::OnOtmenit()//Отменить----------------------------------
{
CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
mEdit->Undo();
mEdit->SetFocus();
}
void CMenuDlg::OnEnChangeEdit1()//Едит------------------------------
{
//CEdit *mEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
//mEdit->SetSel(0, 0);
CString str_4;
m_Edit1.GetWindowText(str_4);
if (str_4 != _T(""))
{
CMenu* MENU = GetMenu();
CMenu* sibmenu = MENU->GetSubMenu(1);
sibmenu->EnableMenuItem(ID_Otmenit, MF_BYCOMMAND | MF_ENABLED );
}
/*else if(str_4 ==_T(""))
{
CMenu* MENU = GetMenu();
CMenu* sibmenu = MENU->GetSubMenu(1);
sibmenu->EnableMenuItem(ID_Otmenit, MF_BYCOMMAND | MF_GRAYED);
}*/
/*
CString str_5;
m_Edit1.GetWindowText(str_5);
if (str_5 != _T(""))
{
CMenu* MENU2 = GetMenu();
CMenu* sebmenu = MENU2->GetSubMenu(1);
sebmenu->EnableMenuItem(ID_Wirezat, MF_BYCOMMAND | MF_ENABLED );
}
else if(str_5 ==_T(""))
{
CMenu* MENU2 = GetMenu();
CMenu* sebmenu = MENU2->GetSubMenu(1);
sebmenu->EnableMenuItem(ID_Wirezat, MF_BYCOMMAND | MF_GRAYED);
}
CString str_6;
m_Edit1.GetWindowText(str_6);
if (str_6 != _T(""))
{
CMenu* MENU2 = GetMenu();
CMenu* sebmenu = MENU2->GetSubMenu(1);
sebmenu->EnableMenuItem(ID_Udalit, MF_BYCOMMAND | MF_ENABLED );
}
else if(str_5 ==_T(""))
{
CMenu* MENU2 = GetMenu();
CMenu* sebmenu = MENU2->GetSubMenu(1);
sebmenu->EnableMenuItem(ID_Udalit, MF_BYCOMMAND | MF_GRAYED);
}*/
}
void CMenuDlg::OnInitMenu(CMenu* pMenu)
{
CDialog::OnInitMenu(pMenu);
}
void CMenuDlg::OnClose()//Закрытие-------------------------------------
{
CString str_r;
m_Edit1.GetWindowText(str_r);
if (str_r == _T(""))
{
EndDialog(0);
return;
}
else if (str_r != _T(""))
{
UINT uRes = MessageBox(_T("Текст в файле Безымянный был изменньон \n\n Сохранить изменение?"),
_T("Блокнот"), MB_YESNOCANCEL | MB_ICONWARNING);
if (uRes == IDYES)
{
CString path;
CFileDialog fdlg(FALSE,_T(".txt"),NULL,NULL,"Text Files(*.txt) |*.txt|",NULL);
if(fdlg.DoModal() == IDOK)
{
path = fdlg.GetPathName();
CFile f;
if(!f.Open(path, CFile::modeCreate | CFile::modeWrite))
{
MessageBox("Не могу сохранить файл");
return;
}
CString str;
m_Edit1.GetWindowText(str);
f.Write(str, str.GetLength());
f.Close();
}
}
if (uRes == IDNO)
{
CDialog::OnClose();
}
if (uRes == IDCANCEL)
{}
}
KillTimer(m_uTimer);
KillTimer(m_nTimer);
//CDialog::OnClose();
}
void CMenuDlg::OnSprawka2()//Вызовсправки----------------------------
{
MessageBox(_T("Самопал от Лехи ") ,
_T("Блокнот"), MB_OK | MB_ICONINFORMATION);
}
void CMenuDlg::OnNauti()//Найти-------------------------------------------------
{
if (!m_pAddDlg)
{
m_pAddDlg = new m_nauti (this);
m_pAddDlg->Create(IDD_M_NAUTI);
}
m_pAddDlg->ShowWindow(SW_SHOW);
m_pAddDlg->SetForegroundWindow();
m_Find = TRUE;
}
void CMenuDlg::OnNautidalee()//Найтидалее-------------------------------
{
OnNauti();
/*if (!m_Find)
OnEditMfind();
else
m_nauti->OnNauti();*/
}
void CMenuDlg::OnZamenit()//Заменить--------------------------------------
{
CEdit *pEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
pEdit->SetSel(0, 0);
if (!m_zamenitDlg)
{
// Создаемобъектдочернегоокна
m_zamenitDlg = new Zamenit (this);
// Создаемдочернееокно
m_zamenitDlg->Create(IDD_ZAMENIT);
}
// Показываемдочернееокно
m_zamenitDlg->ShowWindow(SW_SHOW);
m_zamenitDlg->SetForegroundWindow();
//Zamenit dlg;
//if (dlg.DoModal() == IDCANCEL)
//{
////Beep(1500,300);
//}
}
void CMenuDlg::OnT()//строка состояние-------------------------------------
{
CMenu* pMenu = GetMenu()->GetSubMenu(3);
CWnd *pEdit = GetDlgItem(IDC_EDIT1);
CRect rcEditSize;
UINT state = pMenu->GetMenuState(0, MF_BYPOSITION);
if (state & MF_CHECKED)
{
//Beep(100,100);
/*Beep(200,100);Beep(300,100);Beep(400,100);Beep(500,100);Beep(600,100);
Beep(700,100);Beep(800,100);Beep(900,100);Beep(1000,100);Beep(1100,100);
Beep(1200,100);Beep(1300,100);Beep(1400,100);Beep(1500,100);Beep(1600,100);
Beep(1700,100);Beep(1800,100);Beep(1900,100);Beep(2000,100);Beep(2100,100);
Beep(2500,500);Beep(1900,100);Beep(1800,100);Beep(1700,100);Beep(1600,100);
Beep(1500,100);Beep(1400,100);Beep(1300,100);Beep(1200,100);Beep(1100,100);
Beep(1000,100);Beep(900,100);Beep(800,100);Beep(700,100);Beep(600,100);
Beep(500,100);Beep(400,100);Beep(300,100);Beep(200,100);Beep(100,500);*/
pMenu->CheckMenuItem(0, MF_UNCHECKED | MF_BYPOSITION);
m_wndStatusBar.ShowWindow(SW_HIDE);
GetClientRect(rcEditSize);
rcEditSize.InflateRect(-2, -2);
pEdit->MoveWindow(rcEditSize);
m_bFlMenu = FALSE;
}
else
{
pMenu->CheckMenuItem(0, MF_CHECKED | MF_BYPOSITION);
m_wndStatusBar.ShowWindow(SW_SHOW);
GetClientRect(rcEditSize);
rcEditSize.InflateRect(-2, -2, -2, -20);
pEdit->MoveWindow(rcEditSize);
m_bFlMenu = TRUE;
}
}
void CMenuDlg::OnTimer(UINT nIDEvent)//Онтаймер-------------------
{
CString strPartsStatusBar;
CEdit *pmyEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
int nStart, nEnd;
pmyEdit->GetSel(nStart, nEnd);
m_nStrStatusBar = pmyEdit->LineFromChar(nStart);
m_nStolbetsStatusBar = nEnd - pmyEdit->LineIndex(m_nStrStatusBar);
strPartsStatusBar.Format(_T("Стр %d, стлб%d"), m_nStrStatusBar + 1, m_nStolbetsStatusBar + 1);
m_wndStatusBar.SetText(strPartsStatusBar, 1, 0);
//m_wndStatusBar.ShowWindow(SW_SHOW);
CDialog::OnTimer(nIDEvent);
}
LRESULT CMenuDlg::OnTrayIcon(WPARAM wParam, LPARAM lParam)//Трай-----------------------
{
if (wParam != ID_TRAYICON || (lParam != WM_LBUTTONUP && lParam != WM_RBUTTONUP))
return 0L;
if (lParam == WM_LBUTTONUP)
{
OnTrayOpen();
}
else if (lParam == WM_RBUTTONUP)
{
CPoint pt;
GetCursorPos(&pt);
CMenu *pTrayMenu = m_menuTray.GetSubMenu(0);
// Исправляем баг с контекстным меню (см. MSDN Knowledge Base: 135788)
SetForegroundWindow();
pTrayMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this);
// Исправляем баг с контекстным меню (см. MSDN Knowledge Base: 135788)
PostMessage(WM_NULL, 0, 0);
}
return 0;
}
void CMenuDlg::OnTrayOpen()
{
ShowWindow(SW_RESTORE);
SetForegroundWindow();
Shell_NotifyIcon(NIM_DELETE, &m_nidTray);
}
void CMenuDlg::OnTrayExit()
{
Shell_NotifyIcon(NIM_DELETE, &m_nidTray);
EndDialog(0);
}
void CMenuDlg::OnTrei()
{
CMenu* pMenu = GetMenu()->GetSubMenu(3);
UINT state = pMenu->GetMenuState(1, MF_BYPOSITION);
if (state == MF_CHECKED)
{
pMenu->CheckMenuItem(1, MF_UNCHECKED | MF_BYPOSITION);
}
else
{
pMenu->CheckMenuItem(1, MF_CHECKED | MF_BYPOSITION);
}
}
void CMenuDlg::OnPereuti()//перейти-----------------------------------------
{
/*
pereuti move;
CString str,str1;
int index;
int lines;
//DWORD word;
lines = m_Edit1.GetLineCount();
str1 = _T("Столькострокнет!!! их всего: ");
str.Format(_T("%d"),lines);
str1 += str;
//word = m_Edit.GetSel();
index = m_Edit1.LineFromChar()+1;
//index = m_Edit1.GetLineCount();
move.m_position = index;
//move.Goto_Edit.SetSel(0, -1);
if(move.DoModal() == IDOK)
{
//move.m_edit_pereuti.SetSel(0, -1);
if(lines < m_Edit1.LineIndex(move.m_position+10))
AfxMessageBox(str1);
else
m_Edit1.SetSel(m_Edit1.LineIndex(move.m_position-1),
m_Edit1.LineIndex(move.m_position-1));
}*/
pereuti move;
CString str,str1;
int index;
int lines;
lines = m_Edit1.GetLineCount();
str1 = _T("Столькострокнет!!! их всего: ");
str.Format(_T("%d"),lines);
str1 += str;
index = m_Edit1.LineFromChar() + 1;
move.m_position = index;
if(move.DoModal() == IDOK)
{
//move.m_edit_pereuti.SetSel(0, -1);
if(index >= m_Edit1.LineIndex(move.m_position-1))
AfxMessageBox(str1);
else
m_Edit1.SetSel(m_Edit1.LineIndex(move.m_position-1),
m_Edit1.LineIndex(move.m_position-1));
}
}
void CMenuDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
CEdit *pEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
int nFerstChar, nSecondChar;
CString strEdit;
pEdit->GetSel(nFerstChar, nSecondChar);
pEdit->GetWindowText(strEdit);
UINT format = CF_TEXT;
BOOL bClipboard = IsClipboardFormatAvailable(format);
//pPopupMenu->EnableMenuItem(ID_Otmenit,
//MF_BYCOMMAND | (bClipboard == FALSE ? MF_GRAYED : MF_ENABLED));
//pPopupMenu->EnableMenuItem(ID_Otmenit,
//MF_BYCOMMAND | (m_bFlag == FALSE ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Wirezat,
MF_BYCOMMAND | (nFerstChar == nSecondChar ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Kopirowat,
MF_BYCOMMAND | (nFerstChar == nSecondChar ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Udalit,
MF_BYCOMMAND | (nFerstChar == nSecondChar ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Nauti,
MF_BYCOMMAND | (strEdit == _T("") ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Zamenit,
MF_BYCOMMAND | (strEdit == _T("") ? MF_GRAYED : MF_ENABLED));
pPopupMenu->EnableMenuItem(ID_Nauti_dalee,
MF_BYCOMMAND | (strEdit == _T("") ? MF_GRAYED : MF_ENABLED));
}