WndMessageListBox.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:5k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // -------------------------------------------------------------------------
  2. // 文件名 : ShowChatText.h
  3. // 创建者 : 彭建波
  4. // 创建时间 : 2002-9-16 16:22:52
  5. // 功能描述 : 显示聊天内容
  6. // -------------------------------------------------------------------------
  7. #pragma once
  8. #include "WndWindow.h"
  9. #include "WndScrollbar.h"
  10. struct KOneMsgInfo
  11. {
  12. int  nLines; //这条信息占了多少行
  13. int  nCharWidth; //这条信息占了字符宽
  14. unsigned int uTextBKColor; //这条信息字显示时的文字衬底的颜色,0为无
  15. int  nMaxSize; //Msg可以容纳的最大信息长度
  16. int  nLen; //信息长度
  17. char  Msg[1]; //信息的内容
  18. };
  19. class KWndScrollBar;
  20. class KWndMessageListBox : public KWndWindow
  21. {
  22. public:
  23. KWndMessageListBox();
  24. virtual ~KWndMessageListBox();
  25. virtual int Init(KIniFile* pIniFile, const char* pSection);//初始化
  26. void SetFirstShowLine(int nLine); //设置第一条被显示的文字是全部文字的第几行
  27. int GetFirstShowLine(); //获取第一条被显示的文字是全部文字的第几行
  28. void SetScrollbar(KWndScrollBar* pScroll);
  29. int SetCapability(int nNumMessage);
  30. int GetCapability(){ return m_nCapability;}
  31. int GetCurSel() { return m_nSelMsgIndex; }
  32. int SetCurSel(int nIndex);
  33. int AddOneMessage(const char* pText, int nLen, unsigned int uTextBKColor = 0);
  34. int GetOneMessage(int nIndex, char* pBuffer, int nLen, bool bExcludeCtrl);
  35. void RemoveAMessage(int nIndex);
  36. int GetMsgCount() { return m_nNumMessage; }
  37. int HitTextAtPoint(int x, int y);
  38. void SetSize(int nWidth, int nHeight);//设置窗口大小
  39. void Clear();
  40. void Clone(KWndMessageListBox* pCopy);
  41. int GetMaxShowLine() {return m_nNumMaxShowLine;}
  42. int GetItemLineCount(int nIndex);
  43. //从窗口分离出数据
  44. unsigned int SplitData();
  45. //给窗口捆绑数据
  46. unsigned int BindData(unsigned int hData);
  47. //释放窗口数据句柄
  48. static void FreeData(unsigned int hData);
  49. virtual int PtInWindow(int x, int y);
  50. void ClearHideLine();
  51. void HideNextLine();
  52. void HideAllLine();
  53. int GetMinHeight();
  54. void SetFontSize(int nFontSize);
  55. int GetFontSize() {return m_nFontSize;}
  56. private:
  57. int WndProc(unsigned int uMsg, unsigned int uParam, int nParam);
  58. void UpdateData(); //根据内容增删或者窗口尺寸变化重新作些参数计算以及滚动条容量调整
  59. virtual void PaintWindow(); //绘制窗口
  60. void OnMouseMove(int x, int y);
  61. void OnLButtonDown(int x, int y);
  62. void OnLButtonDClick(int x, int y);
  63. int GetMsgAtPoint(int x, int y);
  64. private:
  65. struct KMessageListData
  66. {
  67. KOneMsgInfo** pMessages; //信息数据
  68. int nNumMessage; //信息条数目
  69. int nCapability; //信息条最多允许数目
  70. int nStartShowMsg; //首条显示的信息
  71. int nStartMsgSkipLine; //首条显示的信息上方忽略的行数目
  72. int nSelMsgIndex; //当前选择的消息
  73. };
  74. private:
  75. KWndScrollBar* m_pScrollbar; //滚动条
  76. KOneMsgInfo** m_pMessages; //信息数据
  77. int m_nNumMessage; //信息条数目
  78. int m_nCapability; //信息条最多允许数目
  79. int m_nNumMaxShowLine; //最多可显示的行数目
  80. int m_nNumBytesPerLine; //每一行字符的数目
  81. int m_nNumVisibleTextLine; //可以看见的有文字的行的数目
  82. int m_nHideNumLine; //被强迫隐藏的行数,追加/删除/选中/滚动行/改尺寸时会无效
  83. int m_nFontSize; //字体大小
  84. int m_nStartShowMsg; //首条显示的信息
  85. int m_nStartMsgSkipLine; //首条显示的信息上方忽略的行数目
  86. int m_nSelMsgIndex; //当前选择的消息
  87. int m_nHLMsgIndex; //鼠标所指消息的索引
  88. unsigned int m_MsgColor; //默认的文字颜色
  89. unsigned int m_MsgBorderColor; //默认的文字边缘颜色
  90. unsigned int m_SelMsgColor; //被选中文字的颜色
  91. unsigned int m_SelMsgBorderColor; //被选中文字的边缘颜色
  92. unsigned int m_SelMsgBgColor; //被选中消息的背景颜色
  93. unsigned int m_HLMsgColor; //鼠标所指消息的颜色
  94. unsigned int m_HLMsgBorderColor; //鼠标所指消息的边缘颜色
  95. unsigned int m_uTextLineShadowColor; //有文字的行拥有的背景颜色,如果为0,表示无此背景色
  96. BOOL m_bHitText;
  97. unsigned int GetOffsetTextHeight();
  98. };
  99. class KScrollMessageListBox : public KWndWindow
  100. {
  101. public:
  102. KScrollMessageListBox();
  103. virtual int Init(KIniFile* pIniFile, const char* pSection);//初始化
  104. int WndProc(unsigned int uMsg, unsigned int uParam, int nParam);
  105. KWndMessageListBox* GetMessageListBox()
  106. {
  107. return &m_MsgList;
  108. }
  109. KWndScrollBar* GetScrollBar()
  110. {
  111. return &m_Scroll;
  112. }
  113. int HeightToLineHeight(int nHeight);
  114. int WidthToCharWidth(int nWidth);
  115. int GetMinHeight();
  116. protected:
  117. KWndMessageListBox m_MsgList;
  118. KWndScrollBar m_Scroll;
  119. int m_nLineHeight;
  120. int m_nMinLineCount;
  121. int m_nMaxLineCount;
  122. int m_nCurrentLineCount;
  123. void SetMsgLineCount(int nCount);
  124. void InitMinMaxLineCount(int nMin, int nMax);//初始化
  125. };
  126. bool MsgListBox_LoadContent(KWndMessageListBox* pBox, KIniFile* pFile, const char* pszSection);