tingyuyiye01
tingyuyiye01
采纳率0%
2016-04-25 06:09 阅读 1.7k

c++获取桌面图标名出错

1

环境:win8.1 专业版
开发环境 vs2013-win32

通过测试,获取桌面句柄没有问题,获取图标坐标没有问题
但是获取文件快捷键名为空

//获取系统窗口句柄
HWND dwndparent;
HWND dwndviem = NULL;
HWND dwdesktopicon; 
dwndparent = FindWindowEx(0, 0, "WorkerW", "");//获得第一个WorkerW类的窗口
while ((!dwndviem) && dwndparent)
{
    dwndviem = FindWindowEx(dwndparent, 0, "SHELLDLL_DefView", 0);
    if (dwndviem != NULL)
        break;  
    dwndparent = FindWindowEx(0, dwndparent, "WorkerW", "");        
}
dwdesktopicon = FindWindowEx(dwndviem, 0, "SysListView32", "FolderView");
HWND listview = dwdesktopicon;
int count = (int)SendMessage(listview, LVM_GETITEMCOUNT, (WPARAM)0, (LPARAM)0);

LVITEM lvi, *_lvi;
char item[512];
char *_item;
unsigned long pid;
HANDLE process;

GetWindowThreadProcessId(listview, &pid);
process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid);

_lvi = (LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),MEM_COMMIT, PAGE_READWRITE);
_item = (char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);

//lvi.mask = LVIF_TEXT;
lvi.cchTextMax = 512;
lvi.pszText = _item;
lvi.iSubItem = 0;

RECT  rc;
rc.left = LVIR_ICON;
RECT* _rc = (RECT*)VirtualAllocEx(process, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);

for (int i = 0; i < count; i++) {

    WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
    SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);

    ::WriteProcessMemory(process, _rc, &rc, sizeof(rc), NULL);
    ::SendMessage(listview, LVM_GETITEMRECT, (WPARAM)i, (LPARAM)_rc);

    ReadProcessMemory(process, _item, item, 512, NULL);
    ReadProcessMemory(process, _rc, &rc, sizeof(rc), NULL);
    cout << item;
    cout << endl;


}

VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);

ReadProcessMemory(process, _item, item, 512, NULL); //这里获取快捷键的名称出错

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • tingyuyiye01 tingyuyiye01 2016-04-26 07:09

    目前问题已经查出来了,经过验证,程序逻辑没有问题,出问题的地方是lvi.pszText = _item;这句,这里的赋值有问题
    需要做的工作是重新定义一个LVITEM 结构体,将其中的的pszText的结构类型INT64 pszText;
    typedef struct tagLVITEM64A
    {
    UINT mask;
    int iItem;
    int iSubItem;
    UINT state;
    UINT stateMask;
    INT64 pszText;
    int cchTextMax;
    int iImage;
    LPARAM lParam;
    #if (_WIN32_IE >= 0x0300)
    int iIndent;
    #endif
    #if (_WIN32_WINNT >= 0x501)
    int iGroupId;
    UINT cColumns; // tile view columns
    PUINT puColumns;
    #endif
    } LVITEM64A, *LPLVITEM64A;

    
    

    问题就这样解决了。

    点赞 评论 复制链接分享
  • tingyuyiye01 tingyuyiye01 2016-04-26 07:10

    目前问题已经查出来了,经过验证,程序逻辑没有问题,出问题的地方是lvi.pszText = _item;这句,这里的赋值有问题
    需要做的工作是重新定义一个LVITEM 结构体,将其中的的pszText的结构类型INT64 pszText;
    typedef struct tagLVITEM64A
    {
    UINT mask;
    int iItem;
    int iSubItem;
    UINT state;
    UINT stateMask;
    INT64 pszText;
    int cchTextMax;
    int iImage;
    LPARAM lParam;
    #if (_WIN32_IE >= 0x0300)
    int iIndent;
    #endif
    #if (_WIN32_WINNT >= 0x501)
    int iGroupId;
    UINT cColumns; // tile view columns
    PUINT puColumns;
    #endif
    } LVITEM64A, *LPLVITEM64A;

    
    

    问题就这样解决了。

    点赞 评论 复制链接分享
  • tingyuyiye01 tingyuyiye01 2016-04-26 07:12

    LVITEM64A lv;
    lvi.cchTextMax = 512;
    lvi.pszText = (INT64 )_item;
    lvi.iSubItem = 0;
    这样就完美解决了。
    先在这里为自己鼓个掌,点个赞。

    点赞 评论 复制链接分享

相关推荐