当前位置:编程学习 > VB >>

SysListView32控件

"我的电脑" 文件列表类 SysListView32控件一个item被选中 返回他的路径?????

我已取行SysListView32 hwnd   
--------------------编程问答-------------------- --------------------编程问答-------------------- 参考这个CB代码
void MyGetListViewItem(HWND hWindow,TStrings *strlist)
{
    const nMaxLen=1023;
    char szBuf[nMaxLen+1];
    char buf[nMaxLen+1];

    int          nLVItemCount;
    int          nColumns;
    DWORD        dwProcessID;
    HANDLE       hProcess;
    HANDLE       hHeaderCtrl;
    LVITEM       lvItemLocal;
    HDITEM       hdItemLocal;
    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);
    LPVOID lpHeadItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(HDITEM),MEM_COMMIT,PAGE_READWRITE);
    if((!lpTextRemote) || (!lpListItemRemote) || (!lpHeadItemRemote)) //不能在指定进程内分配存储空间
        return;

    nLVItemCount=ListView_GetItemCount(hWindow);
    hHeaderCtrl=ListView_GetHeader(hWindow);
    nColumns=Header_GetItemCount(hHeaderCtrl);
    if (nColumns<=0) {
        nColumns=1;
    } else {
        buf[0]=0;
        for (int j=0;j<nColumns;j++) {
            ZeroMemory(szBuf,nMaxLen+1);
            bWriteOK= WriteProcessMemory(hProcess,lpTextRemote,(LPVOID)szBuf,nMaxLen+1,(LPDWORD)&dwBytesWrite);
            if(!bWriteOK) //写内存错误
                return;
            hdItemLocal.mask=HDI_TEXT;
            hdItemLocal.cchTextMax=nMaxLen;
            hdItemLocal.pszText=(LPTSTR)lpTextRemote;
            dwBytesWrite=0;
            bWriteOK=WriteProcessMemory(hProcess,lpHeadItemRemote,(LPVOID)&hdItemLocal,sizeof(HDITEM),(LPDWORD)&dwBytesWrite);
            if(!bWriteOK) //写内存错误
                return;

            SendMessage(hHeaderCtrl,HDM_GETITEM,(WPARAM)j,(LPARAM)lpHeadItemRemote);
            bSuccess=ReadProcessMemory(hProcess,lpTextRemote,szBuf,nMaxLen+1,&dwBytesRead);
            //从指定进程存储空间读取文本
            if(!bSuccess) //不能在指定进程内读取文本
                return;
            if (j>0) strcat(buf,"|");
            strcat(buf,AnsiString(szBuf).c_str());
        }
        strlist->Add(buf);
    }
//  strlist->Add("ListView的Columns数: " + String(nColumns));
//  strlist->Add("---------------------------");

    for (int i=0;i<nLVItemCount;i++) {
        buf[0]=0;
        for (int j=0;j<nColumns;j++) {
            ZeroMemory(szBuf,nMaxLen+1);
            bWriteOK= WriteProcessMemory(hProcess,lpTextRemote,(LPVOID)szBuf,nMaxLen+1,(LPDWORD)&dwBytesWrite);
            if(!bWriteOK) //写内存错误
                return;
            lvItemLocal.iItem=i;
            lvItemLocal.iSubItem=j;
            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;
            if (j>0) strcat(buf,"|");
            strcat(buf,AnsiString(szBuf).c_str());
        }
        strlist->Add(buf);
    }//end of for(i)
    //在指定进程内释放存储空间
    VirtualFreeEx(hProcess,lpListItemRemote,0,MEM_RELEASE);
    VirtualFreeEx(hProcess,lpTextRemote,0,MEM_RELEASE);
    //关闭指定进程句柄
    CloseHandle(hProcess);
}
--------------------编程问答-------------------- Title: API-ucListView 1.0
Description: API-ListView usercontrol with most commom features (no dependencies 

 http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=56021&lngWId=1 --------------------编程问答-------------------- 有VB板的吗?
补充:VB ,  API
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,