分享
 
 
 

一个多线程的进度对话框源代码

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

// ProgDlg.h : header file

// CG: This file was added by the Progress Dialog component

/////////////////////////////////////////////////////////////////////////////

// CProgressDlg dialog

#ifndef __PROGDLG_H__

#define __PROGDLG_H__

#include "resource.h" //LT

class CProgressDlg : public CDialog

{

// Construction / Destruction

public:

CProgressDlg(UINT nCaptionID = 0); // standard constructor

~CProgressDlg();

BOOL Create(CWnd *pParent=NULL);

// Progress Dialog manipulation

void SetStatus(LPCTSTR lpszMessage);

void SetRange(int nLower,int nUpper);

int SetStep(int nStep);

int SetPos(int nPos);

int OffsetPos(int nPos);

int StepIt();

// Dialog Data

//{{AFX_DATA(CProgressDlg)

enum { IDD = CG_IDD_PROGRESS };

CAnimateCtrl m_Trans_AnimateCtrl;

CProgressCtrl m_Progress;

//}}AFX_DATA

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CProgressDlg)

public:

virtual BOOL DestroyWindow();

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL

// Implementation

protected:

UINT m_nCaptionID;

int m_nLower;

int m_nUpper;

int m_nStep;

BOOL m_bParentDisabled;

void ReEnableParent();

virtual void OnCancel();

virtual void OnOK() {};

void UpdatePercent(int nCurrent);

void PumpMessages();

// Generated message map functions

//{{AFX_MSG(CProgressDlg)

virtual BOOL OnInitDialog();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

#endif // __PROGDLG_H__

// ProgDlg.cpp : implementation file

// CG: This file was added by the Progress Dialog component

#include "stdafx.h"

#include "resource.h"

#include "ProgDlg.h"

#ifdef _DEBUG

#undef THIS_FILE

static char BASED_CODE THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CProgressDlg dialog

CProgressDlg::CProgressDlg(UINT nCaptionID)

{

m_nCaptionID = CG_IDS_PROGRESS_CAPTION;

if (nCaptionID != 0)

m_nCaptionID = nCaptionID;

m_nLower=0;

m_nUpper=100;

m_nStep=10;

//{{AFX_DATA_INIT(CProgressDlg)

// NOTE: the ClassWizard will add member initialization here

//}}AFX_DATA_INIT

m_bParentDisabled = FALSE;

}

CProgressDlg::~CProgressDlg()

{

if(m_hWnd!=NULL)

DestroyWindow();

}

BOOL CProgressDlg::DestroyWindow()

{

ReEnableParent();

return CDialog::DestroyWindow();

}

void CProgressDlg::ReEnableParent()

{

if(m_bParentDisabled && (m_pParentWnd!=NULL))

m_pParentWnd->EnableWindow(TRUE);

m_bParentDisabled=FALSE;

}

BOOL CProgressDlg::Create(CWnd *pParent)

{

// Get the true parent of the dialog

m_pParentWnd = CWnd::GetSafeOwner(pParent);

// m_bParentDisabled is used to re-enable the parent window

// when the dialog is destroyed. So we don't want to set

// it to TRUE unless the parent was already enabled.

if((m_pParentWnd!=NULL) && m_pParentWnd->IsWindowEnabled())

{

m_pParentWnd->EnableWindow(FALSE);

m_bParentDisabled = TRUE;

}

if(!CDialog::Create(CProgressDlg::IDD,pParent))

{

ReEnableParent();

return FALSE;

}

return TRUE;

}

void CProgressDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CProgressDlg)

DDX_Control(pDX, IDC_TRANS_ANIMATE, m_Trans_AnimateCtrl);

DDX_Control(pDX, CG_IDC_PROGDLG_PROGRESS, m_Progress);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CProgressDlg, CDialog)

//{{AFX_MSG_MAP(CProgressDlg)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

void CProgressDlg::SetStatus(LPCTSTR lpszMessage)

{

ASSERT(m_hWnd); // Don't call this _before_ the dialog has

// been created. Can be called from OnInitDialog

CWnd *pWndStatus = GetDlgItem(CG_IDC_PROGDLG_STATUS);

// Verify that the static text control exists

ASSERT(pWndStatus!=NULL);

pWndStatus->SetWindowText(lpszMessage);

}

void CProgressDlg::OnCancel()

{

}

void CProgressDlg::SetRange(int nLower,int nUpper)

{

m_nLower = nLower;

m_nUpper = nUpper;

m_Progress.SetRange((short)nLower,(short)nUpper);

}

int CProgressDlg::SetPos(int nPos)

{

PumpMessages();

int iResult = m_Progress.SetPos(nPos);

UpdatePercent(nPos);

return iResult;

}

int CProgressDlg::SetStep(int nStep)

{

m_nStep = nStep; // Store for later use in calculating percentage

return m_Progress.SetStep(nStep);

}

int CProgressDlg::OffsetPos(int nPos)

{

PumpMessages();

int iResult = m_Progress.OffsetPos(nPos);

UpdatePercent(iResult+nPos);

return iResult;

}

int CProgressDlg::StepIt()

{

PumpMessages();

int iResult = m_Progress.StepIt();

UpdatePercent(iResult+m_nStep);

return iResult;

}

void CProgressDlg::PumpMessages()

{

// Must call Create() before using the dialog

ASSERT(m_hWnd!=NULL);

MSG msg;

// Handle dialog messages

while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

{

if(!IsDialogMessage(&msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

}

void CProgressDlg::UpdatePercent(int nNewPos)

{

CWnd *pWndPercent = GetDlgItem(CG_IDC_PROGDLG_PERCENT);

int nPercent;

int nDivisor = m_nUpper - m_nLower;

ASSERT(nDivisor>0); // m_nLower should be smaller than m_nUpper

int nDividend = (nNewPos - m_nLower);

ASSERT(nDividend>=0); // Current position should be greater than m_nLower

nPercent = nDividend * 100 / nDivisor;

// Since the Progress Control wraps, we will wrap the percentage

// along with it. However, don't reset 100% back to 0%

if(nPercent!=100)

nPercent %= 100;

// Display the percentage

CString strBuf;

strBuf.Format(_T("%d%c"),nPercent,_T('%'));

CString strCur; // get current percentage

pWndPercent->GetWindowText(strCur);

if (strCur != strBuf)

pWndPercent->SetWindowText(strBuf);

}

/////////////////////////////////////////////////////////////////////////////

// CProgressDlg message handlers

BOOL CProgressDlg::OnInitDialog()

{

CDialog::OnInitDialog();

m_Progress.SetRange((short)m_nLower,(short)m_nUpper);

m_Progress.SetStep(m_nStep);

m_Progress.SetPos(m_nLower);

// CString strCaption;

// VERIFY(strCaption.LoadString(m_nCaptionID));

// SetWindowText(strCaption);

m_Trans_AnimateCtrl.Open("filemove.avi");

return TRUE;

}

调用方法:

在需要使用的文件中#include"ProgDlg.h"

CProgressDlg progressdlg;//定义变量

progressdlg.Create(NULL);//初始化

progressdlg.SetRange(0,200);//设定进度条起点和终点范围

progressdlg.SetPos(0);//设定进度条起点位置

progressdlg.SetStep(1);//设定进度条每步进度

progressdlg.SetStatus("提示信息");

progressdlg.StepIt();//进度条前进一步

progressdlg.SetWindowText("对话框标题");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有