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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JensUniwebConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bert1Author Commented:
I know what function it is. What do I have to do to get windows responding while it executes that function?
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.