// Exam.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include "Exam.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 유일한 응용 프로그램 개체입니다.

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
 int nRetCode = 0;

 // MFC를 초기화합니다. 초기화하지 못한 경우 오류를 인쇄합니다.
 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
 {
  // TODO: 오류 코드를 필요에 따라 수정합니다.
  _tprintf(_T("심각한 오류: MFC를 초기화하지 못했습니다.\n"));
  nRetCode = 1;
 }
 else
 {
  if(argc < 2)
  {
   cout << "입력된 행이 없음" << endl;
   return 2;
  }

  // TODO: 응용 프로그램의 동작은 여기에서 코딩합니다.
   
  CString acount = argv[1];

  int iPos = acount.FindOneOf("+-*/");
  if(iPos == -1)
  {
   cout << "사칙 연산 프로그램 띄어쓰지마, +,-,*,/만" << endl;
   return 3;
  }

  CString strFrontEnd = acount.Left(iPos);
  CString strBackEnd = acount.Mid(iPos + 1);
  CString strOperator = acount.Mid(iPos,1);

  int iFrontEnd = atoi(strFrontEnd);
  int iBackEnd = atoi(strBackEnd);
  int iResult = 0;

  if(strOperator == "+")
   iResult = iFrontEnd + iBackEnd;

  else if(strOperator == "-")
   iResult = iFrontEnd - iBackEnd;

  else if(strOperator == "*")
   iResult = iFrontEnd * iBackEnd;

  else if(strOperator == "/")
   iResult = iFrontEnd / iBackEnd;
 
  cout << "계산결과 : "<< iFrontEnd << strOperator << iBackEnd << " = " << iResult << endl;
 }

 return nRetCode;
}

// 파일 사용시 공유 DLL 사용을 체크해야 함

// API의 windows.h 와 같은거
#include <afxwin.h>

// WinMain 부분 음... 여기에 메시지 루프가 들어가 있음
class CHelloApp : public CWinApp
{
public:
 virtual BOOL InitInstance();
};

// 이부분이 API의 WndProc 부분, 메시지를 Catch 해서 처리해줌
class CMainFrame : public CFrameWnd
{
public:
 CMainFrame();

protected:
 afx_msg void OnPaint();
 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 DECLARE_MESSAGE_MAP()
};

// 프로그램 객체
CHelloApp theApp;

// 클래스 정의
// 이부분은 API의 CreateWindow와 같은 역활을 해줌
BOOL CHelloApp::InitInstance()
{
 m_pMainWnd = new CMainFrame;   // 객체 만들어 지면서 생성자 실행
 m_pMainWnd ->ShowWindow(m_nCmdShow); // ShowWindow 명령 실행
 m_pMainWnd ->UpdateWindow();   // UodateWindow 명령 실행
 return TRUE;
}

// 각 함수의 플러그를 보고 싶으면
// 함수에 커서를 대고 F12키를 눌러보자! 그함수를 정의한 헤더 파일등을 볼수 있다

CMainFrame::CMainFrame()
{
 Create(NULL,"HelloMFC Application");
}

// WM_PAINT 할때의 명령
void CMainFrame::OnPaint()
{
 char *msg = "Hello, MFC";
 CPaintDC dc(this);

 dc.TextOut(100,100,msg,lstrlen(msg));
}

// WM_LBUTTONDOWN 의 명령
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
 MessageBox("마우스클릭했지?","마우스",MB_YESNOCANCEL | MB_ICONQUESTION);
}

// 메시지 맵
// 이 메시지 맵은 CMainFrame의 소속이다
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
// MFC에이미 정의가 되어있는 키워드
 ON_WM_PAINT()    
 ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// 맨 마지막 줄은 DefWnidowProc 와 같은 명령을 해준다

// 이 다음에 WinMain 함수가 생략되어 있음.
// 이 소스에서 실행하는건 프로그램 객체 선언 CHelloApp theApp; 이 한줄 뿐임.
// WinMain 함수는 어느 윈도우나 같으므로 아예 생략되었음. (컴파일할때 자동 처리)
// WinMain 함수를 보고 싶으면 BOOL CHelloApp::InitInstance() 줄에 브레이크 포인트를 걸어볼껏
// .net 에서만 유효, 호출 스택을 잘 보면 나옴

+ Recent posts