hello all, I am new to the concept of threading in C..so I find it difficult to implement that in my function...I have a simple application in which i want to display a progress bar at a particular place..In a particular funtion I will read files(in a for loop) for some manipulations(regarding my application) ...while its reading the files I want to display a progress bar...stating that its in process of reading files...I know it should be done using the concept of threading...but i am not quite sure how to do it..please help me with this
+1
A:
Create a worker thread in the main program and set the callback routine that does the file processing.
That routine also will calculate the percentage that is completed. Whenever that percent changes, post the
value as a window message which the main thread will catch and update the progress bar control.
You can define application inner messages like #define MSG_PROGRESS_VALUE (WM_USER + 1)
.
Edit: sample,
#define MSG_PROGRESS_VALUE (WM_USER + 1)
#define MSG_WORKER_DONE (WM_USER + 2)
...
DWORD WINAPI jobroutine(LPVOID lpParameter) {
while (TRUE) {
// process files ...
// calculate new percent
if (newpercent != oldpercent) {
PostMessage(mainwnd, MSG_PROGRESS_VALUE, 0, newpercent);
oldpercent = newpercent;
}
...
}
PostMessage(mainwnd, MSG_WORKER_DONE, 0, 0);
return 0;
}
...
MainWndProc(...) {
switch (uMsg) {
...
case MSG_PROGRESS_VALUE:
// update progress bar value (lParam)
break;
...
}
...
WinMain(...) {
HANDLE worker = CreateThread(NULL, 0, jobroutine, NULL, NULL, NULL);
...
// Start classic windows message loop
...
}
Nick D
2010-03-31 06:31:45
nick thanx 4 ur replay..I appreciate it very much...if u can show me an example or any reference regarding the above..it would be very helpful nick
kiddo
2010-03-31 06:38:27
@Rakesh, I posted a sample to get an idea of the process.
Nick D
2010-03-31 07:09:24