whluk
asked on
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(CGotmail 8_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::InitInstan ce()
{
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(CAboutDl g)
//}}AFX_DATA_INIT
}
//DEL void CAboutDlg::DoDataExchange( CDataExcha nge* pDX)
//DEL {
//DEL CDialog::DoDataExchange(pD X);
//DEL //{{AFX_DATA_MAP(CAboutDlg )
//DEL //}}AFX_DATA_MAP
//DEL }
BEGIN_MESSAGE_MAP(CAboutDl g, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CGotmail8_0Dlg dialog
CGotmail8_0Dlg::CGotmail8_ 0Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CGotmail8_0Dlg::ID D, pParent)
{
//{{AFX_DATA_INIT(CGotmail 8_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(CGotmail 8_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::DoDataExch ange(CData Exchange* pDX)
//DEL {
//DEL CDialog::DoDataExchange(pD X);
//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(CGotmail 8_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::OnInitDial og()
{
//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(ID S_ABOUTBOX );
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SE PARATOR);
pSysMenu->AppendMenu(MF_ST RING, 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::OnSysComma nd(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_ICONERASEBK GND, (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::OnQueryDra gIcon()
//DEL {
//DEL return (HCURSOR) m_hIcon;
//DEL }
//DEL void CGotmail8_0Dlg::OnLButtonD own(UINT nFlags, CPoint point)
//DEL {
//DEL
//DEL // TODO: Add your message handler code here and/or call default
//DEL CDialog::OnLButtonDown(nFl ags, 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(UI NT 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(nIDEven t);
CDialog::OnTimer(nIDEvent) ;
}
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(CGotmail
//{{AFX_MSG_MAP(CGotmail8_
// 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_
{
// 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::InitInstan
{
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(CAboutDl
//}}AFX_DATA_INIT
}
//DEL void CAboutDlg::DoDataExchange(
//DEL {
//DEL CDialog::DoDataExchange(pD
//DEL //{{AFX_DATA_MAP(CAboutDlg
//DEL //}}AFX_DATA_MAP
//DEL }
BEGIN_MESSAGE_MAP(CAboutDl
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// CGotmail8_0Dlg dialog
CGotmail8_0Dlg::CGotmail8_
: CDialog(CGotmail8_0Dlg::ID
{
//{{AFX_DATA_INIT(CGotmail
// 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_
}
CGotmail8_0Dlg::CGotmail8_
{
cho = choice;
//{{AFX_DATA_INIT(CGotmail
// 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_
}
//DEL void CGotmail8_0Dlg::DoDataExch
//DEL {
//DEL CDialog::DoDataExchange(pD
//DEL //{{AFX_DATA_MAP(CGotmail8
//DEL // NOTE: the ClassWizard will add DDX and DDV calls here
//DEL //}}AFX_DATA_MAP
//DEL }
BEGIN_MESSAGE_MAP(CGotmail
//{{AFX_MSG_MAP(CGotmail8_
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON2,
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// CGotmail8_0Dlg message handlers
BOOL CGotmail8_0Dlg::OnInitDial
{
//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(ID
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SE
pSysMenu->AppendMenu(MF_ST
}
}
// 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::OnSysComma
//DEL {
//DEL if ((nID & 0xFFF0) == IDM_ABOUTBOX)
//DEL {
//DEL CAboutDlg dlgAbout;
//DEL dlgAbout.DoModal();
//DEL }
//DEL else
//DEL {
//DEL CDialog::OnSysCommand(nID,
//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_ICONERASEBK
// 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(
//cho = 2;
// }
// else
// dc.TextOut(theRect.Height(
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::OnQueryDra
//DEL {
//DEL return (HCURSOR) m_hIcon;
//DEL }
//DEL void CGotmail8_0Dlg::OnLButtonD
//DEL {
//DEL
//DEL // TODO: Add your message handler code here and/or call default
//DEL CDialog::OnLButtonDown(nFl
//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(UI
{
// 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(nIDEven
CDialog::OnTimer(nIDEvent)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.