Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest "Please Wait" dialog

Status
Not open for further replies.

ed9871

Programmer
Jan 15, 2002
14
0
0
US
I am fairly new to VC++ and need to pop up a small dialog when something is taking a few seconds. This is such a common thing I know it must be easy but I can't figure out the best way to do it. I have created the dialog and created a CDialog class for it. I can't use DoModal because I need to be able to close the dialog when my processing is done. I also want the "Please wait" dialog to be attached to the dialog that is currently being used in my MDI application. How should I do it?

Thanks,
Ed
 
I think that using the hourglass would be sufficient

BeginWaitCursor() and EndWaitCursor() will do that for you.

Matt
 
The following CBusyDlg serves your purpose. m_Msg links to the static text control in which you put your message.
The usage:
in your function:
{
....
CBusyDlg aDlg("This is a long process. Please wait...");
Your long process here ...

}
the busyDlg will automatically destroy itself when it goes out of the scope.

CBusyDlg.h:

class CBusyDlg : public CDialog
{
public:
virtual ~CBusyDlg();
CBusyDlg(CString szBuf="",CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CBusyDlg)
enum { IDD = IDD_BUSYDLG };
CString m_Msg;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBusyDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
};

CBusyDlg.cpp

#include "BusyDlg.h"
CBusyDlg::CBusyDlg(CString szBuf, CWnd* pParent /*=NULL*/)
: CDialog(CBusyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBusyDlg)
if (szBuf == "") m_Msg = _T("Please Wait ....");
else m_Msg = szBuf;
//}}AFX_DATA_INIT

Create(CBusyDlg::IDD,pParent);
}
void CBusyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBusyDlg)
DDX_Text(pDX, IDC_MSG, m_Msg);
//}}AFX_DATA_MAP
}

CBusyDlg::~CBusyDlg()
{
DestroyWindow();
}

 
That works except the message doesn't show up in my dialog, its just a blank square. I added

aDlg.ShowWindow(TRUE);

after the declaration in my function to get it to show. This is perfect as long as I can get the message to show up and also be able to move the box to the center of the MDI window. Did I skip something?

Ed
 
More info - calling DoModal on another dialog while my blank "please wait" dialog is up causes the message to display on my "please wait" dialog. Wierd...

Ed
 
Blank dialog:
Maybe you didn't set the "visible" style of the dialog through resource editor. You should do that.

Center window:
Override the WM_INITDIALOG message, add CenterWindow() in its handler.
 
Duh, I had the static control set to visible but not the dialog box itself.

Last question, can I attach the please wait dialog to my child window in my MDI app and not the main window? The effect I want is while the user is waiting, they can open another child window and do something else.

Thanks so much for your help, I am learning a lot with all this.

Ed
 
Center Window to your child window:
pass the pointer of your window (say pWnd)to your dialog class,

then CenterWindow(pWnd);

open another child window:

You had better create a new worker thread for your long process.
 
CenterWindow(pWnd) worked great, I will start a new thread for my please wait process. Thanks for all your help, I understand everything you've told me!

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top