字体
第(3/6)页
关灯
   存书签 书架管理 返回目录
iew,用于输入聊天信息,它的基类是CEditView。为其添加成员

    函数virtual BOOL PreCreateWindow(CREATESTRUCT& cs),用于设定窗口风格,代码如下:

    BOOL CInputView::PreCreateWindow(CREATESTRUCT& cs)

    {

    BOOL ret = CEditView::PreCreateWindow(cs);

    cs.style = AFX_WS_DEFAULT_VIEW |

    WS_VSCROLL |

    ES_AUTOVSCROLL |

    ES_MULTILINE |

    ES_NOHIDESEL;

    return ret;

    }

    输入完聊天信息,键入回车键后,应当发送消息。为此,要为消息WM_CHAR 编写响

    应函数,代码如下:

    void CInputView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)

    {

    // TODO: Add yourcomssage handler code here and/or call default

    if (nChar != VK_RETURN)

    {

    CEditView::OnChar(nChar, nRepCnt, nFlags);

    return;

    }

    else

    {

    CChatClientDoc* pDoc = (CChatClientDoc*)m_pDoccomnt;

    CString strText;

    GetEditCtrl().GetWindowText(strText);

    //作为普通消息发送

    pDoc->SendMsg(strText, 4, true);

    strText=_T("");

    GetEditCtrl().SetWindowText(strText);

    GetEditCtrl().SetSel(9,9,FALSE);

    }

    CEditView::OnChar(nChar, nRepCnt, nFlags);

    }

    这里的SendMsg()函数是CChatClientDoc 的一个成员函数,在后面的程序中会看到它的

    实现。函数中用到了CChatClientDoc 类,在“InputView.cpp”的头部应加入语句#include

    "ChatClientDoc.h"。

    该界面的主框架分为3 部分。为类CMainFrcom 添加两个用于分割的成员变量

    枫叶文学网www.fywxw.com

    Visual C++ 6.0 程序设计从入门到精通

    ·312·

    CSplitterWnd m_wndSplitter1 和CSplitterWnd m_wndSplitter2,添加重载函数virtual BOOL

    OnCreateClient(LPCREATESTRUCT lpcs, CCreateContex
上一页 目录 下一页