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

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).
bert1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bert1Author Commented:
Adjusted points to 50
0
_seregaCommented:
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
bert1Author Commented:
I know what function it is. What do I have to do to get windows responding while it executes that function?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

bert1Author Commented:
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
_seregaCommented:
put the function into another thread
0
_seregaCommented:
put the function into another thread
0
JensUniwebCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bert1Author Commented:
I have to use threads?

Cant I make it without threads?
0
JensUniwebCommented:
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
bert1Author Commented:
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
bert1Author Commented:
I am using owl...
0
JensUniwebCommented:
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
JensUniwebCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.