关闭

读取其他应用程序中ListView中的内容

271人阅读 评论(0) 收藏 举报

    const nMaxLen=1023;
    char szBuf[nMaxLen+1];

    int          nLVItemCount;
    DWORD        dwProcessID;
    HANDLE       hProcess;
    LVITEM       lvItemLocal;
    DWORD        dwBytesRead, dwBytesWrite;
    bool         bSuccess,bWriteOK;

    GetWindowThreadProcessId(hWindow,&dwProcessID);
    hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
    if(!hProcess)  //得不到指定进程的句柄
        return;
    //在指定进程内分配存储空间
    LPVOID lpTextRemote=VirtualAllocEx(hProcess,NULL,nMaxLen+1,MEM_COMMIT,PAGE_READWRITE);
    LPVOID lpListItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(LVITEM),MEM_COMMIT,PAGE_READWRITE);
    if((!lpTextRemote) || (!lpListItemRemote)) //不能在指定进程内分配存储空间
        return;

    nLVItemCount=ListView_GetItemCount(hWindow);

    for(int i=0;i<nLVItemCount;i++)
    {
        ZeroMemory(szBuf,nMaxLen+1);
        bWriteOK= WriteProcessMemory(hProcess,lpTextRemote,(LPVOID)szBuf,nMaxLen+1,(LPDWORD)&dwBytesWrite);
        if(!bWriteOK) //写内存错误
            return;
        lvItemLocal.iItem=i;
        lvItemLocal.iSubItem=0;
        lvItemLocal.mask=LVIF_TEXT;
        lvItemLocal.cchTextMax=nMaxLen;
        lvItemLocal.pszText=(LPTSTR)lpTextRemote;
        dwBytesWrite=0;
        bWriteOK=WriteProcessMemory(hProcess,lpListItemRemote,(LPVOID)&lvItemLocal,sizeof(LVITEM),(LPDWORD)&dwBytesWrite);
        if(!bWriteOK) //写内存错误
            return;

        SendMessage(hWindow,LVM_GETITEMTEXT,(WPARAM)i,(LPARAM)lpListItemRemote);
        bSuccess=ReadProcessMemory(hProcess,lpTextRemote,szBuf,nMaxLen+1,&dwBytesRead);
        //从指定进程存储空间读取文本
        if(!bSuccess) //不能在指定进程内读取文本

            return;

//获取到指定值

        CString str;

    str.Format("%s",szBuf);


    }//end of for(i)
    //在指定进程内释放存储空间
    VirtualFreeEx(hProcess,lpListItemRemote,0,MEM_RELEASE);
    VirtualFreeEx(hProcess,lpTextRemote,0,MEM_RELEASE);
    //关闭指定进程句柄
    CloseHandle(hProcess);
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:883次
    • 积分:20
    • 等级:
    • 排名:千里之外
    • 原创:0篇
    • 转载:1篇
    • 译文:1篇
    • 评论:0条
    文章分类
    文章存档