I have a dialog in MFC with a CStatusBar. In a separate thread, I want to change the pane text of status bar. However MFC complains with asserts? How is it done? An example code would be great.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Difference between Thread#run and Thread#wakeup?
- Selecting only the first few characters in a strin
- Java/Spring MVC: provide request context to child
- What exactly do pointers store? (C++)
Maybe this can help you: How to access UI elements from a thread in MFC.
I don't code C++/MFC myself but I had experienced the similar problem in C# which is known as Cross-thread GUI update.
You should use a message (either with Send- or PostMessage) to notify the UI thread that the status bar text should be updated. Don't try to update UI elements from a worker thread, it's bound to give you pain.
You could post a private message to the main frame window and 'ask' it to update the status bar. The thread would need the main window handle (don't use the CWnd object as it won't be thread safe). Here is some sample code:
The code is from memory as I don't have access to compiler here at home, so apologies now for any errors.
Instead of using
WM_USER
you could register your own Windows message:Make the above a static member of
CMainFrame
for example.If using string resources is too basic then have the thread allocate the string on the heap and make sure the CMainFrame update function deletes it, e.g.:
Not perfect, but it's a start.