Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <pre><code>static UINT CMainFrame::UpdateStatusBarProc(LPVOID pParam); void CMainFrame::OnCreateTestThread() { // Create the thread and pass the window handle AfxBeginThread(UpdateStatusBarProc, m_hWnd); } LRESULT CMainFrame::OnUser(WPARAM wParam, LPARAM) { // Load string and update status bar CString str; VERIFY(str.LoadString(wParam)); m_wndStatusBar.SetPaneText(0, str); return 0; } // Thread proc UINT CMainFrame::UpdateStatusBarProc(LPVOID pParam) { const HWND hMainFrame = reinterpret_cast&lt;HWND&gt;(pParam); ASSERT(hMainFrame != NULL); ::PostMessage(hMainFrame, WM_USER, IDS_STATUS_STRING); return 0; } </code></pre> <p>The code is from memory as I don't have access to compiler here at home, so apologies now for any errors.</p> <p>Instead of using <code>WM_USER</code> you could register your own Windows message:</p> <pre><code>UINT WM_MY_MESSAGE = ::RegisterWindowsMessage(_T("WM_MY_MESSAGE")); </code></pre> <p>Make the above a static member of <code>CMainFrame</code> for example.</p> <p>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.:</p> <pre><code>// Thread proc UINT CMainFrame::UpdateStatusBarProc(LPVOID pParam) { const HWND hMainFrame = reinterpret_cast&lt;HWND&gt;(pParam); ASSERT(hMainFrame != NULL); CString* pString = new CString; *pString = _T("Hello, world!"); ::PostMessage(hMainFrame, WM_USER, 0, reinterpret_cast&lt;LPARAM&gt;(pString)); return 0; } LRESULT CMainFrame::OnUser(WPARAM, LPARAM lParam) { CString* pString = reinterpret_cast&lt;CString*&gt;(lParam); ASSERT(pString != NULL); m_wndStatusBar.SetPaneText(0, *pString); delete pString; return 0; } </code></pre> <p>Not perfect, but it's a start.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload