Monday, April 19, 2010

modeless

MODELESS
1)Run application wizard and choose single document
2)Create a dialog resource,IDP_DIALOG,Dialog class projdialog
a)Create a pointer to view window in construction
b)Define function create( ) then call base class create( ) function.
c)Define ON-OK,ON-CANCEL functions and post the message GOODBYE.
3)View class:
a)Create a pointer to dialog window with constructor.
b)Onleft mouse button class call create( ) of dialog class.
c)Define on goodbye function that destroy window.
d)Build and execute program.
CODE:
Projdialog.h
#define WM_GOODBYE WM_USER+5
private:
CView* m_pView;
public:
ProjDialog(CView* pView);
BOOL Create();
Projdialog.cpp:
Projdialog::Projdialog(CView* pView)
{
m_pview=pView;
}
BOOL Projdialog::Create()
{
Return CDialog::Create(Projdialog::IDD);
}
void Projdialog::OnOK()
{
if(m_pView!=NULL)
{
UpdateData(TRUE);
m_pView->PostMessage(WM_GOODBYE,IDOK);
}
else
CDialog::OnOK();
}
void Projdialog::OnCancel( )
{
if(m_pView!=NULL)
{
m_pView->PostMessage(WM_GOODBYE,IDCANCEL);
}
else
CDialog::OnCancel();
}

Projview.h
//Add this at the begning
Class Projdialog;
Private:
Projdialog *m_pDlg;
Protected:
//add this line after AFX_MSG and before DECLARE MESSAGE MAP
Afx_msg LRESULT OnGoodbye(WPARAM wparam,LPARAM lparam);
Projview.cpp
//Add after Begin_Message_Map but inside AFX_MSG_MAP
ON_MESSAGE(WM_GOODBYE,OnGoodbye);
#include “Projview.h”
#include “Projdialog.h”
Projview::Projview()
{
m_pDlg=new Projdialog(this);
}
Projview::~Projview()
{
delete m_pDlg;
}
void Projview::OnLButtonDown(UINT nFlags,CPoint point)
{
if(m_pDlg->Get SafeHwnd( )==0)
{
m_pDlg->Create( );
}
CView::OnLButtonDown(nFlags,point);
}
LRESULT Projview::OnGoodbye(WPARAM wparam,LPARAM lparam)
{
m_pDlg->DestroyWindow( );
Return 0;
}

No comments:

Post a Comment