473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Displaying progressbar using threading in win 32 applicaition!

In my application I have a simple module were I will read files for some process that will take
few seconds..so I thought of displaying a progress bar(using worker thread) while the files are in progress.I have created a thread (code shown below) and also I designed a dialog window with progress control.I used the function MyThreadFunction below to display the progressbar but it just shows only one time and disappears,I am not sure how to make it work.I tried my best inspite of the fact that I am new to threading.



Expand|Select|Wrap|Line Numbers
  1. reading files
  2.     void ReadMyFiles()
  3.     {
  4.  
  5.       for(int i = 0; i < fileCount ; fileCount++)
  6.       {  
  7.       CWinThread* myThread = AfxBeginThread((AFX_THREADPROC)MyThreadFunction,NULL);
  8.       tempState = *(checkState + index);
  9.       if(tempCheckState == NOCHECKBOX)
  10.       {
  11.         //my operations
  12.       }
  13.       else//CHECKED or UNCHECKED
  14.       {
  15.         //myoperation
  16.       }
  17.       myThread->PostThreadMessage(WM_QUIT,NULL,NULL);
  18.       }
  19.     }
thread functions
Expand|Select|Wrap|Line Numbers
  1.     UINT MyThreadFunction(LPARAM lparam)
  2.     {
  3.       HWND dialogWnd = CreateWindowEx(0,WC_DIALOG,L"Proccessing...",WS_OVERLAPPEDWINDOW|WS_VISIBLE,
  4.               600,300,280,120,NULL,NULL,NULL,NULL);
  5.       HWND pBarWnd = CreateWindowEx(NULL,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE|PBS_MARQUEE,40,20,200,20,
  6.                   dialogWnd,(HMENU)IDD_PROGRESS,NULL,NULL);
  7.  
  8.       MSG msg;
  9.  
  10.       PostMessage( pBarWnd, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
  11.       PostMessage(pBarWnd,PBM_SETPOS,0,0);
  12.       while(PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
  13.       {
  14.         if(msg.message == WM_QUIT)
  15.         {
  16.           DestroyWindow(dialogWnd);
  17.           return 1;
  18.         }
  19.         AfxGetThread()->PumpMessage();
  20.         Sleep(40);
  21.       }
  22.       return 1;
  23.  
  24.  
  25.     }
  26.  
Apr 27 '10 #1
0 1251

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stuart Norris | last post by:
Dear Group, I am attempting to write a "splash" and "status" Form using a second thread. I wish to use this Form to display status information to the user when I do CPU intensive work in my...
1
by: | last post by:
Hi all I am posting this to check if anyone could help me. The problem still persists. I am beginner in C#. Thanks. Subject: SQLDMO.Backup and ProgressBar - help please From: ...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
10
by: Nicolas | last post by:
When I resize (Enlarge) the form while the progress bar is running the rectangle drawing is not going to the end of the rectangle? I got a form with one button, one statusbar with three...
4
by: pmcguire | last post by:
Rather than putting a progress bar on all of my forms to show progress during time consuming tasks, I made a form called frmProgress with 2 controls, a Label and a ProgressBar. Suppose I expose 1...
2
by: sotto | last post by:
I need a loginscreen, that will show a progressbar that changes values based on a method in the main application (loading data from database) how would i do this? (i guess i need threading for...
1
by: nobody | last post by:
Hi I'm currently developing a Windows application. At the start of the application I load several tables into datatables in a dataset. I also use a progressbar to show the user how much percent...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I want to create an app in VS 2003 (not in 2005 !!). It works this way: user chooses an excel file in openfiledialog. then he clicks OK and a new form appears. There is a progressbar on the form....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.