Discussion:
Showing status of a long process
(too old to reply)
wang
2011-01-20 21:09:24 UTC
Permalink
Hi all gurus,
I've written a dialogue program in Visual C++ which processes many
files and might last long. I want to show the status of the process,
for example, "just processing the file abc.txt", on the GUI, where I
have put a static control with the variable m_strMsg for showing such
messages. During the processing the program changes m_strMsg if a new
file being processed is opened, and I haven't forgotten to write
"UpdateData(FALSE);" after changing m_strMsg. But the message on the
GUI does not change until the end of the program. What must be done to
synchronize the GUI message and the process status? Or should I use
other architecture (for example, SDI) instead of dialogue program?
Many thanks in advance!

k.w.wang
DDD
2011-01-21 03:35:09 UTC
Permalink
There is one possible question. How do you arrange your "file
processing"?

While(...) {

processFile

showStatus

}

Is that so?

If so , the now phenomenon is right. Because the while loop will
occupy CPU until it out. And the main process
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

can not dispatchMessage to WndProc function of the Dialog.

You can put your codes in a thread to achieve your destination.
Post by wang
Hi all gurus,
I've written a dialogue program in Visual C++ which processes many
files and might last long. I want to show the status of the process,
for example, "just processing the file abc.txt", on the GUI, where I
have put a static control with the variable m_strMsg for showing such
messages. During the processing the program changes m_strMsg if a new
file being processed is opened, and I haven't forgotten to write
"UpdateData(FALSE);" after changing m_strMsg. But the message on the
GUI does not change until the end of the program. What must be done to
synchronize the GUI message and the process status? Or should I use
other architecture (for example, SDI) instead of dialogue program?
Many thanks in advance!
k.w.wang
wang
2011-01-21 09:26:26 UTC
Permalink
Post by DDD
There is one possible question. How do you arrange your "file
processing"?
While(...) {
processFile
showStatus
}
Is that so?
If so , the now phenomenon is right. Because the while loop will
occupy CPU until it out. And the main process
while (GetMessage(&msg, NULL, 0, 0))
        {
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }
can not dispatchMessage to WndProc function of the Dialog.
You can put your codes in a thread to achieve your destination.
Post by wang
Hi all gurus,
I've written a dialogue program in Visual C++  which processes many
files and might last long. I want to show the status of the process,
for example, "just processing the file abc.txt", on the GUI, where I
have put a static control with the variable m_strMsg for showing such
messages. During the processing the program changes m_strMsg if a new
file being processed is opened, and I haven't forgotten to write
"UpdateData(FALSE);" after changing m_strMsg. But the message on the
GUI does not change until the end of the program. What must be done to
synchronize the GUI message and the process status? Or should I use
other architecture (for example, SDI) instead of dialogue program?
Many thanks in advance!
k.w.wang- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
Yes, you are right. My code looks like:

while (there is file unprocessed) {
process_the_next_file;
showMsg;
}
I've read in "VC++ in 21 Days" about Multitasking. 4 kinds of
multitasking are introduced there: critical sections, mutexes,
semaphores und events. What kind of multitasking should be used for my
purpose? Thanks!
k.w.wang
DDD
2011-01-21 14:43:24 UTC
Permalink
Post by wang
Post by DDD
There is one possible question. How do you arrange your "file
processing"?
While(...) {
processFile
showStatus
}
Is that so?
If so , the now phenomenon is right. Because the while loop will
occupy CPU until it out. And the main process
while (GetMessage(&msg, NULL, 0, 0))
        {
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }
can not dispatchMessage to WndProc function of the Dialog.
You can put your codes in a thread to achieve your destination.
Post by wang
Hi all gurus,
I've written a dialogue program in Visual C++  which processes many
files and might last long. I want to show the status of the process,
for example, "just processing the file abc.txt", on the GUI, where I
have put a static control with the variable m_strMsg for showing such
messages. During the processing the program changes m_strMsg if a new
file being processed is opened, and I haven't forgotten to write
"UpdateData(FALSE);" after changing m_strMsg. But the message on the
GUI does not change until the end of the program. What must be done to
synchronize the GUI message and the process status? Or should I use
other architecture (for example, SDI) instead of dialogue program?
Many thanks in advance!
k.w.wang- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
while (there is file unprocessed) {
process_the_next_file;
showMsg;
}
I've read in "VC++ in 21 Days" about Multitasking. 4 kinds of
multitasking are introduced there: critical sections, mutexes,
semaphores und events. What kind of multitasking should be used for my
purpose? Thanks!
A simple solution is

void ThreadFunction()
{
process_the_next_file;
showMsg;
}

createThread(...ThreadFunction, ...);
Post by wang
k.w.wang
Loading...