MainFrm.cpp
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:3k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "Server.h"
  5. #include "MainFrm.h"
  6. #include "msg.h"
  7. #include "socket.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. #define WM_MY_TRAY_NOTIFICATION WM_USER+101
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMainFrame
  16. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  17. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  18. //{{AFX_MSG_MAP(CMainFrame)
  19. ON_WM_CREATE()
  20. ON_UPDATE_COMMAND_UI(ID_NUMBER_ONLINE, OnUpdateNumberOnline)
  21. ON_UPDATE_COMMAND_UI(ID_NUMBER_ALLUSER, OnUpdateNumberAlluser)
  22. ON_UPDATE_COMMAND_UI(ID_NUMBER_RECV, OnUpdateNumberRecvReq)
  23. ON_COMMAND(ID_SHOWWINDOW, OnShowwindow)
  24. //}}AFX_MSG_MAP
  25. ON_MESSAGE(WM_MY_TRAY_NOTIFICATION,OnTrayNotification)
  26. END_MESSAGE_MAP()
  27. static UINT indicators[] =
  28. {
  29. ID_SEPARATOR,           // status line indicator
  30. ID_NUMBER_ONLINE,
  31. ID_NUMBER_ALLUSER,
  32. ID_NUMBER_RECV,
  33. };
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMainFrame construction/destruction
  36. CMainFrame::CMainFrame()
  37. {
  38. // TODO: add member initialization code here
  39. }
  40. CMainFrame::~CMainFrame()
  41. {
  42. }
  43. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  44. {
  45. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  46. return -1;
  47. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  48. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  49. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  50. {
  51. TRACE0("Failed to create toolbarn");
  52. return -1;      // fail to create
  53. }
  54. if (!m_wndStatusBar.Create(this) ||
  55. !m_wndStatusBar.SetIndicators(indicators,
  56.   sizeof(indicators)/sizeof(UINT)))
  57. {
  58. TRACE0("Failed to create status barn");
  59. return -1;      // fail to create
  60. }
  61. m_TrayIcon.SetNotificationWnd(this,WM_MY_TRAY_NOTIFICATION);
  62. m_TrayIcon.SetIcon(IDR_TRAYICON,"服务器");
  63. return 0;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMainFrame diagnostics
  67. #ifdef _DEBUG
  68. void CMainFrame::AssertValid() const
  69. {
  70. CFrameWnd::AssertValid();
  71. }
  72. void CMainFrame::Dump(CDumpContext& dc) const
  73. {
  74. CFrameWnd::Dump(dc);
  75. }
  76. #endif //_DEBUG
  77. void CMainFrame::OnUpdateNumberOnline(CCmdUI* pCmdUI) 
  78. {
  79. CString str;
  80. str.Format("在线人数:  %d",((CServerApp*)AfxGetApp())->m_nNumberOnline);
  81. pCmdUI->SetText(str);
  82. }
  83. void CMainFrame::OnUpdateNumberAlluser(CCmdUI* pCmdUI) 
  84. {
  85. CString str;
  86. str.Format("总用户数:  %d",((CServerApp*)AfxGetApp())->m_nTotalUserNumber);
  87. pCmdUI->SetText(str);
  88. }
  89. void CMainFrame::OnUpdateNumberRecvReq(CCmdUI* pCmdUI) 
  90. {
  91. CString str;
  92. str.Format("接受消息:  %d",((CServerApp*)AfxGetApp())->m_nRecvMsg);
  93. pCmdUI->SetText(str);
  94. }
  95. LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  96. {
  97. if(message==WM_SYSCOMMAND)
  98. {
  99. if(wParam==SC_CLOSE)
  100. {
  101. PostMessage(WM_COMMAND,ID_APP_EXIT,0);
  102. return 0;
  103. }
  104. else if(wParam==SC_MINIMIZE)
  105. {
  106. PostMessage(WM_COMMAND,ID_SHOWWINDOW,0);
  107. return 0;
  108. }
  109. }
  110. return CFrameWnd::DefWindowProc(message, wParam, lParam);
  111. }
  112. void CMainFrame::OnTest() 
  113. {
  114. }
  115. LRESULT CMainFrame::OnTrayNotification(WPARAM wp,LPARAM lp)
  116. {
  117. return m_TrayIcon.OnTrayNotification(wp,lp);
  118. }
  119. void CMainFrame::OnShowwindow() 
  120. {
  121. static BOOL bShow=FALSE;
  122. if(bShow)ShowWindow(SW_NORMAL);
  123. else ShowWindow(SW_HIDE);
  124. bShow=!bShow;
  125. }