VC远控(三)磁盘显示

服务端:

发送与接收命令

DWORD WINAPI SLisen(LPVOID lparam)
{
    SOCKET client = (SOCKET)lparam;
    COMMAND command;
    while (true)
    {
        memset((char *)&command, 0, sizeof(command));
        if (recv(client, (char *)&command, sizeof(command), 0) == SOCKET_ERROR)
        {
            cout<<"Client order incorrect"<<endl;
            break;
        }
        else
        {
            cout<<"Client order correct"<<endl;
            switch (command.ID)
            {
            case GetDriver:
                GetDriverProc(command, client);
                break;
            default:
                break;
            }
        }
    }
    closesocket(client);
    return 0;
}

逻辑处理

DWORD GetDriverProc(COMMAND command, SOCKET client)
{
    COMMAND cmd;
    memset((char *)&cmd, 0, sizeof(cmd));
    cmd.ID = GetDriver;

    for (char i = 'A'; i <= 'Z'; i++)
    {
        char x[26] = {i, ':', '\0'};
        
        UINT Type = GetDriveType(x);
        if (Type == DRIVE_FIXED || Type == DRIVE_REMOVABLE || Type == DRIVE_CDROM)
        {
            memset((char *)cmd.lparam, 0, sizeof(cmd.lparam));
            strcpy((char *)cmd.lparam, x);
            if (send(client, (char*)&cmd, sizeof(cmd), 0) == SOCKET_ERROR)
            {
                cout<<"Feedback failed"<<endl;
            }
        }
    }
    return 0;
}

客户端

发送与接收数据

DWORD WINAPI CLisen(LPVOID lparam)
{
    CRemoteClientDlg* dlg = (CRemoteClientDlg *) lparam;
    COMMAND cmd;
    memset((char *)&cmd, 0, sizeof(cmd));
    while (true)
    {
        memset((char *)&cmd, 0, sizeof(cmd));
        if (recv(server, (char *)&cmd, sizeof(cmd), 0) == SOCKET_ERROR)
        {
            break;
        }
        else
        {
            switch (cmd.ID)
            {
            case GetDriver:
                dlg->GetDriverProc(cmd.lparam);
                break;
            default:
                break;
            }
        }
    }
    closesocket(server);
    return 0;
}

逻辑处理

DWORD CRemoteClientDlg::GetDriverProc(BYTE* DATA)
{
    char buff[1024];
    strcpy(buff, (char*)DATA);

    //将接受到的磁盘信息插入到TreeView中。
    m_tree.InsertItem(buff, 1, 1, m_hRoot, 0);
    //展开收缩子目录,初始状态为展开的。
    m_tree.Expand(m_hRoot, TVE_EXPAND);
    return 0;
}

treeView树形显示

    DWORD dwStyle = GetWindowLong(m_tree.m_hWnd, GWL_STYLE);
    dwStyle |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
    SetWindowLong(m_tree.m_hWnd, GWL_STYLE, dwStyle);

posted @ 2013-11-18 23:38  若。只如初见  阅读(1221)  评论(1编辑  收藏  举报