⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogprogress.cpp

📁 《Visual C++ 6.0实例教程》配套代码
💻 CPP
字号:
// DialogProgress.cpp : implementation file
//

#include "stdafx.h"
#include "Dialog.h"
#include "DialogProgress.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogProgress dialog


CDialogProgress::CDialogProgress(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogProgress::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogProgress)
	//}}AFX_DATA_INIT
}


void CDialogProgress::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogProgress)
	DDX_Control(pDX, IDC_PERCENT_SPIN, m_Spin);
	DDX_Control(pDX, IDC_TIME_SLIDER, m_Time);
	DDX_Control(pDX, IDC_PROGRESS, m_Progress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogProgress, CDialog)
	//{{AFX_MSG_MAP(CDialogProgress)
	ON_BN_CLICKED(IDC_PROGRESS_BUTTON, OnProgressButton)
	ON_BN_CLICKED(IDC_QUIT_BUTTON, OnQuitButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogProgress message handlers

BOOL CDialogProgress::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//给Spin控件设置数值范围
	m_Spin.SetRange(1,50);
	//把文本框的初始值设为1
	GetDlgItem(IDC_EDIT)->SetWindowText("1");

	m_Time.SetRange( 0, 10 );//设置滑动的数值范围
	m_Time.SetPos( 1 );//设滑动控件的初始值设为1
	
	m_Progress.SetRange( 0, 100 );//设进度条的数值范围
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogProgress::OnProgressButton() 
{
	// TODO: Add your control notification handler code here
	CString temp;

	//得到文本框中的内容
	GetDlgItem(IDC_EDIT)->GetWindowText(temp);

	//判断文本框中的内容是否在设定的范围之内
	if( (temp<"1") || (temp>"50") )
	{
		MessageBox("输入的数据超出范围!","Waring",MB_ICONWARNING|MB_OK);
		GetDlgItem(IDC_EDIT)->SetFocus();//把焦点设在文本框上
		return;//中断程序的运行,返回
	}

	int nPercent, nTime, nCurPos = 0;

	nPercent = m_Spin.GetPos();//得到Spin控件的值
	nTime = m_Time.GetPos();//得到滑动条上当前的值

	m_Progress.SetPos( 0 );//设置进度条当前的位置为0
	while( (nCurPos+=nPercent) < 100 )
	{
		m_Progress.OffsetPos( nPercent );//在进度条上偏移nPercent位置
		Sleep( 1000 * nTime / 10 );//延迟一定的时间间隔
	}
	m_Progress.SetPos( 100 );//设置进度条当前的位置为100
}

void CDialogProgress::OnQuitButton() 
{
	// TODO: Add your control notification handler code here
	OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -