MainFrm.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:9k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "play.h"
- #include "MainFrm.h"
- #include "playView.h"
- #include <afxmt.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define strDESTPORT " 201"
- CMenu PopMenu;
- extern CEvent g_eventClearup;
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_VIEW_STATUS_BAR, OnViewStatusBar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_STATUS_BAR, OnUpdateViewStatusBar)
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WSA_READ,OnRead)
- ON_MESSAGE(WSA_ACCEPT,OnAccept)
- ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_SEPARATOR,
- ID_SEPARATOR,
- ID_SEPARATOR,
- };
- IMPLEMENT_DYNAMIC(COutlookBar,CGfxOutBarCtrl)
- BEGIN_MESSAGE_MAP(COutlookBar,CGfxOutBarCtrl)
- //{{AFX_MSG_MAP(COutlookBar)
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
-
- END_MESSAGE_MAP()
- BOOL COutlookBar::OnEraseBkgnd(CDC* pDC)
- {
- crBackGroundColor = RGB(0,168,150);
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- LRESULT CMainFrame::OnOutbarNotify(WPARAM wParam, LPARAM lParam)
- {
- if((wParam)==NM_OB_ITEMCLICK)
- {
- CPlayView* pView=(CPlayView*)m_wndSplitter.GetPane(0,1);
- ::SendMessage(pView->m_hWnd,WM_VIEW_OUTBAR_NOTIFY,wParam,lParam);
- }
- return 0;
- }
- //响应消息WSA_ACCEPT
- LRESULT CMainFrame::OnAccept(WPARAM wParam,LPARAM lParam)
- {
- int acsock;
- int status;
- if (WSAGETSELECTERROR( lParam ))
- return -1;
- if (WSAGETSELECTERROR( lParam ) == 0)
- { /* Success */
- int req_sin_len = sizeof(req_sin );
-
- //接受客户的连接请求
- acsock = accept(Lsock,(struct sockaddr FAR *) &req_sin,(int FAR *)&req_sin_len);
- if (acsock < 0)
- {
- MessageBox("Cant Accepted a connection!");
- return -1;
- }
- //设定服务器响应的网络事件为FD_READ或FD_CLOSE,即读取数据或关闭socket
- //产生相应传递给窗口的消息为WSA_READ
- if ((status = WSAAsyncSelect(acsock, m_hWnd,WSA_READ,FD_READ|FD_CLOSE))<0)
- {
- MessageBox("Error on WSAAsyncSelect()");
- closesocket(acsock );
- return -1;
- }
- }
- return 0;
- }
- //响应消息WSA_READ
- LRESULT CMainFrame::OnRead(WPARAM wParam,LPARAM lParam)
- {
- int status;
- char szRev[80];
- char szBuff[80];
- char szSend[80];
- strcpy(szSend,MULTIDESTADDR);
- strcat(szSend, strDESTPORT);
- if (WSAGETSELECTERROR( lParam ))
- return -1;
- if (WSAGETSELECTEVENT(lParam) == FD_READ)
- {//网络事件为FD_READ
- //接收数据
- status =recv(wParam, szRev, 80,0);
- if (status)
- {
- //如果客户端请求发送数据,将组播地址和端口发送给客户端
- if (strcmp(szRev,"请发送数据")==0)
- {
- sprintf(szBuff,"来自%s请求数据",inet_ntoa(req_sin.sin_addr));
- MessageBox(szBuff, "Client Request Data", MB_OK);
- //发送组播地址和端口给客户端
- send(wParam, szSend, sizeof(szSend),0);
- }
-
- }
- else
- if(status==0)
- MessageBox("Connection was closed by client", "Server", MB_OK);
- }
- else
- { //网络事件为FD_CLOSE
- //表示对方已接收到地址信息
- MessageBox("可以发送数据", "success", MB_OK);
- //关闭socket
- closesocket((SOCKET)wParam);
- }
- return 0;
- }
- CMainFrame::CMainFrame()
- {
-
-
- }
- CMainFrame::~CMainFrame()
- {
-
- }
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- // Create the splitter window with two columns
- if (!m_wndSplitter.CreateStatic(this, 1, 2))
- {
- TRACE0("Failed to create splitter windown");
- return FALSE;
- }
-
- if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CPlayView),
- CSize(0, 0), pContext))
- {
- TRACE0("Failed to create CTestViewn");
- return FALSE;
- }
- DWORD dwStyle =
- CGfxOutBarCtrl::fDragItems |
- CGfxOutBarCtrl::fEditGroups |
- CGfxOutBarCtrl::fEditItems |
- CGfxOutBarCtrl::fRemoveGroups |
- CGfxOutBarCtrl::fRemoveItems |
- CGfxOutBarCtrl::fAddGroups |
- CGfxOutBarCtrl::fAnimation;
-
- // Here we create the outbar control; we give as id the parent splitter pane id here
- if (!m_wndOutlookBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0),
- &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), dwStyle))
- {
- TRACE0("Failed to create outlook bar.");
- return FALSE;
- }
- // UINT nid=m_wndSplitter.IdFromRowCol(0, 0);
- // Tell the control to send message to this window (the mainframe)
- // and not to its real parent (the splitter)
- m_wndOutlookBar.SetOwner(this);
- // Here we create the imagelists for the control
- m_ImageLarge.Create (32, 32, TRUE, 2, 1);
- for( int nIcon = 0; nIcon <12; ++nIcon )
- {
- HICON hIcon = AfxGetApp()->LoadIcon(CPlayApp::m_nImages[nIcon]);
- ASSERT(hIcon);
- m_ImageLarge.Add(hIcon);
- }
- // and we link them to the control
- m_wndOutlookBar.SetImageList(&m_ImageLarge, CGfxOutBarCtrl::fLargeIcon);
- m_wndOutlookBar.SetAnimationTickCount(20);
- m_wndOutlookBar.SetAnimSelHighlight(200);
- // Look at function reference for information about linking image list
- // Here we can add the folders to the control; we need at least one folder.
- // The numbers aside the text are an "lParam" value we can assign to each folder
- m_wndOutlookBar.AddFolder(_T("播放视频文件"),PLAY);
- m_wndOutlookBar.AddFolder(_T("采集视频文件"),CAPTURE);
- // m_wndOutlookBar.AddFolder(_T("发送数据"),SEND);
- // Here we insert the items; syntax is folder, index, text, image, lParam value for item
- m_wndOutlookBar.InsertItem(PLAY, Play_Set, _T("播放设置"), 0, 0);
- m_wndOutlookBar.InsertItem(PLAY, Play_Open, _T("打开视频文件"),1,0);
- m_wndOutlookBar.InsertItem(PLAY, Play_Begin, _T("开始播放"),2,0);
- m_wndOutlookBar.InsertItem(PLAY, Play_Pause, _T("暂停播放"),3,0);
- m_wndOutlookBar.InsertItem(PLAY, Play_Resume, _T("继续播放"),4, 0);
- m_wndOutlookBar.InsertItem(PLAY, Play_Stop, _T("停止"),5, 0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Preview, _T("实时播放"),6,0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Set, _T("采集文件设置"),7,0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Begin, _T("开始采集"),8,0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Pause, _T("暂停采集"),9,0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Resume, _T("继续采集"),10,0);
- m_wndOutlookBar.InsertItem(CAPTURE, Cap_Stop, _T("停止采集"),11,0);
-
- /* m_wndOutlookBar.InsertItem(SEND, Real_Set, _T("实时发送"), 12, 0);
- m_wndOutlookBar.InsertItem(SEND, Play_Open, _T("发送文件"),13,0);
- m_wndOutlookBar.InsertItem(SEND, Play_Begin, _T("开始发送"),14,0);
- m_wndOutlookBar.InsertItem(SEND, Play_Pause, _T("停止发送"),15,0);*/
-
- m_wndOutlookBar.SetSelFolder(1);
-
- // Standard sizing for splitter
- CRect r;
- GetClientRect(&r);
- int w1 = r.Width()/7;
- int w2 = r.Width()/5;
- m_wndSplitter.SetColumnInfo( 0, w1, 0 );
- m_wndSplitter.SetColumnInfo( 1, w2, 0 );
- m_wndSplitter.RecalcLayout();
- return TRUE;
- }
- 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,WS_CHILD|WS_VISIBLE|CBRS_BOTTOM,ID_MY_STATUSBAR) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- m_wndStatusBar.SetPaneInfo(0,0,0,270);
- // 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);
- PopMenu.LoadMenu(IDR_POPUP);
- 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
- 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::OnViewStatusBar()
- {
- // TODO: Add your command handler code here
- m_wndStatusBar.ShowWindow((m_wndStatusBar.GetStyle()&WS_VISIBLE)==0);
- RecalcLayout();
- }
- void CMainFrame::OnUpdateViewStatusBar(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck((m_wndStatusBar.GetStyle()&WS_VISIBLE)!=0);
- pCmdUI->SetCheck(m_wndStatusBar.ShowWindow(m_wndStatusBar.GetStyle()));
- }
- void CMainFrame::ActivateFrame(int nCmdShow)
- {
- // TODO: Add your specialized code here and/or call the base class
- m_wndSplitter.SetActivePane(0,1,NULL);
- nCmdShow=SW_MAXIMIZE;
- CFrameWnd::ActivateFrame(nCmdShow);
- }
- void CMainFrame::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- CPlayView* pView=(CPlayView*)GetActiveView();
- pView->SendMessage(WM_PREPARE_CLOSE);
- ::WaitForSingleObject(g_eventClearup,0);
- CFrameWnd::OnClose();
- }