// ConnectionDialog.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù. // #include "stdafx.h" #include "ServiceMonitor.h" #include "ConnectionDialog.h" #include "SubControlBaseView.h" #include "ConfigMngr.h" #include "NetConnection.h" #include "VarArg.hpp" #include "MainFrm.h" #include "NetConnection.h" #include "BasePartitionView.h" // CConnectionDialog ´ëÈ­ »óÀÚÀÔ´Ï´Ù. IMPLEMENT_DYNAMIC(CConnectionDialog, CDialog) CConnectionDialog::CConnectionDialog(CWnd* pParent /*=NULL*/) : CDialog(CConnectionDialog::IDD, pParent) { } CConnectionDialog::~CConnectionDialog() { } void CConnectionDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_IPADDRESS_SVMN, m_IpAddress); DDX_Control(pDX, IDC_PORT_SVMN, m_PortNo); DDX_Control(pDX, IDC_ID_SVMN, m_ID); DDX_Control(pDX, IDC_PASS_SVMN, m_Pass); } BEGIN_MESSAGE_MAP(CConnectionDialog, CDialog) ON_WM_TIMER() ON_WM_DESTROY() ON_BN_CLICKED(IDC_CNNDLG_CONNECT, &CConnectionDialog::OnBnClickedButtonConnect) ON_BN_CLICKED(IDC_CNNDLG_DISCONNECT, &CConnectionDialog::OnBnClickedButtonDisconnect) ON_BN_CLICKED(IDC_CNNDLG_CANCEL, &CConnectionDialog::OnBnClickedCnndlgCancel) ON_WM_PAINT() ON_WM_SIZE() ON_WM_LBUTTONDOWN() ON_WM_CLOSE() END_MESSAGE_MAP() void CConnectionDialog::SaveConfig() { { DWORD aIpAddress; m_IpAddress.GetAddress(aIpAddress); CConfigMngr::GetInstancePtr()->m_IpAddress.Set(static_cast(::htonl(aIpAddress))); } { USES_CONVERSION; TCHAR aPortNo[8] = { _T('\0'), }; m_PortNo.GetWindowText(aPortNo, _countof(aPortNo)); CConfigMngr::GetInstancePtr()->m_PortNo = static_cast(_ttoi(aPortNo)); } { USES_CONVERSION; TCHAR aID[SMIDLENMAX+1] = { _T('\0'), }; m_ID.GetWindowText(aID, _countof(aID)); CConfigMngr::GetInstancePtr()->m_ID = aID; } } void CConnectionDialog::EnableButton(BOOL pIsConnect) { GetDlgItem(IDC_CNNDLG_CONNECT)->EnableWindow(!pIsConnect); GetDlgItem(IDC_CNNDLG_DISCONNECT)->EnableWindow(pIsConnect); } CString CConnectionDialog::GetID() const { CString aRetVal; TCHAR aID[SMIDLENMAX+1] = { _T('\0'), }; m_ID.GetWindowText(aID, _countof(aID)); aRetVal = aID; return aRetVal; } CString CConnectionDialog::GetPass() const { CString aRetVal; TCHAR aPass[SMPASSLENMAX+1] = { _T('\0'), }; m_Pass.GetWindowText(aPass, _countof(aPass)); aRetVal = aPass; return aRetVal; } // CConnectionDialog ¸Þ½ÃÁö 󸮱âÀÔ´Ï´Ù. BOOL CConnectionDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ­ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù. CenterWindow(); { m_IpAddress.SetAddress(::htonl(CConfigMngr::GetInstancePtr()->m_IpAddress.GetDecimal())); } { USES_CONVERSION; m_PortNo.SetWindowText(I2T(CConfigMngr::GetInstancePtr()->m_PortNo)); } { m_ID.SetWindowText(CConfigMngr::GetInstancePtr()->m_ID); } SetTimer(EV_TMD_UPDATECONNECTDIALOG, g_TimerInterval[EV_TMD_UPDATECONNECTDIALOG - EV_TIMERID_DEF], NULL); return TRUE; // return TRUE unless you set the focus to a control // ¿¹¿Ü: OCX ¼Ó¼º ÆäÀÌÁö´Â FALSE¸¦ ¹ÝÈ¯ÇØ¾ß ÇÕ´Ï´Ù. } BOOL CConnectionDialog::PreTranslateMessage(MSG* pMsg) { // TODO: ¿©±â¿¡ Ư¼öÈ­µÈ Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº» Ŭ·¡½º¸¦ È£ÃâÇÕ´Ï´Ù. switch(pMsg->message) { case WM_KEYDOWN: { switch(pMsg->wParam) { case VK_ESCAPE: // return TRUE; // ESC Ű¿¡ ´ëÇÑ ¿¬°áâ ÇØÁ¦´Â Çã¿ë (CDialog::OnCancel() È£Ãâµµ ÇÔ²² À¯ÁöµÇ¾î¾ß ÇÔ) break; } } break; } return CDialog::PreTranslateMessage(pMsg); } void CConnectionDialog::OnOK() { // TODO: ¿©±â¿¡ Ư¼öÈ­µÈ Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº» Ŭ·¡½º¸¦ È£ÃâÇÕ´Ï´Ù. // CDialog::OnOK(); } void CConnectionDialog::OnCancel() { // TODO: ¿©±â¿¡ Ư¼öÈ­µÈ Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº» Ŭ·¡½º¸¦ È£ÃâÇÕ´Ï´Ù. SaveConfig(); CDialog::OnCancel(); } void CConnectionDialog::OnTimer(UINT_PTR nIDEvent) { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. switch(nIDEvent) { case EV_TMD_UPDATECONNECTDIALOG: { DWORD aIpAddress = 0; m_IpAddress.GetAddress(aIpAddress); ULONG nConID = ::htonl(aIpAddress); CNetConnection* pNetConnection = CNetConnectionMgr::GetInstancePtr()->GetConnection (nConID); if (pNetConnection) // ±âÁ¸¿¡ Á¢¼ÓÇÑ °æ¿ì { CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) BASE_RETURN_NONE; if (pNetSession->IsConnect()) { if (GetDlgItem(IDC_CNNDLG_CONNECT)->IsWindowEnabled()) GetDlgItem(IDC_CNNDLG_CONNECT)->EnableWindow(FALSE); if (!GetDlgItem(IDC_CNNDLG_DISCONNECT)->IsWindowEnabled()) GetDlgItem(IDC_CNNDLG_DISCONNECT)->EnableWindow(TRUE); } else { if (!GetDlgItem(IDC_CNNDLG_CONNECT)->IsWindowEnabled()) GetDlgItem(IDC_CNNDLG_CONNECT)->EnableWindow(TRUE); if (GetDlgItem(IDC_CNNDLG_DISCONNECT)->IsWindowEnabled()) GetDlgItem(IDC_CNNDLG_DISCONNECT)->EnableWindow(FALSE); } } else // »õ·Î¿î ÁÖ¼ÒÀÎ °æ¿ì { GetDlgItem(IDC_CNNDLG_CONNECT)->EnableWindow(TRUE); GetDlgItem(IDC_CNNDLG_DISCONNECT)->EnableWindow(TRUE); } } break; default: break; } CDialog::OnTimer(nIDEvent); } void CConnectionDialog::OnDestroy() { CDialog::OnDestroy(); // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. KillTimer(EV_TMD_UPDATECONNECTDIALOG); } void CConnectionDialog::OnBnClickedButtonConnect() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. DWORD aIpAddress = 0; TCHAR aPortNo[8] = { _T('\0'), }; { m_IpAddress.GetAddress(aIpAddress); m_PortNo.GetWindowText(aPortNo, _countof(aPortNo)); } if (INADDR_ANY == aIpAddress || INADDR_NONE == aIpAddress) { ::AfxMessageBox(_T("IP Address is not valid !"), MB_ICONERROR); return; } if (0 == aPortNo) { ::AfxMessageBox(_T("Port Number is not valid !"), MB_ICONERROR); return; } ULONG nConID = ::htonl(aIpAddress); CNetConnection* pNetConnection = CNetConnectionMgr::GetInstancePtr()->GetConnection (nConID); if (pNetConnection) // ±âÁ¸¿¡ Á¢¼ÓÇÑ °æ¿ì { CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) BASE_RETURN_NONE; DWORD dwRetVal = pNetSession->Connect(::htonl(static_cast(aIpAddress)), static_cast(_ttoi(aPortNo))); if (NOERROR != dwRetVal) BASE_RETURN_NONE; } else // óÀ½Á¢¼ÓÇÏ´Â °æ¿ì { // ¾Æ·¡ È£Ãâ ¼ø¼­´ë·Î ÇØ¾ß Á¤»óÀÛµ¿ÇÕ´Ï´Ù. pNetConnection = CNetConnectionMgr::GetInstancePtr()->CreateConnection(); if (!pNetConnection) BASE_RETURN_NONE; CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) BASE_RETURN_NONE; CMainFrame* pMainFrame = static_cast(::AfxGetApp())->GetMainFrame(); if (!pMainFrame) BASE_RETURN_NONE; CBasePartitionView* pPartitionView = pMainFrame->AddPartition (pNetConnection, nConID); if (!pPartitionView) BASE_RETURN_NONE; DWORD dwRetVal = pNetSession->Connect(::htonl(static_cast(aIpAddress)), static_cast(_ttoi(aPortNo))); if (NOERROR != dwRetVal) BASE_RETURN_NONE; pNetSession->SetConnect(true); // Ä¿³¼¼Ç ¾ÆÀ̵ð ÀúÀå pPartitionView->SetConnectionID(nConID); // Ä¿³Ø¼Çµî·Ï CNetConnectionMgr::GetInstancePtr()->RegistConnection (pNetConnection); } GetDlgItem(IDC_CNNDLG_CONNECT)->EnableWindow(FALSE); } void CConnectionDialog::OnBnClickedButtonDisconnect() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. DWORD aIpAddress = 0; TCHAR aPortNo[8] = { _T('\0'), }; { m_IpAddress.GetAddress(aIpAddress); m_PortNo.GetWindowText(aPortNo, _countof(aPortNo)); } if (INADDR_ANY == aIpAddress || INADDR_NONE == aIpAddress) { ::AfxMessageBox(_T("IP Address is not valid !"), MB_ICONERROR); return; } if (0 == aPortNo) { ::AfxMessageBox(_T("Port Number is not valid !"), MB_ICONERROR); return; } ULONG nConID = ::htonl(aIpAddress); CNetConnection* pNetConnection = CNetConnectionMgr::GetInstancePtr()->GetConnection (nConID); if (pNetConnection) // ±âÁ¸¿¡ Á¢¼ÓÇÑ °æ¿ì { CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) BASE_RETURN_NONE; if (pNetSession->IsConnect()) { pNetSession->SetConnect(false); pNetSession->Disconnect(); EnableButton(FALSE); } else AfxMessageBox(_T("Not Connected !"), MB_ICONERROR); } else // »õ·Î¿î ÁÖ¼ÒÀÎ °æ¿ì { AfxMessageBox(_T("Not Connected !"), MB_ICONERROR); } } void CConnectionDialog::OnBnClickedCnndlgCancel() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. CConnectionDialog::OnCancel(); } void CConnectionDialog::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. // ±×¸®±â ¸Þ½ÃÁö¿¡ ´ëÇØ¼­´Â CDialog::OnPaint()À»(¸¦) È£ÃâÇÏÁö ¸¶½Ê½Ã¿À. Graphics aGraphics(dc); aGraphics.SetSmoothingMode(SmoothingModeHighQuality); CRect aRect; GetClientRect(&aRect); // Draw Title { // Gradient Line { // Title 1 { LinearGradientBrush aBrush( Rect( EV_UIS_TITLELINE_1_PAD_LFT, EV_UIS_TITLELINE_1_PAD_TOP, EV_UIS_TITLELINE_1_WTH, EV_UIS_TITLELINE_1_HGT ), Color(100, 221, 221, 221), Color(255, 120, 120, 120), 180.0f, FALSE ); aGraphics.FillRectangle( &aBrush, EV_UIS_TITLELINE_1_PAD_LFT, EV_UIS_TITLELINE_1_PAD_TOP, EV_UIS_TITLELINE_1_WTH - 1, EV_UIS_TITLELINE_1_HGT ); } // Title 2 { LinearGradientBrush aBrush( Rect( EV_UIS_TITLELINE_2_PAD_LFT, EV_UIS_TITLELINE_2_PAD_TOP, EV_UIS_TITLELINE_2_WTH, EV_UIS_TITLELINE_2_HGT ), Color(100, 221, 221, 221), Color(255, 120, 120, 120), 180.0f, FALSE ); aGraphics.FillRectangle( &aBrush, EV_UIS_TITLELINE_2_PAD_LFT, EV_UIS_TITLELINE_2_PAD_TOP, EV_UIS_TITLELINE_2_WTH - 1, EV_UIS_TITLELINE_2_HGT ); } } // Draw Text { LOGFONT aLogFont; ::memset(&aLogFont, 0x00, sizeof(aLogFont)); _tcsncpy_s(aLogFont.lfFaceName, _T("Arial"), LF_FACESIZE); aLogFont.lfCharSet = DEFAULT_CHARSET; aLogFont.lfHeight = 16; aLogFont.lfWeight = FW_ULTRABOLD; CFont aNewFont; VERIFY(aNewFont.CreateFontIndirect(&aLogFont)); CFont* aOldFont = dc.SelectObject(&aNewFont); COLORREF aOldTxColor = dc.SetTextColor(RGB(255, 255, 255)); int aOldBkMode = dc.SetBkMode(TRANSPARENT); // Title 1 { CRect aRect( EV_UIS_TITLELINE_1_PAD_LFT + EV_UIS_TITLETEXT_1_PAD_X, EV_UIS_TITLELINE_1_PAD_TOP, EV_UIS_TITLELINE_1_PAD_LFT + EV_UIS_TITLELINE_1_WTH, EV_UIS_TITLELINE_1_PAD_TOP + EV_UIS_TITLELINE_1_HGT ); dc.DrawText(_T("Dragon Nest"), &aRect, DT_LEFT | DT_VCENTER); } // Title 2 { CRect aRect( EV_UIS_TITLELINE_2_PAD_LFT + EV_UIS_TITLETEXT_2_PAD_X, EV_UIS_TITLELINE_2_PAD_TOP, EV_UIS_TITLELINE_2_PAD_LFT + EV_UIS_TITLELINE_2_WTH, EV_UIS_TITLELINE_2_PAD_TOP + EV_UIS_TITLELINE_2_HGT ); dc.DrawText(_T("Service Monitor"), &aRect, DT_LEFT | DT_VCENTER); } dc.SetTextColor(aOldTxColor); dc.SetBkMode(aOldBkMode); dc.SelectObject(aOldFont); aNewFont.DeleteObject(); } } } void CConnectionDialog::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. } void CConnectionDialog::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. CDialog::OnLButtonDown(nFlags, point); PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y)); // WM_NCHITTEST ´ë½Å »ç¿ë (¸¶¿ì½º ¹öư À̺¥Æ® ¹Þ±â À§ÇÔ) } void CConnectionDialog::OnClose() { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. SaveConfig(); CDialog::OnClose(); }