모달리스 다이얼로그
//class CMainFrame에서
CModeless *m_pDlg; //선언
///////////////////////////////////////////////////////////////////
void CMainFrame::OnMenuitem() //메뉴를 클릭했을때
{
if( m_pDlg != NULL )
{
m_pDlg->SetFocus();
}
else
{
m_pDlg = new Modeless;
m_pDlg->Create(IDD_DIALOG1, this);
m_pDlg->ShowWindow(SW_SHOW);
}
}
void Modeless::OnCancel() //취소 버튼 눌렀을 때
{
DestroyWindow();
//CDialog::OnCancel(); //주석 처리 해야함
}
void Modeless::OnClose() //확인 버튼 눌렀을때
{
DestroyWindow();
//CDialog::OnClose(); //주석 처리 해야함
}
void Modeless::PostNcDestroy() //PostNcDestroy추가
{
delete this;
((CMainFrame *)AfxGetMainWnd())->m_pDlg = NULL;
}
//////////////////////////////////////////////////////////////////////
//더 쉬운 방법
//class CTestView에서
CModeless m_Dlg; //선언
void TestView::OnInitialUpdate()
{
CRect rect, winRect;
CString str;
if( m_Dlg.GetSafeHwnd() == NULL )
{
m_Dlg.Create(IDD_DIALOG1);
}
AfxGetMainWnd()->GetWindowRect( &winRect );
m_Dlg.GetWindowRect( &rect );
m_Dlg.SetWindowPos( NULL, winRect.right - rect.Width() - 10, winRect.top + 75, rect.Width(), rect.Height(), 0 );
m_Dlg.ShowWindow(SW_SHOW);
}