Knowledge Base Nr: 00320 progressdlg.cpp - http://www.swe-kaiser.de

Downloads:

MFC: progress dialog, fortschrittsanzeige mittels nicht-modalem dialog

  
################ sample

CProgressDlg dlg(theApp.Translate(L"Raster wird geladen ..."), L"");
dlg.Create();

for (...)
{
dlg.SetText(sProdLine + L" " + arCmpnntSize[c]);
...
}

################ definition

class CProgressDlg : public CDialog
{
DECLARE_DYNAMIC(CProgressDlg)

public:
CProgressDlg(const CString sTitle, const CString sInitText, CWnd* pParent = NULL); // Standardkonstruktor
virtual ~CProgressDlg();

BOOL Create();
void SetText(const CString sText);

// Dialogfelddaten
enum { IDD = IDD_PROGRESSDIALOG };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung

CString m_sTitle, m_sInitText;

DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
};

################ implementation

#include "stdafx.h"
#include "ProgressDlg.h"

IMPLEMENT_DYNAMIC(CProgressDlg, CDialog)

CProgressDlg::CProgressDlg(const CString sTitle, const CString sInitText, CWnd* pParent /*=NULL*/)
: CDialog(CProgressDlg::IDD, pParent)
{
m_sTitle = sTitle;
m_sInitText = sInitText;
}

CProgressDlg::~CProgressDlg()
{
}

BOOL CProgressDlg::Create()
{
BOOL ok = CDialog::Create(CProgressDlg::IDD);

if (ok)
ShowWindow(SW_SHOW);

return ok;
}

void CProgressDlg::SetText(const CString sText)
{
GetDlgItem(IDC_TEXT)->SetWindowText(sText);
}

void CProgressDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CProgressDlg, CDialog)
END_MESSAGE_MAP()


// CProgressDlg-Meldungshandler

BOOL CProgressDlg::OnInitDialog()
{
CDialog::OnInitDialog();

SetWindowText(m_sTitle);
GetDlgItem(IDC_TEXT)->SetWindowText(m_sInitText);

return TRUE; // return TRUE unless you set the focus to a control
// AUSNAHME: OCX-Eigenschaftenseite muss FALSE zurückgeben.
}