I wrote a simple program to test out the progress bar functionality. I'm having an issue, though. If I run the .exe (included in my attachment), the application gives the (Not Responding) message and the progress bar disappears. This only happens if I try to click on the window to move it, or if I switch to another Window and it has to redraw.
One method around this is to use the Hide() and Show() commands each time it refreshes, but that causes unwanted side effects like making it difficult to switch between windows or having the progressbar application flash on the screen in a strobe-like fashion. Is there something I am doing wrong?
Included is the release version of the example app and the source code in c++ for further help.
Please let me know if you know what I am doing wrong.
Here is the code being used:
Form1.h
progressBar.cpp
Also found at TSF: http://www.techsupportforum.com/for...-moved-or-loses-focus-669221.html#post3904888
One method around this is to use the Hide() and Show() commands each time it refreshes, but that causes unwanted side effects like making it difficult to switch between windows or having the progressbar application flash on the screen in a strobe-like fashion. Is there something I am doing wrong?
Included is the release version of the example app and the source code in c++ for further help.
Please let me know if you know what I am doing wrong.
Here is the code being used:
Form1.h
C++:
#pragma once
namespace progressBar {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::ProgressBar^ progressBar1;
protected:
public: System::Windows::Forms::Label^ label1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->label1 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point(41, 119);
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(199, 23);
this->progressBar1->TabIndex = 0;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->ForeColor = System::Drawing::Color::Red;
this->label1->Location = System::Drawing::Point(64, 91);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(153, 20);
this->label1->TabIndex = 1;
this->label1->Text = L"Progress Bar Test";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->label1);
this->Controls->Add(this->progressBar1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
};
}
progressBar.cpp
C++:
// progressBar.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
#include <sstream>
#include <string>
using namespace progressBar;
using namespace std;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Form1^ myProgress = gcnew Form1();
myProgress->Show();
myProgress->progressBar1->Maximum = 10000000;
for(int i = 0; i < 10000000; i++){
myProgress->label1->ForeColor = System::Drawing::Color::Black;
String^ str;
stringstream sstemp;
sstemp << "Running "<< i + 1 << " of 10000000";
string stringstore;
stringstore = sstemp.str();
str = gcnew String(stringstore.c_str());
if(i%10000 == 0){
myProgress->label1->Text = str;
myProgress->progressBar1->Value = i;
myProgress->Refresh();
}
}
return 0;
}
Also found at TSF: http://www.techsupportforum.com/for...-moved-or-loses-focus-669221.html#post3904888
Attachments
Last edited: