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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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_USERyou could register your own Windows message:Make the above a static member of
CMainFramefor 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.