
mutual class include problem: accessing members from one class from inside another
This was already discussed.
What I would do is have a view member that looked like this:
void CMyView::ShowText(CString s)
{
c_Alert.SetWindowText(s);
SetTimer(IDT_CLEAR_MESSAGE, 5000, NULL);
}
void CMyView::OnTimer(UINT nIdTimer)
{
switch(nIdTimer)
{ /* nIDTimer */
case IDT_CLEAR_MESSAGE:
c_Alert.SetWindowText(_T(""));
KillTimer(IDT_CLEAR_MESSAGE);
break;
...other times here
} /* nIDTimer */
...
}
What I am most likely to do is provide a CView * pointer in my associated classes, and use
SendMessage or PostMessage (depending on my threading situation) to send the message to
the view, which would handle the display, e.g.,
LRESULT CMyView::OnShowText(WPARAM wParam, LPARAM)
{
CString * s = (CString *)wParam;
ShowText(*s);
return 0;
}
void CClient::ShowText(CString s)
{
view->SendMessage(UWM_SHOW_TEXT, (WPARAM)&s);
}
joe
Quote:
>I have the following problem:
>I want to be in my view class everything concerning menus, dialog boxes,...
>I have another class, CClient, which contains network code
>then there's a third class, CWorld, which contains openGL code
>In my view class I have a CWorld member m_world and a CClient member
>m_client
>when I choose a certain menu, I need to acces client code, and this works
>fine
>now when a new users connects (this happens in CClient code) I want to
>display a message for a certain time
>to do this, I start a timer in my View and call a function of CWorld to draw
>it using openGL
>what is a proper way to do this?
>because now to be able to do this i have to declare a CTestView* member
>m_view in CClient which is fill in when I construct m_client:
> in CTestView::CTestView() :
>{
>...
>m_client = new CClient(this);
>...
>}
>and then in CClient::NewUser()
>{
> ...
> m_view->DisplayMessage(str);
> ...
>}
>but I was told this is not a good idea...
>so how it this done correctly?
>tnx
>Steven
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm