kinky code!

Who can help me resolve this kinky code?
What I am trying to do is to set up
3 dialogs displayed one after one.
The first one is to say "You've got mail", after the user clicks ok, the second dialog appears, then waiting for 5 seconds, the third one appears..
thx
jacky


// gotmail8_0.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "gotmail8_0.h"
#include "gotmail8_0Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGotmail8_0App

BEGIN_MESSAGE_MAP(CGotmail8_0App, CWinApp)
      //{{AFX_MSG_MAP(CGotmail8_0App)
            // NOTE - the ClassWizard will add and remove mapping macros here.
            //    DO NOT EDIT what you see in these blocks of generated code!
      //}}AFX_MSG
      ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGotmail8_0App construction

CGotmail8_0App::CGotmail8_0App()
{
      // TODO: add construction code here,
      // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CGotmail8_0App object

CGotmail8_0App theApp;

/////////////////////////////////////////////////////////////////////////////
// CGotmail8_0App initialization

BOOL CGotmail8_0App::InitInstance()
{
      AfxEnableControlContainer();

      // Standard initialization
      // If you are not using these features and wish to reduce the size
      //  of your final executable, you should remove from the following
      //  the specific initialization routines you do not need.

#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif
   
    CGotmail8_0Dlg dlg, dlg2, dlg3;
///      CAboutDlg about1;
      m_pMainWnd = &dlg;
//      dlg.DoModal();
//      dlg.KillTimer(1);
      //exit(0);
      //int nResponse = dlg.DoModal();
      if (dlg.DoModal() == IDOK)
      {
            m_pMainWnd = &dlg2;
            if (dlg2.DoModal() == IDOK) {
                  m_pMainWnd = &dlg3;
                  if (dlg3.DoModal() == IDOK) {
                        exit(0);
                  }

            }
                  
      }
      


      
      // Since the dialog has been closed, return FALSE so that we exit the
      //  application, rather than start the application's message pump.
      return FALSE;
}


// gotmail8_0Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "gotmail8_0.h"
#include "gotmail8_0Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
      CAboutDlg();

// Dialog Data
      //{{AFX_DATA(CAboutDlg)
      enum { IDD = IDD_ABOUTBOX };
      //}}AFX_DATA

      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CAboutDlg)
      protected:
      //}}AFX_VIRTUAL

// Implementation
protected:
      //{{AFX_MSG(CAboutDlg)
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
      //{{AFX_DATA_INIT(CAboutDlg)
      //}}AFX_DATA_INIT
}

//DEL void CAboutDlg::DoDataExchange(CDataExchange* pDX)
//DEL {
//DEL       CDialog::DoDataExchange(pDX);
//DEL       //{{AFX_DATA_MAP(CAboutDlg)
//DEL       //}}AFX_DATA_MAP
//DEL }

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
      //{{AFX_MSG_MAP(CAboutDlg)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGotmail8_0Dlg dialog

CGotmail8_0Dlg::CGotmail8_0Dlg(CWnd* pParent /*=NULL*/)
      : CDialog(CGotmail8_0Dlg::IDD, pParent)
{
 
      //{{AFX_DATA_INIT(CGotmail8_0Dlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CGotmail8_0Dlg::CGotmail8_0Dlg(int choice/*=NULL*/)
 
{
    cho = choice;
      //{{AFX_DATA_INIT(CGotmail8_0Dlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


//DEL void CGotmail8_0Dlg::DoDataExchange(CDataExchange* pDX)
//DEL {
//DEL       CDialog::DoDataExchange(pDX);
//DEL       //{{AFX_DATA_MAP(CGotmail8_0Dlg)
//DEL             // NOTE: the ClassWizard will add DDX and DDV calls here
//DEL       //}}AFX_DATA_MAP
//DEL }

BEGIN_MESSAGE_MAP(CGotmail8_0Dlg, CDialog)
      //{{AFX_MSG_MAP(CGotmail8_0Dlg)
      ON_WM_PAINT()
      ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
      ON_WM_TIMER()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGotmail8_0Dlg message handlers

BOOL CGotmail8_0Dlg::OnInitDialog()
{
      //CDialog::OnInitDialog();
      SetTimer(1,5000,NULL);

      // Add "About..." menu item to system menu.

      // IDM_ABOUTBOX must be in the system command range.
      ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
      ASSERT(IDM_ABOUTBOX < 0xF000);

      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
            CString strAboutMenu;
            strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
            }
      }

      // Set the icon for this dialog.  The framework does this automatically
      //  when the application's main window is not a dialog
      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon
      
      // TODO: Add extra initialization here
      
      return TRUE;  // return TRUE  unless you set the focus to a control
}


//DEL void CGotmail8_0Dlg::OnSysCommand(UINT nID, LPARAM lParam)
//DEL {
//DEL       if ((nID & 0xFFF0) == IDM_ABOUTBOX)
//DEL       {
//DEL             CAboutDlg dlgAbout;
//DEL             dlgAbout.DoModal();
//DEL       }
//DEL       else
//DEL       {
//DEL             CDialog::OnSysCommand(nID, lParam);
//DEL       }
//DEL }

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGotmail8_0Dlg::OnPaint()
{
//      CAboutDlg aDialog;
//      aDialog.DoModal();
//      aDialog.DoModal();


      if (IsIconic())
      {
            CPaintDC dc(this); // device context for painting

            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

            // Center icon in client rectangle
            int cxIcon = GetSystemMetrics(SM_CXICON);
            int cyIcon = GetSystemMetrics(SM_CYICON);
            CRect rect;
            GetClientRect(&rect);
            int x = (rect.Width() - cxIcon + 1) / 2;
            int y = (rect.Height() - cyIcon + 1) / 2;

            // Draw the icon
            dc.DrawIcon(x, y, m_hIcon);
      }
      else
      {
       CPaintDC dc(this);
    CFont fnt;
      CRect theRect;
      //dc.settextcolor (0x00ff0000);
      dc.SetTextColor ( 0x000000ff);
      dc.SetBkMode ( TRANSPARENT );
    fnt.CreatePointFont(300, _T("Arial"));

      GetClientRect(&theRect);
      //int2 x = (rect.Width() - cxIcon + 1) / 2;
    //int2 y = (rect.Height() - cyIcon + 1) / 2;
      //CPoint aPoint = theRect.CenterPoint();
    CFont *pOldFont = dc.SelectObject(&fnt);
//      if (choice == 1)//
      //if (cho == 1){
     dc.TextOut(theRect.Height()/4+30, theRect.Width()/4-20, CString(_T("You've got mail")));
       //cho = 2;
//      }
//      else
//       dc.TextOut(theRect.Height()/4+30, theRect.Width()/4-20, CString(_T("Save the Planet")));
    dc.SelectObject(pOldFont);
      CDialog::OnPaint();
      }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
//DEL HCURSOR CGotmail8_0Dlg::OnQueryDragIcon()
//DEL {
//DEL       return (HCURSOR) m_hIcon;
//DEL }

//DEL void CGotmail8_0Dlg::OnLButtonDown(UINT nFlags, CPoint point)
//DEL {
//DEL    
//DEL       // TODO: Add your message handler code here and/or call default
//DEL       CDialog::OnLButtonDown(nFlags, point);
//DEL }

 

 

void CGotmail8_0Dlg::OnButton2()
{
      OnOK();
      //EndDialog(0);
      //CGotmail8_0Dlg wer = new CGotmail8_0Dlg(1);
      //if (wer.DoModal() == IDOK)
      //{
      //OnOK();
//      }
//      CGotmail8_0Dlg poi = new CGotmail8_0Dlg(2);
//      if (poi.DoModal() == IDOK)
//      {
//      OnOK();
//      }
//      exit(0);
//      SetTimer(1,5000,NULL);
      //CGotmail8_0Dlg poi;
      //poi.DoModal();
      //poi.EndDialog(0);
      //exit(0);
      //PostMessage(WM_TIMER,0,0);
   // TODO: Add your control notification handler code here
//   exit(0);       
}

//DEL void CAboutDlg::OnTimer(UINT nIDEvent)
//DEL {
//DEL       // TODO: Add your message handler code here and/or call default
//DEL       
//DEL       CDialog::OnTimer(nIDEvent);
//DEL }

void CGotmail8_0Dlg::OnTimer(UINT nIDEvent)
{
      // TODO: Add your message handler code here and/or call default
//            static int count123 = 1;
      // TODO: Add your message handler code here and/or call default
      EndDialog(1);
      
      //if (nIDEvent == 1) {
//      EndDialog(1);
 //      CGotmail8_0Dlg dlg2;
//      dlg2.DoModal();
//      EndDialog(1);      
//      KillTimer(1);
//      exit(0);
//      } else if (nIDEvent == 2) {
//      EndDialog(2);      
 //      CGotmail8_0Dlg efg;
   // efg.DoModal();
      //KillTimer(2);
//      exit(0);
//}
//      EndDialog(1);
//      count123++;
      //CDialog::OnTimer(nIDEvent);

      CDialog::OnTimer(nIDEvent);
}
whlukAsked:
Who is Participating?
 
inprasConnect With a Mentor Commented:
Hi
Have a variable in dialog class like
m_bSetTimer
dlg.m_bSetTimer = FALSE;
if (dlg.DoModal() == IDOK)
{
dlg.m_bSetTimer = TRUE;
m_pMainWnd = &dlg2;
if (dlg2.DoModal() == IDOK) {
dlg.m_bSetTimer = FALSE;
m_pMainWnd = &dlg3;
if (dlg3.DoModal() == IDOK) {
exit(0);
}
}

in OnIntDailog change UR code to

if (m_bSetTimer)
SetTimer(1,5000,NULL);


Hope this helps
0
All Courses

From novice to tech pro — start learning today.