void CProgressDlg::UpdatePercentText() //上面是进度条的设置
{
int nPos=m_Progress.GetPos();
int nLow,nUp;
m_Progress.GetRange(nLow,nUp);
m_strPercent.Format("%4.0f%",(float)nPos/(float)(nUp-nLow)*100.0);
UpdateData(FALSE);
}BOOL CProgressDlg::OnInitDialog()
{
CDialog::OnInitDialog(); m_Progress.SetRange(0,100);
m_Progress.SetStep(5);
m_Progress.SetPos(30);
UpdatePercentText();
// TODO: Add extra initialization herereturn TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
{
int nPos=m_Progress.GetPos();
int nLow,nUp;
m_Progress.GetRange(nLow,nUp);
m_strPercent.Format("%4.0f%",(float)nPos/(float)(nUp-nLow)*100.0);
UpdateData(FALSE);
}BOOL CProgressDlg::OnInitDialog()
{
CDialog::OnInitDialog(); m_Progress.SetRange(0,100);
m_Progress.SetStep(5);
m_Progress.SetPos(30);
UpdatePercentText();
// TODO: Add extra initialization herereturn TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
解决方案 »
- 请教在VC++2005中如何读取一个EXCEL文件中的数据
- 关于ActiveX不能在客户端正确显示的问题,希望你帮我解答下,谢谢!
- 妄想花100积分就能解决无数Money才能解决的问题?
- 如何动态改变控件大小,请高手指教
- ======= 800分,或者如何实现MainFram无标题但其任务栏有标题?======
- ???如何在DialogBar上画菜单
- 类似360手机管家窗体最大化后,拖动复原是怎么做出的呀?
- 怎样设置属性表(CPropertySheet)的大小
- 在VC中,将十进制的数据转化为十六进制的数据该调用什么函数?谢谢!
- 关于VC 调用Excel的问题!
- 动态DLL改写成静态Lib问题
- 获取的是哪个窗口的矩形尺寸?
可以启动一个定时器,在定时器里StepIt,时间长的操作用后台线程来完成
加定时器了吗?
int nPos=m_Progress.GetPos();
int nLow,nUp;
m_Progress.GetRange(nLow,nUp);
m_strPercent.Format("%4.0f%",(float)nPos/(float)(nUp-nLow)*100.0);
UpdateData(FALSE);我是一点也不懂啊,编译没有错误,就是不显示
void CProgressDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(m_Progress.GetPos()==100)
KillTimer(1);
m_Progress.StepIt();
CDialog::OnTimer(nIDEvent);
}
//给CProgressDlg加一个WM_TIMER消息响应函数OnTimer(UINT nIDEvent),再在OnTimer函数中调用UpdatePercentText
BOOL CProgressDlg::OnInitDialog()
{
CDialog::OnInitDialog(); m_Progress.SetRange(0,100);
m_Progress.SetStep(5);
m_Progress.SetPos(30);
m_Progress.SetTimer(1,1000,0);
UpdatePercentText();
return TRUE;
}
在OnInitDialog函数中调用SetTimer(1,1000,0)编译没有出错误,就好似进度条那个对话框根本没有出来,
我的目的就是在我的一个文件转换程序里加上进度条来显示进度,现在是文件能转换,就是没有弹出进度条,刚接触VC不到一个月,请多多指教。
另外可打断点看看程序进入OnTimer函数中没有
改为 m_Progress.SetTimer(1,1000,0);
SetTimer(1,1000,0);
就可以看到效果了
#include "stdafx.h"
#include "Test2.h"
#include "TestDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
struct Mydata{char time[16];char value[16];};
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
m_strPercent = _T("");
//}}AFX_DATA_INIT
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
DDX_Text(pDX, IDC_STATIC_TEXT, m_strPercent);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlersvoid CTestDlg::OnOK()
{
// TODO: Add extra validation here
CFile m_File;
CFileDialog dlg(TRUE,0,0,0,"XML Files(*.xml)|*.xml|All Files(*.*)|*.*||");
if (dlg.DoModal()!=IDOK)
return;
if ( !m_File.Open( dlg.GetPathName(), CFile::modeRead) ){
MessageBox("无法打开文件");
return;
CDialog::OnOK();
}
int i,j;
int length,num,location_temp1,location_temp2,location_temp3,location_temp4;
int location_Power_start,location_Power_end;
int location_WindSpeed_start,location_WindSpeed_end;
int location_Rpm_start,location_Rpm_end;
int location_Torque_start,location_Torque_end;
length=m_File.GetLength();
char* c=new char[length+1]; m_File.Read(c,length);
c[length]=0;
CString str(c);
m_File.Close();
delete c; location_Power_start = str.Find("AI_GridRealPower" , 0);
location_WindSpeed_start = str.Find("AI_WindSpeed" , 0);
location_Rpm_start = str.Find("V_GeneratorRpm1Sec" , 0);
location_Torque_start = str.Find("V_TorqueSPNm" , 0);
location_Power_start = str.Find("<valueitem" , location_Power_start);
location_Power_end = str.Find("</channel>" , location_Power_start);
location_WindSpeed_start = str.Find("<valueitem" , location_WindSpeed_start);
location_WindSpeed_end = str.Find("</channel>" , location_WindSpeed_start); location_Rpm_start = str.Find("<valueitem" , location_Rpm_start);
location_Rpm_end = str.Find("</channel>" , location_Rpm_start); location_Torque_start = str.Find("<valueitem" , location_Torque_start);
location_Torque_end = str.Find("</channel>" , location_Torque_start);
CString str_Power(str.Mid(location_Power_start , location_Power_end - location_Power_start));
CString str_WindSpeed(str.Mid(location_WindSpeed_start , location_WindSpeed_end - location_WindSpeed_start));
CString str_Rpm(str.Mid(location_Rpm_start , location_Rpm_end - location_Rpm_start));
CString str_Torque(str.Mid(location_Torque_start , location_Torque_end - location_Torque_start));
for(num=0,location_temp1=0; ;num++,location_temp1++){
location_temp1=str_Power.Find('<',location_temp1);
if(location_temp1==-1)
break;
}
struct Mydata *Power,*Power1,*WindSpeed,*WindSpeed1,*Rpm,*Rpm1,*Torque,*Torque1;
Power1 = Power = new Mydata[num];
WindSpeed1 = WindSpeed = new Mydata[num];
Rpm1 = Rpm = new Mydata[num];
Torque1 = Torque = new Mydata[num];
location_temp1 = 0;
location_temp2 = 0;
location_temp3 = 0;
location_temp4 = 0; for(i=0;i<num;i++,Power1++){
location_temp1 = str_Power.Find('<' , location_temp4);
location_temp4 = str_Power.Find('>' , location_temp1);
location_temp2 = str_Power.Find('"' , location_temp1) + 1;
location_temp3 = str_Power.Find('"' , location_temp2 + 1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Power1->time , str_Power.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Power1->time[j]=' ';
}
location_temp2 = str_Power.Find('"' , location_temp3+2) + 1;
location_temp3 = str_Power.Find('"' , location_temp2+1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Power1->value , str_Power.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Power1->value[j]=' ';
}
}
location_temp1 = 0;
location_temp2 = 0;
location_temp3 = 0;
location_temp4 = 0; for(i=0;i<num;i++,WindSpeed1++){
location_temp1 = str_WindSpeed.Find('<' , location_temp4);
location_temp4 = str_WindSpeed.Find('>' , location_temp1);
location_temp2 = str_WindSpeed.Find('"' , location_temp1) + 1;
location_temp3 = str_WindSpeed.Find('"' , location_temp2 + 1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(WindSpeed1->time , str_WindSpeed.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
WindSpeed1->time[j]=' ';
}
location_temp2 = str_WindSpeed.Find('"' , location_temp3+2) + 1;
location_temp3 = str_WindSpeed.Find('"' , location_temp2+1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(WindSpeed1->value , str_WindSpeed.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
WindSpeed1->value[j]=' ';
}
}
location_temp1 = 0;
location_temp2 = 0;
location_temp3 = 0;
location_temp4 = 0; for(i=0;i<num;i++,Rpm1++){
location_temp1 = str_Rpm.Find('<' , location_temp4);
location_temp4 = str_Rpm.Find('>' , location_temp1);
location_temp2 = str_Rpm.Find('"' , location_temp1) + 1;
location_temp3 = str_Rpm.Find('"' , location_temp2 + 1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Rpm1->time , str_Rpm.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Rpm1->time[j]=' ';
}
location_temp2 = str_Rpm.Find('"' , location_temp3+2) + 1;
location_temp3 = str_Rpm.Find('"' , location_temp2+1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Rpm1->value , str_Rpm.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Rpm1->value[j]=' ';
}
}
location_temp1 = 0;
location_temp2 = 0;
location_temp3 = 0;
location_temp4 = 0; for(i=0;i<num;i++,Torque1++){
location_temp1 = str_Torque.Find('<' , location_temp4);
location_temp4 = str_Torque.Find('>' , location_temp1);
location_temp2 = str_Torque.Find('"' , location_temp1) + 1;
location_temp3 = str_Torque.Find('"' , location_temp2 + 1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Torque1->time , str_Torque.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Torque1->time[j]=' ';
}
location_temp2 = str_Torque.Find('"' , location_temp3+2) + 1;
location_temp3 = str_Torque.Find('"' , location_temp2+1) - 1;
if((location_temp2<location_temp4)&(location_temp3<location_temp4)){
strcpy(Torque1->value , str_Torque.Mid(location_temp2 , 16));
for(j=location_temp3-location_temp2+1;j<16;j++)
Torque1->value[j]=' ';
}
}
CString str1;
str1.Format("转换完成,提取了%d个数据",num);
MessageBox(str1); CFileDialog dlg1(FALSE,"csv",0,OFN_OVERWRITEPROMPT,"CSV Files(*.csv)|*.csv|All Files(*.*)|*.*||");
if (dlg1.DoModal()!=IDOK){
//delete Power,WindSpeed,Rpm,Torque;
return;
}
if ( !m_File.Open( dlg1.GetPathName(), CFile::modeCreate | CFile::modeWrite) ){
MessageBox("无法保存文件");
//delete Power,WindSpeed,Rpm,Torque;
return;
}
i=0;
Power1 = Power;
WindSpeed1 = WindSpeed;
Rpm1 = Rpm;
Torque1 = Torque;
#define TITLE "Time,Grid Real Power(KW),Wind speed(m/s),Gen. rpm(RPM),Torque(Nm)\r\n"
m_File.Write(TITLE,strlen(TITLE));
while(i<num){
m_File.Write(Power1->time,16);
m_File.Write(",",1);
m_File.Write(Power1->value,16);
m_File.Write(",",1);
m_File.Write(WindSpeed1->value,16);
m_File.Write(",",1);
m_File.Write(Rpm1->value,16);
m_File.Write(",",1);
m_File.Write(Torque1->value,16);
m_File.Write("\r\n",2);
i++;
Power1++;
WindSpeed1++;
Rpm1++;
Torque1++;
}
m_File.Close();
}
void CTestDlg::UpdatePercentText()
{
int nPos=m_Progress.GetPos();
int nLow,nUp;
m_Progress.GetRange(nLow,nUp);
m_strPercent.Format("%4.0f%",(float)nPos/(float)(nUp-nLow)*100.0);
UpdateData(FALSE);
}CScrollBar* CTestDlg::GetScrollBarCtrl(int nBar) const
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::GetScrollBarCtrl(nBar);
}BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_Progress.SetRange(0,100);
m_Progress.SetStep(5);
m_Progress.SetPos(30);
SetTimer(1,1000,0);
UpdatePercentText();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CTestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(m_Progress.GetPos()==100)
KillTimer(1);
UpdatePercentText();
CDialog::OnTimer(nIDEvent);
}