본문 바로가기

mfc

(3)
다중 커멘트라인 입력 받기 MFC 프로그램 하다 보면 커멘드 라인으로 입력을 받아야 할 때가 많이 있다. 방법은 아래와 같다. CString strArglist[MAX_PATH]; int nArgs; int i; szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if( NULL == szArglist ) { AfxMessageBox(_T("CommandLineToArgvW failed")); } else { for( i = 0; i < nArgs; i++ ) AfxMessageBox(strArglist[i]); }
MFC 파일 입출력(CFile 사용) MFC에서는 파일 입출력할때 쉽게 도와주도록 CFile을 제공한다. 이를 이용해서 간단하게 파일을 출력하는 예제를 만들어 보도록 하겠다. (말로 하는 것 보다 보는게 훨씬 바를테니깐) CString temp; temp = _T("\"Demo Page \"\r\n"); temp += _T("\"If you want show this page, you must save file\"\r\n"); CFile *pFile = NULL; int length = temp.GetLength(); pFile = new CFile(_T("C:\\demo.txt"), CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone); pFile->Write(temp, length*..
종료 단축기 만들기 MFC에서 종료는 [Alt+F4]로 간단하게 종료 할 수 있다. 하지만 특정키를 누르거나 다른 단축키로도 종료를 원한다면 직접 프로그래밍 상에서 소스를 추가해줘야 한다. 다음은 프로그래밍 상에서의 추가 방법이다. 예제) [Alt+X]를 눌렀을 경우 프로그램이 종료되도록 하는 코드 void Cmfc_testView::OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if(nChar == 'x' || nChar == 'X') { ASSERT(AfxGetMainWnd() != NULL); AfxGetMainWnd()->SendMessage(WM_CLOSE)..

반응형