UserListDlg.cpp
上传用户:hysujiao87
上传日期:2007-12-02
资源大小:156k
文件大小:3k
- // UserListDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "QQServer.h"
- #include "UserListDlg.h"
- #include "MainFrm.h"
- #include "QQServerDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CUserListDlg dialog
- CUserListDlg::CUserListDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CUserListDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUserListDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- _userList = NULL;
- }
- void CUserListDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUserListDlg)
- DDX_Control(pDX, IDC_USERLIST, _lcUserList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CUserListDlg, CDialog)
- //{{AFX_MSG_MAP(CUserListDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUserListDlg message handlers
- BOOL CUserListDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- _lcUserList.InsertColumn(0, _T("用户ID"));
- _lcUserList.InsertColumn(1, _T("用户密码"));
- _lcUserList.InsertColumn(2, _T("用户昵称"));
- _lcUserList.InsertColumn(3, _T("IP地址"));
- CRect rcList;
- _lcUserList.GetClientRect(rcList);
- int widthBlock = rcList.Width() / 4;
- _lcUserList.SetColumnWidth(0, widthBlock);
- _lcUserList.SetColumnWidth(1, widthBlock);
- _lcUserList.SetColumnWidth(2, widthBlock);
- _lcUserList.SetColumnWidth(3, rcList.Width() - widthBlock * 3);
- for(int i = 0; i < _userList->getCount(); i++)
- {
- CUserData *userData = _userList->getUserByIndex(i);
- _ASSERTE(userData != NULL);
- if (userData == NULL)
- return TRUE;
- CString ipaddr;
- if(userData->_online == TRUE)
- {
- ipaddr.Format("%d.%d.%d.%d", userData->_sockAddr.sin_addr.S_un.S_un_b.s_b1,
- userData->_sockAddr.sin_addr.S_un.S_un_b.s_b2,
- userData->_sockAddr.sin_addr.S_un.S_un_b.s_b3,
- userData->_sockAddr.sin_addr.S_un.S_un_b.s_b4);
- }
- else
- ipaddr = "offline";
- int index = _lcUserList.InsertItem(_lcUserList.GetItemCount(), userData->_clientID);
- _lcUserList.SetItemText(index, 1, userData->_password);
- _lcUserList.SetItemText(index, 2, userData->_nickname);
- _lcUserList.SetItemText(index, 3, ipaddr);
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }