One of the funny things about Windows is that the visible elements (GUI Controls, stuff like that) need to process messages in order to operate correctly.
Any Windows GUI based application needs to ensure that the message processing loop is run in a timely fashion to allow that to work. Some applications do that with a separate GUI thread (something you get for free with an MFC / Dialog based application.
The code you show looks like it's in the main line processing of your application, opening files, etc. If your code never enters an idle state or returns to the message loop until it's finished, you will see the behavior you report.
I cannot tell you how to structure your code without seeing lots more of it. However, you can force the message processing loop to run by calling
void ProcessWindowMessages()
{
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
at reasonable time, like after each time you put something in the listbox. Not that this is the best way to do things but it is often a good way depending on the design of your application.