close

Вход

Забыли?

вход по аккаунту

?

приложение A мое

код для вставкиСкачать
ПРИЛОЖЕНИЕ А
Листинг программы:
//файл main.cpp
#include <afxwin.h> #include <afxext.h> #include <afxdisp.h> #include <afxdtctl.h>
#include <vector>
#include "resource.h"
#include "event.h"
#include <fstream>
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif #include <iostream>
using namespace std;
string str;
vector<event> storage;
// ===== класс окна задания нового события =====================================
class SetNewDialog: public CDialog
{
public:
SetNewDialog(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonAdd();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(SetNewDialog, CDialog)
ON_COMMAND(IDADD,OnButtonAdd)
END_MESSAGE_MAP()
afx_msg void SetNewDialog::OnButtonAdd()
{
CString Y,M,D,H,Min,S,type,mess;
GetDlgItem(IDC_COMBO1)->GetWindowTextW(type);
GetDlgItem(IDC_EDIT7)->GetWindowTextW(mess);
GetDlgItem(IDC_EDIT7)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT1)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT1)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT2)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT2)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT3)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT3)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT4)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT4)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT5)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT5)->SetWindowTextW(NULL);
GetDlgItem(IDC_EDIT6)->GetWindowTextW(S);
GetDlgItem(IDC_EDIT6)->SetWindowTextW(NULL);
storage.push_back(event(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),type,mess));
}
// ===== класс окна вывода всех событий ================================
class ShowAllDialog: public CDialog
{
public:
ShowAllDialog(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonShow()
{
CListBox *list=(CListBox *)(this->GetDlgItem(IDC_LIST2));
CFont *NeedFont=new CFont;
NeedFont->CreatePointFont(80,L"Courier New");
unsigned int i=0;
CString buf;
SYSTEMTIME st;
GetDlgItem(IDC_LIST2)->SetFont(NeedFont);
list->ResetContent();
for(i=0;i<storage.size();i++)
{
st=storage[i].GetTime();
buf.Format(_T("%-24.24s %4.4d/%-2.2d/%-2.2d/%-2.2d/%-2.2d/%-2.2d %15s"),storage[i].GetMessage(),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,storage[i].GetType());
list->AddString(buf);
}
};
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(ShowAllDialog, CDialog)
ON_COMMAND(IDShow,OnButtonShow)
END_MESSAGE_MAP()
// ===== класс окна вывода событий в конкретное время========================
class ShowEventsAt: public CDialog
{
public:
ShowEventsAt(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonShow()
{
SYSTEMTIME st;
CString Y,M,D,H,Min,S,buf;
unsigned int i=0;
CFont *NeedFont=new CFont;
CListBox *list=(CListBox *)(this->GetDlgItem(IDC_LIST2));
NeedFont->CreatePointFont(80,L"Courier New");
list->SetFont(NeedFont);
GetDlgItem(IDC_EDIT1)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT2)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT3)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT4)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT5)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT6)->GetWindowTextW(S);
event temp(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
list->ResetContent();
for(i=0;i<storage.size();i++)
{
if(temp==storage[i])
{
st=storage[i].GetTime();
buf.Format(_T("%-24.24s %4.4d/%-2.2d/%-2.2d/%-2.2d/%-2.2d/%-2.2d %15s"),storage[i].GetMessage(),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,storage[i].GetType());
list->AddString(buf);
}
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(ShowEventsAt, CDialog)
ON_COMMAND(IDShow,OnButtonShow)
END_MESSAGE_MAP()
// ===== класс окна вывода событий в интервале времени =========================
class ShowEventsInInterval: public CDialog
{
public:
ShowEventsInInterval(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonShow();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(ShowEventsInInterval, CDialog)
ON_COMMAND(IDShow,OnButtonShow)
END_MESSAGE_MAP()
afx_msg void ShowEventsInInterval::OnButtonShow()
{
CString Y,M,D,H,Min,S,buf;
unsigned int i=0;
CFont *NeedFont=new CFont;
CListBox *list=(CListBox *)(this->GetDlgItem(IDC_LIST1));
NeedFont->CreatePointFont(80,L"Courier New");
list->SetFont(NeedFont);
SYSTEMTIME st;
GetDlgItem(IDC_EDIT1)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT2)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT3)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT4)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT5)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT6)->GetWindowTextW(S);
event temp1(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
GetDlgItem(IDC_EDIT7)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT8)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT9)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT10)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT11)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT12)->GetWindowTextW(S);
event temp2(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
list->ResetContent();
for(i=0;i<storage.size();i++)
{
if(storage[i]>temp1 && temp2>storage[i])
{
st=storage[i].GetTime();
buf.Format(_T("%-24.24s %4.4d/%-2.2d/%-2.2d/%-2.2d/%-2.2d/%-2.2d %15s"),storage[i].GetMessage(),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,storage[i].GetType());
list->AddString(buf);
}
}
}
// ===== класс окна вывода прошедших событий сначала =======================
class ShowEventsFromBegining: public CDialog
{
public:
ShowEventsFromBegining(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonShow();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(ShowEventsFromBegining, CDialog)
ON_COMMAND(IDShow,OnButtonShow)
END_MESSAGE_MAP()
afx_msg void ShowEventsFromBegining::OnButtonShow()
{
SYSTEMTIME st;
unsigned int i=0;
CString buf;
GetLocalTime(&st);
event temp(st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,"","");
CListBox *list=(CListBox *)(this->GetDlgItem(IDC_LIST2));
CFont *NeedFont=new CFont;
NeedFont->CreatePointFont(80,L"Courier New");
GetDlgItem(IDC_LIST2)->SetFont(NeedFont);
list->ResetContent();
for(i=0;i<storage.size();i++)
{
if(temp>storage[i])
{
st=storage[i].GetTime();
buf.Format(_T("%-24.24s %4.4d/%-2.2d/%-2.2d/%-2.2d/%-2.2d/%-2.2d %15s"),storage[i].GetMessage(),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,storage[i].GetType());
list->AddString(buf);
}
}
}
// ===== класс проверки наличия событий в заданном интервале ===================
class CheckInInterval: public CDialog
{
public:
CheckInInterval(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonCheck();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CheckInInterval, CDialog)
ON_COMMAND(IDCheck, OnButtonCheck)
END_MESSAGE_MAP()
afx_msg void CheckInInterval::OnButtonCheck()
{
CString Y,M,D,H,Min,S,message;
unsigned int i=0,n=0;
GetDlgItem(IDC_EDIT1)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT2)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT3)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT4)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT5)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT6)->GetWindowTextW(S);
event temp1(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
GetDlgItem(IDC_EDIT7)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT8)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT9)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT10)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT11)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT12)->GetWindowTextW(S);
event temp2(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
for(i=0;i<storage.size();i++)
{
if(storage[i]>temp1 && temp2>storage[i])
{
n++;
}
}
message.Format(L"Number of events in this inteval: %d",n);
MessageBox(message,L"Nunber of events");
}
// ===== класс проверки наличия событий в заданное время =======================
class CheckInTime: public CDialog
{
public:
CheckInTime(char *DialogName, CWnd *Owner):
CDialog((LPCTSTR)DialogName, Owner){};
afx_msg void OnButtonCheck();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CheckInTime, CDialog)
ON_COMMAND(IDCheck,OnButtonCheck)
END_MESSAGE_MAP()
afx_msg void CheckInTime::OnButtonCheck()
{
CString Y,M,D,H,Min,S,message;
unsigned int i=0,n=0;
GetDlgItem(IDC_EDIT1)->GetWindowTextW(Y);
GetDlgItem(IDC_EDIT2)->GetWindowTextW(M);
GetDlgItem(IDC_EDIT3)->GetWindowTextW(D);
GetDlgItem(IDC_EDIT4)->GetWindowTextW(H);
GetDlgItem(IDC_EDIT5)->GetWindowTextW(Min);
GetDlgItem(IDC_EDIT6)->GetWindowTextW(S);
event temp(_ttoi(Y),_ttoi(M),_ttoi(D),_ttoi(H),_ttoi(Min),_ttoi(S),"","");
for(i=0;i<storage.size();i++)
{
if(temp==storage[i])
{
n++;
}
}
message.Format(L"Number of events in this time: %d",n);
MessageBox(message,L"Number of events");
}
// ===== класс главного ОКНА приложения ====================
class WINDOW : public CFrameWnd {
public:
WINDOW ();
afx_msg void OnMenuItem_SetNew();
afx_msg void OnMenuItem_ShowAll();
afx_msg void OnMenuItem_ShowAt();
afx_msg void OnMenuItem_ShowInInterval();
afx_msg void OnMenuItem_ShowFromBegining();
afx_msg void OnMenuItem_CheckInInterval();
afx_msg void OnMenuItem_CheckInTime();
afx_msg void OnDestroy();
DECLARE_MESSAGE_MAP() };
// ===== конструктор Создание окна WINDOW::WINDOW () {
Create ( NULL, L"Курсовой проект 6 семестр", WS_SYSMENU, rectDefault, NULL, (LPCTSTR)IDR_MENU1);
FILE *in=fopen ("g:\\1.bin","rb");
if(!in) {
MessageBox(L"File not fount",L"Error");
}
else
{
event temp;
unsigned int i=0;
while (fread(&temp, sizeof (event),1,in))
{
storage.push_back(temp);
i++;
fseek(in,sizeof(event)*i,SEEK_SET);
}
fclose (in);
}
}
afx_msg void WINDOW :: OnMenuItem_ShowAll()
{
ShowAllDialog ShowAllDialog ((char *)IDD_SHOWALL_DIALOG,NULL);
ShowAllDialog.DoModal();
}
afx_msg void WINDOW :: OnMenuItem_SetNew()
{
SetNewDialog SetDialog((char *)IDD_SETDIALOG,NULL);
SetDialog.DoModal();
}
afx_msg void WINDOW:: OnMenuItem_ShowAt()
{
ShowEventsAt EventsAt((char *)IDD_ShowEventsAt, NULL);
EventsAt.DoModal();
}
afx_msg void WINDOW::OnMenuItem_ShowInInterval()
{
ShowEventsInInterval InInterval((char *)IDD_ShowEventsInInterval,NULL);
InInterval.DoModal();
}
afx_msg void WINDOW::OnMenuItem_ShowFromBegining()
{
ShowEventsFromBegining FromBegining((char *)IDD_ShowEventsFromBegining,NULL);
FromBegining.DoModal();
}
afx_msg void WINDOW::OnMenuItem_CheckInInterval()
{
CheckInInterval CheckInterval((char *)IDD_CheckInInterval, NULL);
CheckInterval.DoModal();
}
afx_msg void WINDOW::OnMenuItem_CheckInTime()
{
CheckInTime CheckTime((char *)IDD_CheckInTime,NULL);
CheckTime.DoModal();
}
afx_msg void WINDOW::OnDestroy()
{
FILE *out=fopen ("g:\\1.bin","wb"); // Если файл не существует он создастся
if(!out) {
MessageBox(L"File not open",L"Error"); // Проверка на NULL
}
for (unsigned int i=0; i<storage.size(); i++)
{
fwrite (&storage[i], sizeof (event),1,out);
fseek(out,sizeof(event),SEEK_CUR);
}
fclose (out); }
// ===== очередь сообщений главного окна BEGIN_MESSAGE_MAP(WINDOW, CFrameWnd) ON_COMMAND(ID_set_new,OnMenuItem_SetNew)
ON_COMMAND(ID_ShowAll,OnMenuItem_ShowAll)
ON_COMMAND(ID_40006,OnMenuItem_ShowAt)
ON_COMMAND(ID_40007,OnMenuItem_ShowInInterval)
ON_COMMAND(ID_40005,OnMenuItem_ShowFromBegining)
ON_COMMAND(ID_40010,OnMenuItem_CheckInInterval)
ON_COMMAND(ID_40009,OnMenuItem_CheckInTime)
ON_WM_DESTROY()
END_MESSAGE_MAP()
// ===== класс ПРИЛОЖЕНИЕ ====================
class APPLICATION : public CWinApp {
public:
BOOL InitInstance();
};
// ===== конструктор Инициализация приложения BOOL APPLICATION::InitInstance ()
{ m_pMainWnd = new WINDOW; m_pMainWnd -> ShowWindow ( m_nCmdShow); m_pMainWnd -> UpdateWindow (); return TRUE;
}
// ===== создание экземпляра приложения ====================
APPLICATION TheApplication; //файл event.h
#include <string>
#include "windows.h"
using namespace std;
class event{
private:
string message;
string type;
SYSTEMTIME st;
public:
event()
{
type="unknown";
message="none";
st.wYear=0;
st.wMonth=0;
st.wDay=0;
st.wHour=0;
st.wMinute=0;
st.wSecond=0;
}
event(int Y,int M,int D,int H,int Min, int Sec, CString the_type, CString the_message)
{
type.resize(the_type.GetLength());
WideCharToMultiByte(CP_ACP, 0, the_type, -1, &type[0], type.size(), NULL, NULL);
message.resize(the_message.GetLength());
WideCharToMultiByte(CP_ACP, 0, the_message, -1, &message[0], message.size(), NULL, NULL);
st.wYear=Y;
st.wMonth=M;
st.wDayOfWeek=0;
st.wDay=D;
st.wHour=H;
st.wMinute=Min;
st.wSecond=Sec;
st.wMilliseconds=0;
}
CString GetMessage()
{
CString the_mess=message.c_str();
return the_mess;
}
SYSTEMTIME GetTime()
{
return st;
}
CString GetType()
{
CString the_type=type.c_str(); return the_type;
}
bool operator > (event a)
{
if(st.wYear>a.GetTime().wYear)
return true;
else if(st.wMonth>a.GetTime().wMonth && st.wYear>=a.GetTime().wYear)
return true;
else if(st.wDay>a.GetTime().wDay && st.wMonth>=a.GetTime().wMonth && st.wYear>=a.GetTime().wYear)
return true;
else if(st.wHour>a.GetTime().wHour && st.wDay>=a.GetTime().wDay && st.wMonth>=a.GetTime().wMonth && st.wYear>=a.GetTime().wYear)
return true;
else if(st.wMinute>a.GetTime().wMinute && st.wHour>=a.GetTime().wHour && st.wDay>=a.GetTime().wDay && st.wMonth>=a.GetTime().wMonth && st.wYear>=a.GetTime().wYear)
return true;
else if(st.wSecond>a.GetTime().wSecond && st.wMinute>=a.GetTime().wMinute && st.wHour>=a.GetTime().wHour && st.wDay>=a.GetTime().wDay && st.wMonth>=a.GetTime().wMonth && st.wYear>=a.GetTime().wYear)
return true;
else return false;
}
bool operator == (event a)
{
if(st.wSecond==a.GetTime().wSecond && st.wMinute==a.GetTime().wMinute && st.wHour==a.GetTime().wHour && st.wDay==a.GetTime().wDay && st.wMonth==a.GetTime().wMonth && st.wYear==a.GetTime().wYear)
return true;
else return false;
}
};
Документ
Категория
Рефераты
Просмотров
21
Размер файла
60 Кб
Теги
мое, приложение
1/--страниц
Пожаловаться на содержимое документа