분석좀 부탁드릴께요 ~
친구한테 부탁해서 소스 받아 내긴했는데 어떤식으로 진행되는지 감이 안잡혀서요
헤더파일은 다 있다고 치고 분석좀 부탁드려요ㅠㅠ
// Schedule M.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Schedule M.h"
#include "Schedule MDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScheduleMApp
BEGIN_MESSAGE_MAP(CScheduleMApp, CWinApp)
//{{AFX_MSG_MAP(CScheduleMApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScheduleMApp construction
CScheduleMApp::CScheduleMApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CScheduleMApp object
CScheduleMApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CScheduleMApp initialization
BOOL CScheduleMApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CScheduleMDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application\'s message pump.
return FALSE;
}
// Schedule MDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Schedule M.h"
#include "Schedule MDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScheduleMDlg dialog
CScheduleMDlg::CScheduleMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScheduleMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScheduleMDlg)
m_strEdit = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CScheduleMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScheduleMDlg)
DDX_Control(pDX, IDC_CTRL_MONTH, m_ctrlMonth);
DDX_Text(pDX, IDC_EDIT_DISPLAY, m_strEdit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScheduleMDlg, CDialog)
//{{AFX_MSG_MAP(CScheduleMDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_INSERT, OnBtnInsert)
ON_NOTIFY(MCN_SELCHANGE,IDC_CTRL_MONTH, OnSelChange)
ON_BN_CLICKED(IDC_BTN_EDIT, OnBtnEdit)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScheduleMDlg message handlers
BOOL CScheduleMDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application\'s main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CScheduleMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CScheduleMDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CScheduleMDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CScheduleMDlg::OnBtnInsert()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
Insert();
UpdateData(FALSE);
AfxMessageBox("스케줄 입력 완료!!");
}
void CScheduleMDlg::OnSelChange()
{
// 선택한 날짜의 스케줄이 Display되어야 함.
SelChangeDisplay();
}
void CScheduleMDlg::OnBtnEdit()
{
// TODO: Add your control notification handler code here
// 선택된 날짜의 수정된 스케줄로 파일에 다시 저장
UpdateData(TRUE);
Delete();
Insert();
UpdateData(FALSE);
AfxMessageBox("스케줄 수정 완료!!");
}
void CScheduleMDlg::OnBtnDelete()
{
// TODO: Add your control notification handler code here
// 파일에 선택된 날짜의 스케줄을 삭제.
UpdateData(TRUE);
Delete();
SelChangeDisplay();
UpdateData(FALSE);
AfxMessageBox("스케줄 삭제 완료!!");
}
void CScheduleMDlg::GetPointDate()
{
SYSTEMTIME DateTime;
m_ctrlMonth.GetCurSel(&DateTime);
m_nSelYear = DateTime.wYear;
m_nSelMonth = DateTime.wMonth;
m_nSelDay = DateTime.wDay;
// 유효성 검사가 있으면 더 좋겠다.
// if(m_nSelYear > 2000 && m_nSelYear<2011 && m_nSelMonth > 0 && m_month<13 && m_day>0 && m_day<32)
}
void CScheduleMDlg::Delete()
{
FILE *stream;
char list[200];
char cur_day[9],txt_day[9];
char data_txt[3000][200];
int sel_index,count;
CString msg;
CString str_msg;
count=0;
memset(cur_day,0x00,sizeof(cur_day));
GetPointDate();
sprintf(cur_day,"%04d%02d%02d",m_nSelYear,m_nSelMonth,m_nSelDay);
if( (stream = fopen( "스케줄.txt", "r" )) != NULL )
{
memset(list,0x00,sizeof(list));
while(fgets( list, 198, stream ) != NULL)
{
memset(txt_day,0x00,sizeof(txt_day));
sprintf(txt_day,"%.8s",list);
if((strncmp(cur_day,txt_day,8) != 0) && (strlen(list) > 8))
{
strcpy(data_txt[count++],list);
memset(list,0x00,sizeof(list));
}
} // end while
fclose( stream );
if( (stream = fopen( "스케줄.txt", "w+" )) != NULL )
{
for(int i=0; i<count; i++)
{
fwrite( data_txt[i], sizeof( char ), strlen(data_txt[i]), stream );
}
fclose( stream );
}
}
else
{
str_msg.Format("File could not be opened" );
}
}
void CScheduleMDlg::SelChangeDisplay()
{
FILE *stream;
char list[200];
char cur_day[9],txt_day[9];
int i,count;
CString str_month,str_msg;
UpdateData(TRUE);
GetPointDate(); // m_nSelYear, m_nSelMonth, m_nSelDay
memset(cur_day,0x00,sizeof(cur_day));
sprintf(cur_day,"%04d%02d%02d",m_nSelYear,m_nSelMonth,m_nSelDay);
count=0;
if( (stream = fopen( ".\\\\스케줄.txt", "r" )) != NULL )
{
memset(list,0x00,sizeof(list));
while(fgets( list, 198, stream ) != NULL)
{
memset(txt_day,0x00,sizeof(txt_day));
if(strlen(list) > 8)
sprintf(txt_day,"%.8s",list);
else continue;
if(strncmp(cur_day,txt_day,8) == 0)
{
// 스케줄이 있는 경우
for(i=0;i<200;i++)
{
if(i>=0 && i<=7) list[i] = \' \';
if(list[i] == \'\\n\') list[i] = \' \';
}
str_msg.Format("%.199s", list );
m_strEdit = str_msg;
UpdateData(FALSE);
memset(list,0x00,sizeof(list));
break;
} else {
// 스케줄이 없는 경우
str_msg.Format("스케줄이 없습니다.");
m_strEdit = str_msg;
UpdateData(FALSE);
memset(list,0x00,sizeof(list));
}
}
fclose( stream );
} else {
AfxMessageBox("데이타가 없습니다.");
}
}
void CScheduleMDlg::Insert()
{
FILE *stream;
char list[200];
GetPointDate();
memset(list,0x00,sizeof(list));
sprintf(list,"\\n%04d%02d%02d%s",m_nSelYear,m_nSelMonth,m_nSelDay,m_strEdit);
stream = fopen( ".\\\\스케줄.txt", "a+" );
fwrite( list, sizeof( char ), 199, stream );
fclose( stream );
}
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.