如何在VC ++ MFC中添加ProgressBar? [英] How to add ProgressBar in VC++ MFC ?

查看:308
本文介绍了如何在VC ++ MFC中添加ProgressBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在处理线程中的某些方法的阶段添加ProgressBar.

How to add ProgressBar at the stage of Processing some methods in Thread.

我想在处理时显示正在加载的图像,这就是为什么我需要在运行线程时添加进度栏.

i want to show loading image while processing that's why i need to add progress bar while running the thread.

当我单击开始按钮时,线程将启动(这时我想在屏幕中央显示进度条.就像Visual Studio打开一样,它会显示带有进度条和一些文本的矩形框).

when i click the start button the Thread will start (at this time i want to show progress bar at center of the screen. just like Visual Studio opening it'll show rectangular box with progress bar and some text).

如何实现..

推荐答案

您可以创建一个对话框来承载进度条.您可以使用一些全局变量来使进度控件与您的工作线程相关联.我制作了一个示例来创建进度条.

You can create a dialog to host a progress bar. You could use some global variables to make the progress control associated with your worker thread. I make a sample to create that progress bar.

void CMyDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialogEx::OnShowWindow(bShow, nStatus);
	m_progress.SetRange(0, 100);

	m_progress.SetPos(0);

	m_progress.SetStep(1);
	this->KillTimer(1);
	this->SetTimer(1, 20, NULL);
	
	// TODO: Add your message handler code here
}

处理计时器:

void CMyDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	CDialogEx::OnTimer(nIDEvent);
	

	for (int i = 1; i <= 100; i++)
	{
	Sleep(50);
	m_progress.SetPos(i);

	}

	this->EndDialog(true);
}

在上面的代码中,您可以将"i"(m_progress.SetPos(i))的值更改为工作线程中使用的全局变量.

In above code, you could change the value of "i"(m_progress.SetPos(i) ) to a global variable which used in your worker thread.

this->KillTimer(1);//kill the timer

检查屏幕截图:

希望这对您有所帮助.


这篇关于如何在VC ++ MFC中添加ProgressBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆