如何实现不在双击消息里面存储文件,隔一段时间自动存储

C语言 码拜 9年前 (2015-09-28) 1001次浏览

我现在只能双击list control 组件表格实现存储文件,我想实现让客户端接收到的文件能够自动存储,如果能需要,源代码我直接发您。我把文件上传到地址是http://download.csdn.net/detail/zhao1209/8964329.和:http://download.csdn.net/detail/zhao1209/8964347

void CClient_FileTransferDlg::OnDblclkListFilelist(NMHDR* pNMHDR, LRESULT* pResult) 

{

// TODO: Add your control notification handler code here

NMLISTVIEW* pListView = (NMLISTVIEW*)pNMHDR;//结构体,ListView的通知信息

int iSel = pListView->iItem;

if(iSel == -1)

return;

CString strFileName = m_ListFile.GetItemText(iSel, 0);

     CString str2;

    str2.Format(“D:\zhao.txt”);

//得到客户端保存路径

CFile file;

BOOL bOpen = file.Open(str2, CFile::modeCreate|CFile::modeWrite, NULL);

if(!bOpen)

{

MessageBox(“文件创建或打开失败!请确认路径再重试!”);

return;

}

file.Close();

MSGREQUEST msgRequest;//通信语言结构体

msgRequest.iCommand = FILEDATA;

msgRequest.lFileLength = m_ListFile.GetItemData(iSel);

msgRequest.lFileOffset = 0;

strcpy(msgRequest.sClientPath, str2.GetBuffer(0));

strcpy(msgRequest.sServerPath, m_ListFile.GetItemText(iSel, 5)); 

//子项目,第6列

DWORD dwStartTick = GetTickCount();

char sStartTick[20];

sprintf(sStartTick, “%u”, dwStartTick);

//格式:Unsigned decimal integer

m_ListFile.SetItemText(iSel, 6, sStartTick);

m_pClient->RequestFile(msgRequest);//调用请求线程

*pResult = 0;

}

#1
你注册一个timer时间,当时间到了的时候触发一个存储文件操作。

你百度一下“MFC timer”这两个关键字。不会太难的。

#2
你注册一个timer时间 -——>你注册一个timer事件
#3
谢谢楼上的回复,移动上面那段程序到timer消息里,我试过了,因为涉及到线程以及结构体的问题,所以我一直没有解决掉,您能否下载我的代码帮我看看,谢谢您啦
#4

5分

回复3楼:

自己写个小程序测试一下该控件的用法,然后将代码加到模块中去.你始终也要学会这个非常常用的控件啊,为什么不在这一次学会尼?

#5

50分

发你了      。
#6

5分

你接收实际就是下载,只要把路径定死,自动接收就行了
#7
void CClient_FileTransferDlg::Download()

{

    int nCount = m_ListFile.GetItemCount();

    for (int i = 0; i < nCount; i++)

    {

        int iSel = i;

        CString strFileName = m_ListFile.GetItemText(iSel, 0);

        CString str2;

        str2.Format(“D:\zhao.txt”);

        //得到客户端保存路径

        CFile file;

        BOOL bOpen = file.Open(str2, CFile::modeCreate|CFile::modeWrite, NULL);

        if(!bOpen)

        {

            MessageBox(“文件创建或打开失败!请确认路径再重试!”);

            continue;

        }

        file.Close();

        MSGREQUEST msgRequest;//通信语言结构体

        msgRequest.iCommand = FILEDATA;

        msgRequest.lFileLength = m_ListFile.GetItemData(iSel);

        msgRequest.lFileOffset = 0;

        strcpy(msgRequest.sClientPath, str2.GetBuffer(0));

        strcpy(msgRequest.sServerPath, m_ListFile.GetItemText(iSel, 5)); 

        //子项目,第6列

        DWORD dwStartTick = GetTickCount();

        char sStartTick[20];

        sprintf(sStartTick, “%u”, dwStartTick);

        //格式:Unsigned decimal integer

        m_ListFile.SetItemText(iSel, 6, sStartTick);

        m_pClient->RequestFile(msgRequest);//调用请求线程

    }

    SetTimer(TIMER_ID_SAVE, 4000, NULL);

}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何实现不在双击消息里面存储文件,隔一段时间自动存储
喜欢 (0)
[1034331897@qq.com]
分享 (0)