There are a number of ways to achieve this:
Make the main frame a global and add a member function (say
SetStatusText
):void CMainFrame::SetStatusText(CString strText) { CStatusBarCtrl sb(m_hWndStatusBar); sb.SetText(SB_SIMPLEID, strText); } LRESULT CTabPeople::OnMenuRefresh(...) { g_pMainFrame->SetStatusText(_T("Status text")); }
Use a static member function with a 'this pointer':
class CMainFrame;// Forward declaration class CMainFrame : public ... { public: CMainFrame() { this_ptr = this; } static void SetStatusText(CString strText) { CStatusBarCtrl sb(this_ptr->m_hWndStatusBar); sb.SetText(SB_SIMPLEID, strText); } static CMainFrame* this_ptr; }; // Initialization (in .cpp file) CMainFrame* CMainFrame::this_ptr = NULL; LRESULT CTabPeople::OnMenuRefresh(...) { CMainFrame::SetStatusText(_T("Status text")); }
Use the SendMessage API with a custom message identifier. Either send the message to the parent control (
CTabViewCtrl
), which in turn passes the message to its parents or the main frame, or send it to the main frame directly. The last case requires that you know how many nested windows there are, or you can use the main window handle as you already mentioned.LRESULT CTabPeople::OnMenuRefresh(...) { // Parent control processes the message ::SendMessage(GetParent(), MY_STATUS_MSG, (WPARAM) _T("Status text"), 0); // Main frame processes the message ::SendMessage(::GetParent(GetParent()), MY_STATUS_MSG, (WPARAM) _T("Status text"), 0); ::SendMessage(g_hWndMain, MY_STATUS_MSG, (WPARAM) _T("Status text"), 0); }
Add a message handler in the main frame and/or
CTabViewCtrl
:BEGIN_MSG_MAP(CMainFrame) ... MESSAGE_HANDLER(MY_STATUS_MSG, OnSetStatusMsg) END_MSG_MAP() LRESULT CMainFrame::OnSetStatusMsg(UINT, WPARAM wParam, LPARAM, BOOL&) { CStatusBarCtrl sb(m_hWndStatusBar); sb.SetText(SB_SIMPLEID, (LPCTSTR) wParam); return FALSE; }
Or you can simply send the
SB_SETTEXT
message if you have the status bar handle as a global:LRESULT CTabPeople::OnMenuRefresh(...) { ::SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(SB_SIMPLEID, 0), (LPARAM) _T("Status text")); }
Option 3 and 4 obviously take away the point of having classes (not object-oriented). Option 2 is probably the most applicable.
I haven't tested anything of this, but you have the idea. :)