双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

获取桌面图标的名称

shoufaqi2 shoufaqi2 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区



#include <Windows.h>
#include <tchar.h>
#include "Commctrl.h"
#include <iostream>
#include <string>
using namespace std;
#define ALLOC_SIZE 200
//取桌面 ListView 的句柄
string OnSetDeskIcon()
{
HWND hDeskTop;
DWORD dwPID;
HANDLE hProcess;
LPVOID pData;
LPVOID pString;
LVITEM lvi;
//BOOL fResult;
//SIZE_T BytesRead;
//SIZE_T BytesWritten;
char szText[ALLOC_SIZE];

hDeskTop = FindWindow(_T("progman"), NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, _T("shelldll_defview"), NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, _T("syslistview32"), NULL);
int count = ListView_GetItemCount(hDeskTop);

// get desktop window process ID (explorer.exe)
GetWindowThreadProcessId(hDeskTop, &dwPID);

// open process to get explorer process handle
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);

// allocate memory in explorer's address space
// allocate space for LVITEM struct
pData = VirtualAllocEx(hProcess, NULL, ALLOC_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
// allocate space for string (i.e. "Network Neighborhood")
pString = VirtualAllocEx(hProcess, NULL, ALLOC_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);

// init LV_ITEM struct
ZeroMemory(&lvi, sizeof(LVITEM));
//lvi.iItem = 0;

lvi.cchTextMax = 500;

// write the contents of lvi into explorer's address space

for(int i = 0; i < count; i++)
{
// get item's name
lvi.iSubItem = 0;
lvi.pszText = (LPWSTR)pString;
WriteProcessMemory(hProcess, pData, &lvi, sizeof(LVITEM),NULL);
::SendMessage(hDeskTop, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)pData);

// read back lvi struct (for debugging purposes only)
//ReadProcessMemory(hProcess, pData, szText, ALLOC_SIZE, &BytesRead);
// read text of queried item
ReadProcessMemory(hProcess, pString, szText, ALLOC_SIZE,NULL);

}
VirtualFreeEx(hProcess, pString, ALLOC_SIZE, MEM_DECOMMIT);
VirtualFreeEx(hProcess, pData, ALLOC_SIZE, MEM_DECOMMIT);
CloseHandle(hProcess);

string s = szText;
return s;
}
int main()
{
//int n = OnSetDeskIcon();
//cout << n << endl;
//cout <<
string s = OnSetDeskIcon();
cout << s;

}




只能显示图标数量,不能显示名称
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
shoufaqi2
进程/线程/DLL 15,466 成员 49,169 内容