?
Solved

Program doesn't respond when it add strings to listbox.

Posted on 1999-07-05
13
Medium Priority
?
207 Views
Last Modified: 2010-04-16
My program doesnt respond when it add strings to a listbox. I cant move the window or scroll the ListBox until the program are done! What's wrong ? How can I enable the window while it working with one task (I dont use threds, I just have one function).
0
Comment
Question by:bert1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 

Author Comment

by:bert1
ID: 1199126
Adjusted points to 50
0
 

Expert Comment

by:_serega
ID: 1199127
probably your program's flow control comes into some function that didn't return. set a breakpoints to find out which functions didn't return control. window doesn't respond because message loop isn't processed
0
 

Author Comment

by:bert1
ID: 1199128
I know what function it is. What do I have to do to get windows responding while it executes that function?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bert1
ID: 1199129
Here is one example...
void CWindow::HandleButtonMsg()
{
   LPCSTR lpszFileName = CApp().cmdLine.c_str();
   char szSectionHeader[3];
      ListBox->ClearList();
   ListBoxUpdated->ClearList();
   for (int nCounter=1; nCounter<=15; nCounter++)
   {
         itoa(nCounter, szSectionHeader, 3);
      ReadIniFile(lpszFileName, szSectionHeader);
   }
}
0
 

Expert Comment

by:_serega
ID: 1199130
put the function into another thread
0
 

Expert Comment

by:_serega
ID: 1199131
put the function into another thread
0
 
LVL 2

Accepted Solution

by:
JensUniweb earned 200 total points
ID: 1199132
You will have to incorporate a GetMessage() part in the code that takes to long time. Otherwise your program will not get any messages. The other solution is to start a thread that is doing the part that is taking to long.
0
 

Author Comment

by:bert1
ID: 1199133
I have to use threads?

Cant I make it without threads?
0
 
LVL 2

Expert Comment

by:JensUniweb
ID: 1199134
You use PeekMessage() and DispatchMessage in you loop to receive the waiting messages. That way you don't need any threads.

Do you use OWL/MFC/VCL??? Or are you writing in plain WinAPI???
0
 

Author Comment

by:bert1
ID: 1199135
JensUniWeb:

If you look at my code example... It's the ReadIniFile that takes long time... where and how shall I put the GetMesage() function?

Thanks a lot!
0
 

Author Comment

by:bert1
ID: 1199136
I am using owl...
0
 
LVL 2

Expert Comment

by:JensUniweb
ID: 1199137
Have you written ReadIniFile()??? Because the best way to do it is to make a function maybe called FlushMessages(). In this function you have a loop like this.

FlushMessage( HWND tWnd )
{
 MSG tMsg;

 while( PeekMessage( &tMsg,tWnd,0,0,true ) )
 {
  TranslateMessage( &tMsg );
  DispatchMessage( &tMsg );
 }
}

And you call it as often as needed in the code that takes time. If you're able to put it in the ReadIniFile() do so. In the loop that is reading or something.

 /Jens
0
 
LVL 2

Expert Comment

by:JensUniweb
ID: 1199138
Been too long seens I used OWL. And I'm not sure there were any function like FlushMessage(). But if you look at the code for TApplication::MessageLoop() you my find a call to a function to a function like the FlushMessage() function.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question