⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionthread.cpp

📁 VC网络程序设计实例导航配套代码
💻 CPP
字号:
#include "stdafx.h"
#include "ConnectionThread.h"
#include "Command.h"
#include "RemoteAdminView.h"
#include "RemoteAdminDoc.h"
#include "MachineView.h"
#include "GlobalHelperFunc.h"


UINT __stdcall ThreadConnection::ConnectToMachine(void* pParam)
{
    SConnectInfo* pConnectInfo = reinterpret_cast<SConnectInfo*>(pParam);

    CRemoteAdminDoc* pDoc              = pConnectInfo->pDoc;
    CRemoteAdminView* pRemoteAdminView = pConnectInfo->pRemoteAdminView;
    CMachineView* pMachineView         = pConnectInfo->pMachineView;
    CString strIP                      = pConnectInfo->strIP;
    CString strPwd                     = pConnectInfo->strPwd;
    
    // Add to the connection pending list, so that even if someone requests
    // connection for the same machine it will fail.
    pDoc->AddToConnectionPendingList(strIP);

    BOOL bConnectOk = pDoc->EstablishAllConnections(strIP, strPwd, TRUE, pMachineView, pRemoteAdminView);

    if (!bConnectOk)
    {
        //:AfxMessageBox(IDS_CONNECTION_NOT_ESTABLISHED);
        CString strFromatAPIMsg = ErrorHandling::FormatLastError();
        CString strDisplayMsg;
        strDisplayMsg.Format("Machine IP %s: %s", strIP.GetBuffer(0), strFromatAPIMsg.GetBuffer(0));
    }
    else
    {
        // Since one machine has connected, resume the process updation thread
        // This will be called more than once, when every new nachine is conncted.
        // It will only be an extra call, but dosen't harm, we just need to
        // trigger iti
        ::ResumeThread(pDoc->m_hUpdateProcessList);
        
        int iTotalMachineBeingMonitored = pDoc->GetTotalMachinesMonitored();
           
        if (iTotalMachineBeingMonitored == 0) 
        {
            // Clean the list view
            pRemoteAdminView->GetListCtrl().DeleteAllItems();
        }
        else  // Select the latest machine added and show it's processes
        {
            HTREEITEM h = pMachineView->GetTreeItemForText(strIP);

            if (h != NULL)
            {
                //pMachineView->GetTreeCtrl().Select(h, TVGN_CARET);
                pRemoteAdminView->RefreshProcesses(strIP);
            }
        }
    }
 
    // Since the pending connection request is over (failed or succeded), now remove
    // it from the pending connection list
    pDoc->RemoveFromConnecionPendingList(strIP);

	if (pConnectInfo)
	{
		delete pConnectInfo;
	}
    
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -