servertreeview.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:7k
源码类别:
游戏
开发平台:
Visual C++
- // servertreeview.cpp : implementation file
- //
- #include "stdafx.h"
- #include "..GameHigh.h"
- #include "..includeservertreeview.h"
- #include "MainFrm.h"
- #include "Macros.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CGameHighApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CServerTreeView
- IMPLEMENT_DYNCREATE(CServerTreeView, CView)
- CServerTreeView::CServerTreeView()
- {
- hRootItem =NULL;
- hGambleItem =NULL;
- hForumItem =NULL;
- hChessItem =NULL;
- hCardItem =NULL;
- }
- CServerTreeView::~CServerTreeView()
- {
- m_ServerImgList.DeleteImageList();
- }
- BEGIN_MESSAGE_MAP(CServerTreeView, CView)
- //{{AFX_MSG_MAP(CServerTreeView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CServerTreeView drawing
- void CServerTreeView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CServerTreeView diagnostics
- #ifdef _DEBUG
- void CServerTreeView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CServerTreeView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CServerTreeView message handlers
- int CServerTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- try
- {
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- m_ServerTree.Create(WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT |
- TVS_HASBUTTONS | TVS_SHOWSELALWAYS , rect, this,
- SERVER_TREEID);
- m_ServerTree.SetItemHeight(20);
- COLORREF clrBk =RGB(150, 175, 230);
- m_ServerTree.SetBkColor(clrBk);
- }
- catch(...)
- {
- ::MessageBox(this->GetSafeHwnd(), "无法创建游戏列表树!",
- "错误!", MB_OK | MB_ICONERROR);
- }
- InitServerTree();
- return 0;
- }
- BOOL CServerTreeView::InitServerTree()
- {
- CTreeCtrl* pTreeCtrl =&m_ServerTree;
- SAFE_CHECKFALSEWND(pTreeCtrl)
- {
- return FALSE;
- }
- if(NULL == m_ServerImgList.GetSafeHandle())
- {
- m_ServerImgList.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 256);
- CBitmap m_Bmp;
- m_Bmp.LoadBitmap(IDB_HALLTREE);
- if(NULL != m_Bmp.GetSafeHandle())
- {
- m_ServerImgList.Add(&m_Bmp, RGB(3, 126, 129));
- m_Bmp.DeleteObject();
- }
- }
- if(NULL != m_ServerImgList.GetSafeHandle())
- {
- m_ServerTree.SetImageList(&m_ServerImgList, TVSIL_NORMAL);
- }
- hRootItem =m_ServerTree.InsertItem("Game High在线游戏系列", 0, 0, TVI_ROOT, TVI_LAST);
- SAFE_CHECKPOINTER(hRootItem)
- {
- hChessItem =m_ServerTree.InsertItem("棋类游戏", 5, 5, hRootItem, TVI_LAST);
- SAFE_CHECKPOINTER(hChessItem)
- {
- m_ServerTree.InsertItem("奥赛罗", 6, 6, hChessItem, TVI_LAST);
- HTREEITEM hArmy=m_ServerTree.InsertItem("军棋", 8, 8, hChessItem, TVI_LAST);
- //非测试版本应该在这里提取房间列表
- LPGAMEHIGH_ROOM lpArray =NULL;
- int nRoomCount =0;
- CMainData* pMainData =NULL;
- pMainData =theApp.GetMainData();
- SAFE_CHECKPOINTER(pMainData)
- {
- pMainData->Async_GameHigh_LoadRoomsFromServer(1, lpArray, nRoomCount);
- if(hArmy &&
- NULL != lpArray &&
- 0 <nRoomCount)
- {
- for(int i=0; i<nRoomCount; i++)
- {
- HTREEITEM hSubItem =NULL;
- hSubItem =m_ServerTree.InsertItem(lpArray[i].RoomName, 8, 8, hArmy, TVI_LAST);
- m_ServerTree.SetItemData(hSubItem, lpArray[i].uRoomID);
- }
- delete[] lpArray;
- }
- }
- m_ServerTree.InsertItem("斗兽棋", 6, 6, hChessItem, TVI_LAST);
- m_ServerTree.InsertItem("五子棋", 6, 6, hChessItem, TVI_LAST);
- m_ServerTree.InsertItem("围棋", 6, 6, hChessItem, TVI_LAST);
- m_ServerTree.Expand(hChessItem, TVE_EXPAND);
- }//end check pointer "hChessItem"
- hCardItem =m_ServerTree.InsertItem("牌类游戏", 5, 5, hRootItem, TVI_LAST);
- SAFE_CHECKPOINTER(hCardItem)
- {
- m_ServerTree.InsertItem("锄大D", 6, 6, hCardItem, TVI_LAST);
- m_ServerTree.InsertItem("斗地主", 6, 6, hCardItem, TVI_LAST);
- m_ServerTree.Expand(hCardItem, TVE_EXPAND);
- }//end check pointer "hCardItem"
- SAFE_CHECKPOINTER(hGambleItem)
- {
- hGambleItem =m_ServerTree.InsertItem("博彩类", 5, 5, hRootItem, TVI_LAST);
- m_ServerTree.Expand(hGambleItem, TVE_EXPAND);
- }//end check pointer "hGambleItem"
- SAFE_CHECKPOINTER(hForumItem)
- {
- hForumItem =m_ServerTree.InsertItem("游戏论坛", 2, 2, hRootItem, TVI_LAST);
- m_ServerTree.Expand(hForumItem, TVE_EXPAND);
- }//end check pointer "hForumItem"
- m_ServerTree.Expand(hRootItem, TVE_EXPAND);
- } //end check pointer "hRootItem"
- return TRUE;
- }
- void CServerTreeView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- this->GetClientRect(&rect);
- CTreeCtrl* pTreeCtrl =&m_ServerTree;
- SAFE_CHECKWND(pTreeCtrl)
- {
- m_ServerTree.MoveWindow(&rect, TRUE);
- }
- }
- LRESULT CServerTreeView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_COMMAND:
- {
- ;
- }
- break;
- case WM_NOTIFY:
- {
- CTreeCtrl* pTreeCtrl =&m_ServerTree;
- SAFE_CHECKFALSEWND(pTreeCtrl)
- {
- break;
- }
- LPNMHDR lpdr =(LPNMHDR)lParam;
- if(NULL != lpdr && lpdr->hwndFrom == m_ServerTree.GetSafeHwnd())
- {
- switch(lpdr->code)
- {
- case TVN_SELCHANGED:
- {
- OnTreeSelChanged(lpdr);
- }
- break;
- case NM_DBLCLK:
- {
- OnTreeDblClk(lpdr);
- }
- break;
- case NM_RCLICK:
- {
- OnTreeRClick(lpdr);
- }
- break;
- default:
- break;
- }//end switch(lpdr->code)
- }//endif
- }//end case WM_NOTIFY
- break;
- default:
- break;
- }//end switch message
- return CView::WindowProc(message, wParam, lParam);
- }
- void CServerTreeView::OnTreeSelChanged(LPNMHDR lpdr)
- {
- ASSERT(lpdr);
- if(NULL == lpdr)
- return ;
- }
- void CServerTreeView::OnTreeRClick(LPNMHDR lpdr)
- {
- ASSERT(lpdr);
- if(NULL == lpdr)
- return ;
- }
- void CServerTreeView::OnTreeDblClk(LPNMHDR lpdr)
- {
- ASSERT(lpdr);
- if(NULL == lpdr)
- return ;
- CMainData* pMainData =NULL;
- pMainData =theApp.GetMainData();
- if(NULL == pMainData)
- return;
- CTreeCtrl* pTreeCtrl =&m_ServerTree;
- SAFE_CHECKWND(pTreeCtrl)
- {
- HTREEITEM hItem =pTreeCtrl->GetSelectedItem();
- SAFE_CHECKPOINTER(hItem)
- {
- DWORD dwRoomData =pTreeCtrl->GetItemData(hItem);
- if(dwRoomData > 0)
- {
- CMainFrame* pFrame =(CMainFrame*)::AfxGetMainWnd();
- SAFE_CHECKWND(pFrame)
- {
- pFrame->ShowTableFrame(TRUE, dwRoomData);
- }
- }
- }
- }
- }