Reputation: 1666
I need to call the CDocument::UpdateAllViews method with following parameters:
CView* pSender
LPARAM lHint = 0L
CString pHint = ""
One way, described in MSDN documentation is to pass a CObject derived class and override the CView::OnUpdate
member function in the CView-derived class.
Is there any other way I can do that?
Upvotes: 1
Views: 469
Reputation: 15375
No there isn't! Because the last parameter of UpdateAllViews needs a pointer to an object and a CString
is not derived from CObject
you need to wrap the string inside a class derived from CObject
:
class CMyHint : public CObject
{
public:
CString m_strHint;
};
...
CMyHint hint;
hint.m_strHint = _T("hint");
UpdateAllViews(nullptr,0,&hint);
...
void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
CMyHint *pMyHint = static_cast<CMyHint*)(pHint);
CString str = pMyHint->m_strHint;
...
Edit: I just looked into the source code of the MFC. The CObject *pHint
is nowhere used between CDocument::UpdateAllViews
and CView::OnUpdate
. So the pointer is never used as an CObject
.
So it is possible (but I would not recommend it), that you use reinterpret_cast<CObject*>
to a pointer to a CString
and later in CView
you use reinterpret_cast<CString*>
to get the string pointer again.
Possible but again: I would not recommend it!
Upvotes: 1