// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "CheckServer.h" #include "MainFrm.h" #include "ServerSocket.h" #include "CheckServerView.h" #include "..\\Common\\IPInfos.h" #include "SvrOptionDlg.h" #include "WebReloadThread.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame UINT CMainFrame::tm_CMainFrameOnWebNewsFinded = ::RegisterWindowMessage( "CMainFrame OnWebNewsFinded" ); IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_CLOSE() ON_WM_TIMER() ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECTION_STATUS, OnUpdateConnectionStatus) ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECTION_CLIENTS, OnUpdateConnectionClients) ON_COMMAND(ID_OPERATIONS_STARTSERVER, OnOperationsStartserver) ON_UPDATE_COMMAND_UI(ID_OPERATIONS_STARTSERVER, OnUpdateOperationsStartserver) ON_COMMAND(ID_OPERATIONS_STOPSERVER, OnOperationsStopserver) ON_UPDATE_COMMAND_UI(ID_OPERATIONS_STOPSERVER, OnUpdateOperationsStopserver) ON_COMMAND(ID_OPTIONS_PREFERENCES, OnOptionsPreferences) //}}AFX_MSG_MAP ON_REGISTERED_MESSAGE( tm_CMainFrameOnWebNewsFinded, OnWebNewsFinded ) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CONNECTION_STATUS, ID_INDICATOR_CONNECTION_CLIENTS, ID_INDICATOR_TIME, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_pApp = (CCheckServerApp*)AfxGetApp(); m_pView = NULL; m_pServerSocket = NULL; m_bServerStarted = FALSE; m_nPort = 1500; m_pCWebReloadThread = NULL; m_strURL[0] = "http://dart.fss.or.kr/dart/TodayDisclosure?type=listing&sort=time&dayCh=0"; // °Å·¡¼Ò°ø½Ã m_strURL[1] = "http://dart.fss.or.kr/dart/TodayDisclosure?type=kosdaq&sort=time&dayCh=0"; // ÄÚ½º´Ú°ø½Ã } CMainFrame::~CMainFrame() { } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style = WS_OVERLAPPEDWINDOW; return TRUE; } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; SetMessageText("ÇÁ·Î±×·¥ ÁغñÁß..."); 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 toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_STATUS), ID_INDICATOR_CONNECTION_STATUS, SBPS_POPOUT, 40); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_CLIENTS), ID_INDICATOR_CONNECTION_CLIENTS, SBPS_NORMAL, 65); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME), ID_INDICATOR_TIME, SBPS_NORMAL, 110); // 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); CString szBuf; szBuf.LoadString(AFX_IDS_APP_TITLE); //Change title caption SetWindowText(szBuf); SetTimer(ID_TIMER_TIME, TIMER_TIME_VALUE, NULL); ////////////////////////////////////////////////////////////////////////////// // À¥ ¸±·Îµå ¾²·¹µå ½ÃÀÛ. ////////////////////////////////////////////////////////////////////////////// m_pCWebReloadThread = (CWebReloadThread*) ::AfxBeginThread( RUNTIME_CLASS( CWebReloadThread ), THREAD_PRIORITY_BELOW_NORMAL ); ASSERT( m_pCWebReloadThread ); m_pCWebReloadThread->RegisterParent( this ); return 0; } ///////////////////////////////////////////////////////////////////////////// // 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::AddMessage(CString szName, CString szMessage) { m_pView = (CCheckServerView*)GetActiveView(); m_pView->AddMessage(GlobalHelper::GetLocalTime(), szName, szMessage); } void CMainFrame::ClearAllViews() { m_pView = (CCheckServerView*)GetActiveView(); m_pView->ClearView(); } void CMainFrame::UpdateAllView() { m_pView = (CCheckServerView*)GetActiveView(); m_pView->UpdateCols(); } void CMainFrame::UpdateClientsList(CPtrList* pClientstList) { // m_pUserListView->UpdateClientsList(pClientstList); } CPtrList* CMainFrame::GetClientsList() { if (!m_pServerSocket) return NULL; return m_pServerSocket->GetClientsList(); } void CMainFrame::OnDestroy() { CFrameWnd::OnDestroy(); } void CMainFrame::OnClose() { if (!DisconnectServer()) return; KillTimer(ID_TIMER_TIME); ////////////////////////////////////////////////////////////////////////////// // À¥ ¸±·Îµå ¾²·¹µå Á¾·á. ////////////////////////////////////////////////////////////////////////////// //Tell the thread to quit m_pCWebReloadThread->Quit( ); //Wait for the thread to quit so the object gets cleaned up before the debugger does it's shutdown heap check. ::WaitForSingleObject( m_pCWebReloadThread->m_hThread, INFINITE ); CFrameWnd::OnClose(); } LRESULT CMainFrame::OnWebNewsFinded( WPARAM wParam, LPARAM lParam ) { char* pchar = (char*) wParam; CString szBuf = CString (pchar); AddMessage( "WebNews", szBuf ); delete pchar; return NULL; } void CMainFrame::OnTimer(UINT nIDEvent) { switch (nIDEvent) { case ID_TIMER_TIME: m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME), CTime::GetCurrentTime().Format("%m/%d/%Y %H:%M:%S") ); break; default: CFrameWnd::OnTimer(nIDEvent); break; } } /*============================================================================ Description: Update the status bar connection status indicator Return: - ============================================================================*/ void CMainFrame::OnUpdateConnectionStatus(CCmdUI* pCmdUI) { m_wndStatusBar.SetPaneStyle(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_STATUS), m_bServerStarted ? SBPS_NORMAL : SBPS_POPOUT); pCmdUI->SetText(m_bServerStarted ? CString((LPCTSTR)IDS_SERVER_CONNECTED) : CString((LPCTSTR)IDS_SERVER_DISCONNECTED)); } /*============================================================================ Description: Update the status bar connection status indicator Return: - ============================================================================*/ void CMainFrame::OnUpdateConnectionClients(CCmdUI* pCmdUI) { CString szBuf; int nClients = m_pServerSocket ? m_pServerSocket->GetClientsConnectedCount() : 0; szBuf.Format("Á¢¼ÓÀÚ¼ö: %d", nClients); pCmdUI->SetText(szBuf); } void CMainFrame::OnOperationsStartserver() { CString szBuf; m_pView = (CCheckServerView*)GetActiveView(); m_pView->ClearView(); // ClearAllViews(); m_pServerSocket = new CServerSocket(this); if (m_pServerSocket->BeginListening(m_nPort, 100)) { szBuf.Format("Server started and online on port %d.", m_nPort); AddMessage( "Server", szBuf ); // m_DlgBarUtil.BlockConrols(); m_bServerStarted = TRUE; } else { DisconnectServer(); } ////////////////////////////////////////////////////////////////////////////// // À¥ ¸±·Îµå ¾²·¹µå ÀÛ¾÷½ÃÀÛ Áö½Ã. ////////////////////////////////////////////////////////////////////////////// m_pCWebReloadThread->SetURL( m_strURL ); char* pchar0 = new char[ 100 ]; strcpy( pchar0, "WebNewsFind" ); m_pCWebReloadThread->DoContinuous( pchar0 ); } void CMainFrame::OnUpdateOperationsStartserver(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bServerStarted); } void CMainFrame::OnOperationsStopserver() { BOOL bDisconnected = DisconnectServer(); // if (bDisconnected) // m_DlgBarUtil.BlockConrols(FALSE); ////////////////////////////////////////////////////////////////////////////// // À¥ ¸±·Îµå ¾²·¹µå ÀÛ¾÷Á¾·á Áö½Ã. ////////////////////////////////////////////////////////////////////////////// m_pCWebReloadThread->StopContinuous(); } void CMainFrame::OnUpdateOperationsStopserver(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bServerStarted); } BOOL CMainFrame::DisconnectServer() { if (!m_pServerSocket) return TRUE; int nClients = m_pServerSocket->GetClientsConnectedCount(); if (nClients > 0) { CString szBuf; szBuf.Format(IDS_STOP_SERVER, nClients); int nRet = MessageBox(szBuf, CString((LPCTSTR)AFX_IDS_APP_TITLE), MB_ICONQUESTION|MB_YESNO); if (nRet == IDNO) return FALSE; } AddMessage( "Server", "Server shutdown and offline!" ); if (m_pServerSocket) { delete m_pServerSocket; m_pServerSocket = NULL; } m_bServerStarted = FALSE; return TRUE; } void CMainFrame::OnOptionsPreferences() { CSvrOptionDlg dlg; CIPInfos ipinfo; int nCount = ipinfo.GetLocalIPCount(); dlg.m_strSvrIP = ""; for( int i=0; i