본문 바로가기

Programming/Win32&MFC&COM

SDI Document/View 구조 제거하기

반응형

MFC의 SDI(Single Document Interface)는 기본적으로 Document/View 구조를 지원합니다.

프로젝트를 생성할 때 몇 번의 클릭으로 간단하게 Document/View 기반으로 생성할 수 있습니다.

자동으로 생성되는 Doc/View 구조가 필요하지 않을 경우도 발생합니다.

SDI에서 Doc/View 구조를 제거하는 방법입니다.

먼저 프로젝트를 생성합니다.

일단 Document/View architecture support는 그대로 둡니다.

Doc/View가 설정된 프로젝트에서 구조를 제거하기 위해서 입니다.

Compound Document Support, Document Template Properties는 기본 설정을 사용합니다.

그리고 Database Support도 기본 설정으로 둡니다.

다음으로 User Interface Features에서는 Use a ribbon으로 변경합니다.

이 부분은 변경하지 않아도 되는 부분입니다.

나머지 부분(Advanced Feature, Generated Classes)도 그대로 둔 상태로 Finish를 눌러서 생성합니다.

프로그램을 실행시키면 Untitled가 타이틀바에 보이고 Open 등의 메뉴가 활성화됩니다.

Doc/View 옵션을 해제했을 때는 활성화가 되지 않는 부분입니다.

이제 Doc/View 구조를 제거하는 방법입니다.

InitInstance() 함수의 일부 구조입니다.

// Register the application's document templates.  Document templates
//  serve as the connection between documents, frame windows and views
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
	IDR_MAINFRAME,
	RUNTIME_CLASS(CMFCApplication4Doc),
	RUNTIME_CLASS(CMainFrame),       // main SDI frame window
	RUNTIME_CLASS(CMFCApplication4View));
if (!pDocTemplate)
	return FALSE;
AddDocTemplate(pDocTemplate);

이 부분이 Doc/View 구조가 해제된 프로젝트에는 다음과 같은 코드로 되어 있습니다.

// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object
CMainFrame* pFrame = new CMainFrame;
if (!pFrame)
	return FALSE;
m_pMainWnd = pFrame;
// create and load the frame with its resources
pFrame->LoadFrame(IDR_MAINFRAME,
	WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
	NULL);

Doc/View가 해제된 프로젝트의 내용으로 맨 위의 코드를 변경하면 됩니다.

이렇게 변경하고 컴파일을 하게 되면 에러가 발생합니다.

error C2248: 'CMainFrame::CMainFrame' : cannot access protected member declared in class 'CMainFrame' 

CMainFrame의 생성자가 protected에 있어서 접근할 수 없다는 에러입니다.

MainFrm.h 파일로 이동해서 생성자 부분이 있는 곳을 public:으로 변경합니다.

public: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

추가로 Doc과 View의 소스와 헤더 파일도 삭제해도 됩니다.

이 경우에는 헤더를 인클루드하는 소스 코드 역시 삭제하면 됩니다.

그리고 솔루션 탐색기에도 해당 파일을 제거하면 됩니다.

마지막으로 Open 메뉴가 정상적으로 실행이 되지 않습니다.

메뉴를 제거하는 등의 방법으로 수정하면 됩니다.

이제 MainFrame을 통해서 직접 작업을 진행하면 됩니다.


반응형