MainFrm.cpp
资源名称:(vc).rar [点击查看]
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:5k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "AnyServer.h"
- #include "MainFrm.h"
- #include "AnyServerView.h"
- #include "ChatView.h"
- #include "ChatClientView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_MESSAGE(WM_TRAY_NOTIFY,OnSHMenu)
- ON_WM_SYSCOMMAND()
- //}}AFX_MSG_MAP
- ON_UPDATE_COMMAND_UI(ID_INDICATOR_START,OnIndicatorStart)
- ON_UPDATE_COMMAND_UI(ID_INDICATOR_STOP,OnIndicatorStop)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_START,
- ID_INDICATOR_STOP,
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- extern BOOL Started;
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- Started=FALSE;
- }
- CMainFrame::~CMainFrame()
- {
- Shell_NotifyIcon(NIM_DELETE,&m_nTrayData);
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- m_nTrayData.cbSize=sizeof(NOTIFYICONDATA);
- m_nTrayData.hWnd=m_hWnd;
- m_nTrayData.uID=0;
- m_nTrayData.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
- m_nTrayData.uCallbackMessage=WM_TRAY_NOTIFY;
- strcpy(m_nTrayData.szTip,"显示万能服务");
- m_nTrayData.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
- Shell_NotifyIcon(NIM_ADD,&m_nTrayData);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN),
- GetSystemMetrics (SM_CYSCREEN));
- cs.cx=sizeScreen.cx*SCALE;
- cs.cy=sizeScreen.cy*SCALE;
- cs.style&=~WS_MAXIMIZEBOX;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnIndicatorStart(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(Started);
- }
- void CMainFrame::OnIndicatorStop(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!Started);
- }
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN),
- GetSystemMetrics (SM_CYSCREEN));
- if (!m_splitterWnd.CreateStatic(this,3,1))
- return FALSE;
- if (!m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CAnyServerView),CSize(sizeScreen.cx*SCALE,sizeScreen.cy*3*SCALE/10),pContext)||
- !m_splitterWnd.CreateView(1,0,RUNTIME_CLASS(CChatView),CSize(sizeScreen.cx*SCALE,sizeScreen.cy*SCALE/5),pContext)||
- !m_splitterWnd.CreateView(2,0,RUNTIME_CLASS(CChatClientView),CSize(0,0),pContext))
- return FALSE;
- return TRUE;
- }
- LRESULT CMainFrame::OnSHMenu(WPARAM wParam,LPARAM lParam)
- {
- if (lParam==WM_LBUTTONDOWN)
- {
- ShowWindow(SW_RESTORE);
- BringWindowToTop();
- UpdateWindow();
- }
- else if (lParam==WM_RBUTTONDOWN)
- {
- CMenu menu;
- menu.LoadMenu(IDR_TRAYMENU);
- CMenu* pPopup=menu.GetSubMenu(0);
- CRect screen;
- GetDesktopWindow()->GetWindowRect(&screen);
- pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,screen.right,screen.bottom,AfxGetMainWnd());
- }
- return 0;
- }
- void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
- {
- // TODO: Add your message handler code here and/or call default
- CFrameWnd::OnSysCommand(nID, lParam);
- if (nID==SC_MINIMIZE)
- ShowWindow(SW_HIDE);
- else if (nID==SC_RESTORE)
- {
- ShowWindow(SW_SHOW);
- BringWindowToTop();
- }
- }