티스토리 뷰

1. 해당 Dialog 속성 변경
     Border = None
     Style = Child
2. DECLARE_DYNCREATE(CMonitorDlg /*클래스명*/)
3. IMPLEMENT_DYNCREATE(CMonitorDlg /*클래스명*/, CDialog /*또는 CDialogEx 부모클래스 */)

 

동적객체를 만들때 new 연산자를 사용하듯,

View Class 에 #include "MonitorDlg.h" 추가.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "MonitorDlg.h"
 
ShowDialog(RUNTIME_CLASS(CMonitorDlg/*클래스이름*/), IDD_MONITOR_DIALOG/*다이얼로그박스 ID*/); // 아래 CMainFrame::::OnMainFrameMenuMonitor() 코드 참조
 
bool CMonitorView::ShowDialog(CRuntimeClass* pClass, UINT uID)
{
 CDialog* pDlg = (CDialog*/*부모클래스*/)pClass->CreateObject();
 pDlg->Create(uID, this);
 CRect rcChild; pDlg->GetWindowRect( rcChild );
 CRect rcClient; GetClientRect( rcClient );
 CRect rcWindow; GetParent()->GetWindowRect( rcWindow ); rcWindow.right  += rcChild.Width()  - rcClient.Width();
 rcWindow.bottom += rcChild.Height() - rcClient.Height();
 GetParent()->SetWindowPos( NULL00, rcWindow.Width(), rcWindow.Height(), SWP_NOMOVE | SWP_NOZORDER );
 pDlg->ShowWindow(SW_SHOW);
 m_pDlg = pDlg; return false;
}
cs

어떤 클래스(혹은 다이얼로그박스)던 위와같이하면 동적으로 만들 수 있어, 메뉴 선택에 따라 원하는 DialogBox 객체를 동적으로 만들어 View에 보일수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// MonitorDlg.h 소스 일부
 
class CMonitorDlg : public CDialog
{
 protected:
DECLARE_DYNCREATE(CMonitorDlg/*클래스명*/// 동적 생성할 객체에 선언 필요 
...
}
 
// MonitorDlg.cpp 소스 일부
 
IMPLEMENT_DYNCREATE(CMonitorDlg/*클래스명*/, CDialog/*부모클래스*/// 위와 쌍으로 필요
 
 
CMainFrame.cpp 소스 - 특정 메뉴 선택 시 뷰에 해당 다이얼로그를 보여준다
 
void CMainFrame::OnMainFrameMenuMonitor()
{
 AfxGetApp()->m_pDocManager->OnFileNew(); // 새창 열기
 CStView* pView = (CStView*)(GetActiveFrame()->GetActiveView());
 pView->ShowDialog(RUNTIME_CLASS(CMonitorDlg), IDD_MONITOR_DIALOG);
}
cs



만약, 사용자가 만든 클래스를 위처럼 동적 생성하고 싶으면, include "afx.h" 필요, CObject를 상속받아야 한다.

1
2
3
4
5
6
include "afx.h" // MFC에서는 stdafx.h
 
class CTestClas : public CObject
{
    ...
}
cs

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30