MainFrm.cpp
资源名称:anywhere.zip [点击查看]
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:15k
源码类别:
远程控制编程
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "anywhere.h"
- //所有的视的指针
- #include "history.h"//历史记录
- #include "sysinfo.h"//系统信息
- #include "filesource.h"//文件资源
- #include "scrview.h"//看图
- #include "remotec.h"
- #include "option.h"
- #include "thread1.h"
- #include "talk.h"
- //#include "talksocket.h"
- //#include "maincontrol.h"
- //#include "leftview.h"//控制菜单
- //#include "blocksock.h"
- #include "MainFrm.h"
- #include "sitebook.h"
- //#include "msgman.h"
- #include "anywheredoc.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)
- ON_COMMAND_EX(CG_ID_VIEW_WORKSPACE, OnBarCheck)
- ON_UPDATE_COMMAND_UI(CG_ID_VIEW_WORKSPACE, OnUpdateControlBarMenu)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_MESSAGE(WM_SETACTIVE,OnSetActive)
- ON_COMMAND(ID_VIEWSCR, OnViewscr)
- ON_COMMAND(ID_GETINFO, OnGetinfo)
- ON_COMMAND(ID_OPTION, OnOption)
- ON_COMMAND(ID_SITEBOOK, OnSitebook)
- ON_COMMAND(IDS_DISCONNECT, OnDisconnect)
- ON_UPDATE_COMMAND_UI(IDS_DISCONNECT, OnUpdateDisconnect)
- ON_UPDATE_COMMAND_UI(ID_GETINFO, OnUpdateGetinfo)
- ON_UPDATE_COMMAND_UI(ID_LISTFILE, OnUpdateListfile)
- ON_UPDATE_COMMAND_UI(ID_VIEWSCR, OnUpdateViewscr)
- ON_WM_CLOSE()
- ON_UPDATE_COMMAND_UI(ID_OPTION, OnUpdateOption)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- //m_pMsgman=new CMsgman;//消息链表管理者
- //test code temp linkrc initial
- //linkrc.sAddr=CSockAddr("192.168.168.168",7700);
- bFirst=true;
- }
- CMainFrame::~CMainFrame()
- {
- //delete m_pMsgman;
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.CreateEx(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- m_wndToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeHot, RGB( 33, 231, 222 ) );
- m_wndToolBar.SetBitmap( IDB_LG_BW, COOBmpToolBar::LargeStandard, RGB( 33, 231, 222 ) );
- m_wndToolBar.SetBitmap( IDB_LG_DB, COOBmpToolBar::LargeDisable, RGB( 170, 170, 170 ) );
- m_wndToolBar.InitImageList();
- // set button to dropdown list
- m_wndToolBar.SetButtonDropDown( ID_FILE_OPEN );
- m_wndToolBar.SetButtonDropDown( ID_FILE_SAVE );
- /* if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
- CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
- {
- TRACE0("Failed to create dialogbarn");
- return -1; // fail to create
- }
- */
- if (!m_wndReBar.Create(this) ||
- !m_wndReBar.AddBar(&m_wndToolBar))
- //||!m_wndReBar.AddBar(&m_wndDlgBar))
- {
- TRACE0("Failed to create rebarn");
- return -1; // fail to create
- }
- m_ImageList.Create(IDB_IMAGELIST, 13, 1, RGB(0,255,0));
- // CG: The following block was inserted by the 'Dialog Bar' component
- {
- m_wndWorkspace.SetBtnImageList (&m_ImageList);
- m_wndWorkspace.SetMenuID(IDR_MAINFRAME);
- // Initialize dialog bar m_wndWorkspace
- if (!m_wndWorkspace.Create(this, CG_ID_VIEW_WORKSPACE,
- _T("工作区"), CSize(280,200)))
- {
- TRACE0("Failed to create dialog bar m_wndWorkspacen");
- return -1; // fail to create
- }
- // Add the views to the tab control.
- //m_wndWorkspace.AddView(_T("远程机器"), RUNTIME_CLASS(CHistory));
- m_wndWorkspace.AddView(_T("会话"), RUNTIME_CLASS(CTalk));
- //m_wndWorkspace.AddView(_T("历史记录"), RUNTIME_CLASS(CHistory));
- // Define the image list to use with the tab control
- m_TabImageList.Create(IDB_IL_TAB, 16, 1, RGB(0,255,0));
- m_wndWorkspace.SetTabImageList(&m_TabImageList);
- //m_wndWorkspace.EnableToolTips(FALSE);
- // allow bar to be resized when floating
- m_wndWorkspace.SetBarStyle(m_wndWorkspace.GetBarStyle() |
- CBRS_FLYBY | CBRS_SIZE_DYNAMIC|CBRS_TOOLTIPS );
- m_wndWorkspace.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndWorkspace, AFX_IDW_DOCKBAR_LEFT);
- }
- /*
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- */
- 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: Remove this if you don't want tool tips
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY);
- /*
- {
- m_wndOutput.SetBtnImageList (&m_ImageList);
- m_wndOutput.SetMenuID(IDR_MAINFRAME);
- // Initialize dialog bar m_wndOutput
- if (!m_wndOutput.Create(this, CG_ID_VIEW_OUTPUT,
- _T("管理窗口"), CSize(200,100)))
- {
- TRACE0("Failed to create dialog bar m_wndOutputn");
- return -1; // fail to create
- }
- // allow bar to be resized when floating
- m_wndOutput.SetBarStyle(m_wndOutput.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndOutput, AFX_IDW_DOCKBAR_BOTTOM);
- }
- */
- Msginit();
- //test code setactive
- m_Framework.SetActivePane(pObject);
- CenterWindow(GetDesktopWindow());
- /*
- int nIndex;
- TVisualFrameworkIterator it(*m_pFx);
- while (!it.End()) {
- TVisualObject *pObject = it.Get();
- if (pObject->CanFocus()) {
- //nIndex = m_List.AddString(pObject->GetDescription());
- //pObject->GetDescription()
- m_List.SetItemData(nIndex, (DWORD)pObject);
- }
- it ++;
- }
- */
- // m_Framework.SetFont(&m_Font);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style &=~FWS_ADDTOTITLE;
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- //cs.style =~FWS_ADDTOTITLE;
- //return CFrameWnd::PreCreateWindow(cs);
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- 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
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- TVisualObject *pTab=new TVisualObject(20,"",pContext,RUNTIME_CLASS(TTabWnd),TVisualObject::TOS_TABTOP);
- TVisualObject *pTabView1 = new TVisualObject(1,"系统信息", pContext, RUNTIME_CLASS(CSysinfo));
- //TVisualObject *pTabView2 = new TVisualObject(3,"Splitter",1,2,pContext);
- TVisualObject *pTabView2 = new TVisualObject(2,"文件资源", pContext, RUNTIME_CLASS(CFileSource));
- TVisualObject *pTab2 = new TVisualObject(11,"远程控制",pContext,RUNTIME_CLASS(TTabWnd),TVisualObject::TOS_TABBOTTOM);
- TVisualObject *pTab2View1 = new TVisualObject(3,"控制菜单", pContext,RUNTIME_CLASS(CRemoteC));
- //TVisualObject *pTab2View1 = new TVisualObject(5,"控制菜单",1,2, pContext);//, RUNTIME_CLASS(CHistory));
- //TVisualObject *pTab2View11=new TVisualObject(6,0,0,pContext,RUNTIME_CLASS(CLeftView),CSize(100,0));
- //TVisualObject *pTab2View12=new TVisualObject(7,0,1,pContext,RUNTIME_CLASS(CHistory),CSize(0,0));
- //TVisualObject *pTab2View1Sp = new TVisualObject(6,"Splitter",1,2,pContext);
- TVisualObject *pTab2View2 = new TVisualObject(4,"查看屏幕", pContext,RUNTIME_CLASS(CScrView));
- //TVisualObject *pTab2View3 = new TVisualObject(5,"注册表",pContext,RUNTIME_CLASS(CHistory));
- //TVisualObject *pTab3=new TVisualObject(6,"系统设置",pContext,RUNTIME_CLASS(CHistory));
- pTabView1->SetDescription("查看系统消息");
- pTabView2->SetDescription("文件资源");
- pTab2View1->SetDescription("远程控制菜单");
- pTab2View2->SetDescription("查看远程机器屏幕");
- //pTab2View3->SetDescription("注册表");
- //pTab3->SetDescription("Manager AnyWhere系统设置");
- //TVisualObject *pTabSplitter1 = new TVisualObject(8,"系统设置",1,2,pContext);
- //TVisualObject *pSplitLeft = new TVisualObject(9,0,0,pContext,RUNTIME_CLASS(CHistory),CSize(100,0));
- //TVisualObject *pSplitRight = new TVisualObject(10,0,1,pContext,RUNTIME_CLASS(CHistory),CSize(0,0));
- m_Framework.Add(pTab);
- m_Framework.Add(pTab,pTabView1);
- m_Framework.Add(pTab,pTabView2);
- m_Framework.Add(pTab,pTab2);
- //m_Framework.Add(pTab,pTab3);
- m_Framework.Add(pTab2,pTab2View1);
- m_Framework.Add(pTab2,pTab2View2);
- //m_Framework.Add(pTab2,pTab2View3);
- //m_Framework.Add(pTabSplitter1,pSplitLeft);
- //m_Framework.Add(pTabSplitter1,pSplitRight);
- //m_Framework.Add(pTab2View1,pTab2View11);
- //m_Framework.Add(pTab2View1,pTab2View12);
- pTabView1->SetHotKey('1');
- pTabView2->SetHotKey('2');
- pTab2View1->SetHotKey('3');
- pTab2View2->SetHotKey('4');
- //m_Framework.Add(pTab1,pTabView3);
- m_Framework.Create(this);
- TVisualFrameworkIterator it(m_Framework);
- while (!it.End()) {
- TVisualObject *pObject = it.Get();
- it++;
- }
- pObject=pTab2View1;
- //m_Framework.SetActiveTab(pTab);
- //SetActiveView((CView *) pTabView1);
- //m_Framework.SetActiveTab(pTabView1);
- return TRUE;
- // return CFrameWnd::OnCreateClient(lpcs, pContext);
- }
- void CMainFrame::OnDestroy()
- {
- CFrameWnd::OnDestroy();
- m_Framework.Destroy();
- }
- void CMainFrame::Msginit()
- {
- m_hMainWnd=GetSafeHwnd();
- sendevent=CreateEvent(NULL,FALSE,TRUE,NULL);//自动重设
- recvevent=CreateEvent(NULL,FALSE,TRUE,NULL);//初始无信号
- linkrc.bChat=FALSE;
- linkrc.bConnected=FALSE;
- }
- void CMainFrame::ActivateFrame(int nCmdShow)
- {
- // TODO: Add your specialized code here and/or call the base class
- CFrameWnd::ActivateFrame(nCmdShow);
- //得到文档的指针
- POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
- CDocTemplate *ptempl=AfxGetApp()->GetNextDocTemplate(pos);
- POSITION doc_pos=ptempl->GetFirstDocPosition();
- CAnywhereDoc * pDoc=(CAnywhereDoc *)ptempl->GetNextDoc(doc_pos);
- //m_pmsgman=pDoc->m_pmsgman;
- //m_pDoc=pDoc;
- //m_pmsgman->init(GetSafeHwnd());
- //pDoc->m_pFrame=this;//add temp
- //to add
- CSitebook sitedlg;
- if ((IDOK==sitedlg.DoModal())) //& (sitedlg.select))
- {
- /*linkrc.ip=sitedlg.m_ip;
- linkrc.mainport=sitedlg.mainport;
- linkrc.getfileport=sitedlg.getfileport;
- linkrc.putfileport=sitedlg.putfileport;
- linkrc.viewport=sitedlg.viewport;
- linkrc.username=sitedlg.m_username;
- linkrc.password=sitedlg.m_password;
- linkrc.sAddr=CSockAddr(linkrc.ip,linkrc.mainport);
- //设定主端口及ip
- //strcpy(linkrc.sbuf,linkrc.username);
- //strcat(linkrc.sbuf,linkrc.password);
- linkrc.bConnected=FALSE;*/
- //strcpy(linkrc.sbuf,"GETINFO*");
- /*m_pmsgman->AddMsg("START","开始工作,与远程机器连接",
- first,TRUE,linkrc.sAddr,2);
- */
- /*m_pmsgman->AddMsg("GETINFO*","得到远程机器的信息",
- first,TRUE,linkrc.sAddr,2);*/
- //m_pmsgman->SendMsg("GETINFO*");
- OnGetinfo();
- }
- }
- LRESULT CMainFrame::OnSetActive(WPARAM wParam, LPARAM lParam)
- {
- // TODO: 处理用户自定义消息
- //TVisualFramework m_Fx;
- int id=0;
- CString text=*(CString*)lParam;
- /*if (text.Left(8)=="ENDSERVE") {
- id=Respones(text);
- return 1;
- }*/
- if ((BOOL)wParam) {
- id=Respones(text);//处理消息
- }
- else return 0;//失败返回
- //delete (char *)lParam;//
- TVisualFrameworkIterator it(m_Framework);
- while (!it.End()) {
- TVisualObject *pObject = it.Get();
- if ((pObject->CanFocus()) & (pObject->GetID()==id)) {
- if (id==2)
- ((CFileSource *)(pObject->GetSafeWnd()))->message(text);
- if (id==4)
- ((CScrView *)(pObject->GetSafeWnd()))->message(text);
- if (id==1)
- ((CSysinfo *)(pObject->GetSafeWnd()))->message(text);
- m_Framework.SetActivePane(pObject);
- break;
- //nIndex = m_List.AddString(pObject->GetDescription());
- //m_List.SetItemData(nIndex, (DWORD)pObject);
- }
- it ++;
- }
- //OnTest2();
- return 0;
- }
- void CMainFrame::OnViewscr()
- {
- DWORD ThreadId;
- strcpy(linkrc.sbuf,"VIEWSCR*");//"查看远程机器屏幕"
- linkrc.m_hWnd=GetSafeHwnd();
- CreateThread(NULL,0,ViewScr,&linkrc,0,&ThreadId);
- //m_pmsgman->SendMsg("VIEWSCR*");
- }
- void CMainFrame::OnGetinfo()
- {
- DWORD ThreadId;
- strcpy(linkrc.sbuf,"GETINFO*");//发送'getinfo*'该信息
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- /*if (!(m_pmsgman->AddMsg("GETINFO*","请求获得远程机器的系统信息",
- first,TRUE,linkrc.sAddr,2)))
- MessageBox("终止该条命令"," 提示:",MB_OK);
- */
- //m_pmsgman->SendMsg("GETINFO*");
- }
- int CMainFrame::Respones(CString &text)
- {
- CString order=text.Left(8);
- int length=text.GetLength();
- text=text.Right(length-8);//text已更改为主要内容
- length=text.GetLength();
- if (order=="GETINFO*")
- return 1;
- if (order=="VIEWSCR*")
- return 4;
- if (order=="LISTFILE")
- {
- text=order+text;
- return 2;
- }
- if (order=="FINDFILE")
- {
- text=order+text;
- return 2;
- }
- if (order=="ENDSERVE")
- {
- CString sEnd,caption;
- sEnd.LoadString(IDS_ENDSERVER_OK);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sEnd,caption,MB_OK);
- linkrc.bConnected=FALSE;//置为断开连接
- }
- return 0;//返回值是窗口的id
- }
- void CMainFrame::OnOption()
- {
- COption option;
- option.DoModal();
- }
- void CMainFrame::OnSitebook()
- {
- CSitebook sitedlg;
- if (IDOK==sitedlg.DoModal())// & (sitedlg.select))
- OnGetinfo();
- }
- void CMainFrame::OnDisconnect()
- {
- CString sAskmsg,caption;
- sAskmsg.LoadString(IDS_ENDSERVER_ASK);
- caption.LoadString(IDS_CAPTION);
- if (IDYES==MessageBox(sAskmsg,caption,MB_YESNO))
- {
- DWORD ThreadId;
- strcpy(linkrc.sbuf,"ENDSERVE");//发送'getinfo*'该信息
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- }
- void CMainFrame::OnUpdateDisconnect(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(linkrc.bConnected);
- }
- void CMainFrame::OnUpdateGetinfo(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(linkrc.bConnected);
- }
- void CMainFrame::OnUpdateListfile(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(linkrc.bConnected);
- }
- void CMainFrame::OnUpdateViewscr(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(linkrc.bConnected);
- }
- void CMainFrame::OnClose()
- {
- if (linkrc.bConnected) {
- DWORD ThreadId;
- strcpy(linkrc.sbuf,"ENDSERVE");//发送'getinfo*'该信息
- linkrc.m_hWnd=GetSafeHwnd();
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- WaitForSingleObject(recvevent,INFINITE);
- //Sleep(10000);
- }
- CFrameWnd::OnClose();
- }
- void CMainFrame::OnUpdateOption(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(linkrc.bConnected);
- }