I'm new to mfc programming, and have a question... hope you can help me
I have a program that make some calculation, the user input some numbers and press a button to start.
When he press the button, the program start the calculations, and shows the results in a Clistbox as it arrives.
The problem is that when I use clistbox.addstring, the results are not automatically show in the clistbox, instead the user have to wait for all calculations to finish to see the results.
What can I do to show the results as soon as it arrives in the clistbox, and continues to do the calculations in the background??
Your UI looks frozen because the message pump is blocked doing calculations. You must do your calculation in a separate thread[^] and post a User defined message[^] to the main window and handle the message to update your list box.
It is a crappy thing, but it's life -^Carlo Pallini
You must do your calculation in a separate thread[^] and post a User defined message[^] to the main window
Just an interesting aside - I ran into this a couple of days ago. Rather than define a custom user message for each individual action that must occur on the UI thread, I tried to do it the .NET way - define a single message, say WM_INVOKE, and pass a pointer to a member function as LPARAM when posting the message (like Control.Invoke). Unfortunately, C++ doesn't allow you to take a pointer to a member function of an instance object directly - you can get a pointer to a member function, but you'll have to track the instance yourself and then when calling, use the esoteric .* operator to invoke it.
I couldn't be bothered to write a separate struct to hold the instance pointer and the function pointer, so I ended up writing multiple user defined messages instead