MainFrm.cpp
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:5k
源码类别:

远程控制编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "AnyServer.h"
  5. #include "MainFrm.h"
  6. #include "AnyServerView.h"
  7. #include "ChatView.h"
  8. #include "ChatClientView.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  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_MESSAGE(WM_TRAY_NOTIFY,OnSHMenu)
  21. ON_WM_SYSCOMMAND()
  22. //}}AFX_MSG_MAP
  23. ON_UPDATE_COMMAND_UI(ID_INDICATOR_START,OnIndicatorStart)
  24. ON_UPDATE_COMMAND_UI(ID_INDICATOR_STOP,OnIndicatorStop)
  25. END_MESSAGE_MAP()
  26. static UINT indicators[] =
  27. {
  28. ID_SEPARATOR,           // status line indicator
  29. ID_INDICATOR_START,
  30. ID_INDICATOR_STOP,
  31. ID_INDICATOR_CAPS,
  32. ID_INDICATOR_NUM,
  33. ID_INDICATOR_SCRL,
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame construction/destruction
  37. extern BOOL Started;
  38. CMainFrame::CMainFrame()
  39. {
  40. // TODO: add member initialization code here
  41. Started=FALSE;
  42. }
  43. CMainFrame::~CMainFrame()
  44. {
  45. Shell_NotifyIcon(NIM_DELETE,&m_nTrayData);
  46. }
  47. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  48. {
  49. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  50. return -1;
  51. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  52. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  53. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  54. {
  55. TRACE0("Failed to create toolbarn");
  56. return -1;      // fail to create
  57. }
  58. if (!m_wndStatusBar.Create(this) ||
  59. !m_wndStatusBar.SetIndicators(indicators,
  60.   sizeof(indicators)/sizeof(UINT)))
  61. {
  62. TRACE0("Failed to create status barn");
  63. return -1;      // fail to create
  64. }
  65. // TODO: Delete these three lines if you don't want the toolbar to
  66. //  be dockable
  67. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  68. EnableDocking(CBRS_ALIGN_ANY);
  69. DockControlBar(&m_wndToolBar);
  70. m_nTrayData.cbSize=sizeof(NOTIFYICONDATA);
  71. m_nTrayData.hWnd=m_hWnd;
  72. m_nTrayData.uID=0;
  73. m_nTrayData.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  74. m_nTrayData.uCallbackMessage=WM_TRAY_NOTIFY;
  75. strcpy(m_nTrayData.szTip,"显示万能服务");
  76. m_nTrayData.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
  77. Shell_NotifyIcon(NIM_ADD,&m_nTrayData);
  78. return 0;
  79. }
  80. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  81. {
  82. if( !CFrameWnd::PreCreateWindow(cs) )
  83. return FALSE;
  84. // TODO: Modify the Window class or styles here by modifying
  85. //  the CREATESTRUCT cs
  86. CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN),
  87. GetSystemMetrics (SM_CYSCREEN)); 
  88. cs.cx=sizeScreen.cx*SCALE;
  89. cs.cy=sizeScreen.cy*SCALE;
  90. cs.style&=~WS_MAXIMIZEBOX;
  91. return TRUE;
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CMainFrame diagnostics
  95. #ifdef _DEBUG
  96. void CMainFrame::AssertValid() const
  97. {
  98. CFrameWnd::AssertValid();
  99. }
  100. void CMainFrame::Dump(CDumpContext& dc) const
  101. {
  102. CFrameWnd::Dump(dc);
  103. }
  104. #endif //_DEBUG
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMainFrame message handlers
  107. void CMainFrame::OnIndicatorStart(CCmdUI* pCmdUI)
  108. {
  109. pCmdUI->Enable(Started);
  110. }
  111. void CMainFrame::OnIndicatorStop(CCmdUI* pCmdUI)
  112. {
  113. pCmdUI->Enable(!Started);
  114. }
  115. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  116. {
  117. CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN),
  118. GetSystemMetrics (SM_CYSCREEN)); 
  119. if (!m_splitterWnd.CreateStatic(this,3,1))
  120. return FALSE;
  121. if (!m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CAnyServerView),CSize(sizeScreen.cx*SCALE,sizeScreen.cy*3*SCALE/10),pContext)||
  122. !m_splitterWnd.CreateView(1,0,RUNTIME_CLASS(CChatView),CSize(sizeScreen.cx*SCALE,sizeScreen.cy*SCALE/5),pContext)||
  123. !m_splitterWnd.CreateView(2,0,RUNTIME_CLASS(CChatClientView),CSize(0,0),pContext))
  124. return FALSE;
  125. return TRUE;
  126. }
  127. LRESULT CMainFrame::OnSHMenu(WPARAM wParam,LPARAM lParam)
  128. {
  129. if (lParam==WM_LBUTTONDOWN)
  130. {
  131. ShowWindow(SW_RESTORE);
  132. BringWindowToTop();
  133. UpdateWindow();
  134. }
  135. else if (lParam==WM_RBUTTONDOWN)
  136. {
  137. CMenu menu;
  138. menu.LoadMenu(IDR_TRAYMENU);
  139. CMenu* pPopup=menu.GetSubMenu(0);
  140. CRect screen;
  141. GetDesktopWindow()->GetWindowRect(&screen);
  142. pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,screen.right,screen.bottom,AfxGetMainWnd());
  143. }
  144. return 0;
  145. }
  146. void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) 
  147. {
  148. // TODO: Add your message handler code here and/or call default
  149. CFrameWnd::OnSysCommand(nID, lParam);
  150. if (nID==SC_MINIMIZE)
  151. ShowWindow(SW_HIDE);
  152. else  if (nID==SC_RESTORE)
  153. {
  154. ShowWindow(SW_SHOW);
  155. BringWindowToTop();
  156. }
  157. }