servertreeview.cpp
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:7k
源码类别:

游戏

开发平台:

Visual C++

  1. // servertreeview.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "..GameHigh.h"
  5. #include "..includeservertreeview.h"
  6. #include "MainFrm.h"
  7. #include "Macros.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. extern CGameHighApp theApp;
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CServerTreeView
  16. IMPLEMENT_DYNCREATE(CServerTreeView, CView)
  17. CServerTreeView::CServerTreeView()
  18. {
  19. hRootItem =NULL;
  20. hGambleItem =NULL;
  21. hForumItem =NULL;
  22. hChessItem =NULL;
  23. hCardItem =NULL;
  24. }
  25. CServerTreeView::~CServerTreeView()
  26. {
  27. m_ServerImgList.DeleteImageList();
  28. }
  29. BEGIN_MESSAGE_MAP(CServerTreeView, CView)
  30. //{{AFX_MSG_MAP(CServerTreeView)
  31. ON_WM_CREATE()
  32. ON_WM_SIZE()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CServerTreeView drawing
  37. void CServerTreeView::OnDraw(CDC* pDC)
  38. {
  39. CDocument* pDoc = GetDocument();
  40. // TODO: add draw code here
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CServerTreeView diagnostics
  44. #ifdef _DEBUG
  45. void CServerTreeView::AssertValid() const
  46. {
  47. CView::AssertValid();
  48. }
  49. void CServerTreeView::Dump(CDumpContext& dc) const
  50. {
  51. CView::Dump(dc);
  52. }
  53. #endif //_DEBUG
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CServerTreeView message handlers
  56. int CServerTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  57. {
  58. if (CView::OnCreate(lpCreateStruct) == -1)
  59. return -1;
  60. try
  61. {
  62. RECT rect;
  63. memset(&rect, 0, sizeof(RECT));
  64. m_ServerTree.Create(WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT |
  65. TVS_HASBUTTONS | TVS_SHOWSELALWAYS , rect, this,
  66. SERVER_TREEID);
  67. m_ServerTree.SetItemHeight(20);
  68. COLORREF clrBk =RGB(150, 175, 230);
  69. m_ServerTree.SetBkColor(clrBk);
  70. }
  71. catch(...)
  72. {
  73. ::MessageBox(this->GetSafeHwnd(), "无法创建游戏列表树!",
  74. "错误!", MB_OK | MB_ICONERROR);
  75. }
  76. InitServerTree();
  77. return 0;
  78. }
  79. BOOL CServerTreeView::InitServerTree()
  80. {
  81. CTreeCtrl* pTreeCtrl =&m_ServerTree;
  82. SAFE_CHECKFALSEWND(pTreeCtrl)
  83. {
  84. return FALSE;
  85. }
  86. if(NULL == m_ServerImgList.GetSafeHandle())
  87. {
  88. m_ServerImgList.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 256);
  89. CBitmap m_Bmp;
  90. m_Bmp.LoadBitmap(IDB_HALLTREE);
  91. if(NULL != m_Bmp.GetSafeHandle())
  92. {
  93. m_ServerImgList.Add(&m_Bmp, RGB(3, 126, 129));
  94. m_Bmp.DeleteObject();
  95. }
  96. }
  97. if(NULL != m_ServerImgList.GetSafeHandle())
  98. {
  99. m_ServerTree.SetImageList(&m_ServerImgList, TVSIL_NORMAL);
  100. }
  101. hRootItem =m_ServerTree.InsertItem("Game High在线游戏系列", 0, 0, TVI_ROOT, TVI_LAST);
  102. SAFE_CHECKPOINTER(hRootItem)
  103. {
  104. hChessItem =m_ServerTree.InsertItem("棋类游戏", 5, 5, hRootItem, TVI_LAST);
  105. SAFE_CHECKPOINTER(hChessItem)
  106. {
  107. m_ServerTree.InsertItem("奥赛罗", 6, 6, hChessItem, TVI_LAST);
  108. HTREEITEM hArmy=m_ServerTree.InsertItem("军棋",   8, 8, hChessItem, TVI_LAST);
  109. //非测试版本应该在这里提取房间列表
  110. LPGAMEHIGH_ROOM lpArray =NULL;
  111. int nRoomCount =0;
  112. CMainData* pMainData =NULL;
  113. pMainData =theApp.GetMainData();
  114. SAFE_CHECKPOINTER(pMainData)
  115. {
  116. pMainData->Async_GameHigh_LoadRoomsFromServer(1, lpArray, nRoomCount);
  117. if(hArmy && 
  118. NULL != lpArray &&
  119. 0    <nRoomCount)
  120. {
  121. for(int i=0; i<nRoomCount; i++)
  122. {
  123. HTREEITEM hSubItem =NULL;
  124. hSubItem =m_ServerTree.InsertItem(lpArray[i].RoomName, 8, 8, hArmy, TVI_LAST);
  125. m_ServerTree.SetItemData(hSubItem, lpArray[i].uRoomID);
  126. }
  127. delete[] lpArray;
  128. }
  129. }
  130. m_ServerTree.InsertItem("斗兽棋", 6, 6, hChessItem, TVI_LAST);
  131. m_ServerTree.InsertItem("五子棋", 6, 6, hChessItem, TVI_LAST);
  132. m_ServerTree.InsertItem("围棋",   6, 6, hChessItem, TVI_LAST);
  133. m_ServerTree.Expand(hChessItem, TVE_EXPAND);
  134. }//end check pointer "hChessItem"
  135. hCardItem =m_ServerTree.InsertItem("牌类游戏", 5, 5, hRootItem, TVI_LAST);
  136. SAFE_CHECKPOINTER(hCardItem)
  137. {
  138. m_ServerTree.InsertItem("锄大D", 6, 6, hCardItem, TVI_LAST);
  139. m_ServerTree.InsertItem("斗地主", 6, 6, hCardItem, TVI_LAST);
  140. m_ServerTree.Expand(hCardItem, TVE_EXPAND);
  141. }//end check pointer "hCardItem"
  142. SAFE_CHECKPOINTER(hGambleItem)
  143. {
  144. hGambleItem =m_ServerTree.InsertItem("博彩类", 5, 5, hRootItem, TVI_LAST);
  145. m_ServerTree.Expand(hGambleItem, TVE_EXPAND);
  146. }//end check pointer "hGambleItem"
  147. SAFE_CHECKPOINTER(hForumItem)
  148. {
  149. hForumItem =m_ServerTree.InsertItem("游戏论坛", 2, 2, hRootItem, TVI_LAST);
  150. m_ServerTree.Expand(hForumItem, TVE_EXPAND);
  151. }//end check pointer "hForumItem"
  152. m_ServerTree.Expand(hRootItem, TVE_EXPAND);
  153. } //end check pointer "hRootItem"
  154. return TRUE;
  155. }
  156. void CServerTreeView::OnSize(UINT nType, int cx, int cy) 
  157. {
  158. CView::OnSize(nType, cx, cy);
  159. RECT rect;
  160. memset(&rect, 0, sizeof(RECT));
  161. this->GetClientRect(&rect);
  162. CTreeCtrl* pTreeCtrl =&m_ServerTree;
  163. SAFE_CHECKWND(pTreeCtrl)
  164. {
  165. m_ServerTree.MoveWindow(&rect, TRUE);
  166. }
  167. }
  168. LRESULT CServerTreeView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  169. {
  170. switch(message)
  171. {
  172. case WM_COMMAND:
  173. {
  174. ;
  175. }
  176. break;
  177. case WM_NOTIFY:
  178. {
  179. CTreeCtrl* pTreeCtrl =&m_ServerTree;
  180. SAFE_CHECKFALSEWND(pTreeCtrl)
  181. {
  182. break;
  183. }
  184. LPNMHDR lpdr =(LPNMHDR)lParam;
  185. if(NULL != lpdr && lpdr->hwndFrom == m_ServerTree.GetSafeHwnd())
  186. {
  187. switch(lpdr->code)
  188. {
  189. case TVN_SELCHANGED:
  190. {
  191. OnTreeSelChanged(lpdr);
  192. }
  193. break;
  194. case NM_DBLCLK:
  195. {
  196. OnTreeDblClk(lpdr);
  197. }
  198. break;
  199. case NM_RCLICK:
  200. {
  201. OnTreeRClick(lpdr);
  202. }
  203. break;
  204. default:
  205. break;
  206. }//end switch(lpdr->code)
  207. }//endif 
  208. }//end case WM_NOTIFY
  209. break;
  210. default:
  211. break;
  212. }//end switch message
  213. return CView::WindowProc(message, wParam, lParam);
  214. }
  215. void CServerTreeView::OnTreeSelChanged(LPNMHDR lpdr)
  216. {
  217. ASSERT(lpdr);
  218. if(NULL == lpdr)
  219. return ;
  220. }
  221. void CServerTreeView::OnTreeRClick(LPNMHDR lpdr)
  222. {
  223. ASSERT(lpdr);
  224. if(NULL == lpdr)
  225. return ;
  226. }
  227. void CServerTreeView::OnTreeDblClk(LPNMHDR lpdr)
  228. {
  229. ASSERT(lpdr);
  230. if(NULL == lpdr)
  231. return ;
  232. CMainData* pMainData =NULL;
  233. pMainData =theApp.GetMainData();
  234. if(NULL == pMainData)
  235. return;
  236. CTreeCtrl* pTreeCtrl =&m_ServerTree;
  237. SAFE_CHECKWND(pTreeCtrl)
  238. {
  239. HTREEITEM hItem =pTreeCtrl->GetSelectedItem();
  240. SAFE_CHECKPOINTER(hItem)
  241. {
  242. DWORD dwRoomData =pTreeCtrl->GetItemData(hItem);
  243. if(dwRoomData > 0)
  244. {
  245. CMainFrame* pFrame =(CMainFrame*)::AfxGetMainWnd();
  246. SAFE_CHECKWND(pFrame)
  247. {
  248. pFrame->ShowTableFrame(TRUE, dwRoomData);
  249. }
  250. }
  251. }
  252. }
  253. }