Hello friends,
I create ListBox using MFC, in which I want to display the Output (like Visual c++ IDE debug windowor Output window).
I create a button after that it starts processing and ready to display the output.
I used
m_ListBoxResult.AddString(strlineCount); like that for all the functions and so on.. there will be lot of output.
Everything works fine but It displays everything after all the process done.
while processing nothing is displayed.
Its not working in runtime. Hope I perfectly project my question.
and in each function i have hundreds of output. I used only AddString().. with UpdateData(false).
But the List Box displays only after finishing Read Files.
Adding a string into the listbox means a message is sent to the listbox. To see the change the window holding the listbox needs to refresh itself and allow the listbox to to the same.
But with this algorithm you are using the application's main thread ( the UI thread) is blocked in the Onbuttonclick function so no message gets processed until the function finishes.
You have 2 options:
1. the nice way: use a thread to do the file processing and from that thread sent messages to the UI thread to add strings into the listbox
2. the old way: process the window messages yourself. See this article for more details
......
and in each function i have hundreds of output. I used only AddString().. with UpdateData(false).
But the List Box displays only after finishing Read Files.
1. The UpdateData(false) call is not needed here, moreover, it only slows the apllication performance down - remove this line.
2. The problem List Box does not display until finishing Read Files is because the CPU is busy reading the files - there is no time to update the GUI. To solve this problem you could create a worker thread and move all "Read Files" operations to it, then PostMessage a user defined message from a worker thread to the View window with some data to update the GUI. Tke a look at this article: WorkerThreads
3. to junma: sendmessage with paramter "LB_INSERTSTRING" is the same as callinf CListBox::InsertString - the same as CListBox::AddString (minus sorting, plus setting the position in list box).
PS. PadexArt was about 20 minutes faster!
Last edited by VictorN; March 31st, 2006 at 11:47 AM.
Hallo PadexArt,
I use seperate thread for all my function. Inside these functions, I need to use this Listbox control right. But these member variables are not declared according to the thread and its declared in Form View class.cpp
Hallo PadexArt,
I use seperate thread for all my function. Inside these functions, I need to use this Listbox control right. But these member variables are not declared according to the thread and its declared in Form View class.cpp
...
Thanks VictorN for your reply ..
I just going through the article ..
I used the UI thread in my attached file ..
.. I didnt finish the article .. yet..
get back to you guys .. soon ..
thnx
kings
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.