• C++ 桌面图标(转载)



    #include<windows.h>
    #include<commctrl.h>
    #include <stdio.h>


    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;


    void GetChromePT(HWND h)
    {

    DWORD dwProcessId;
    HWND hDeskTop;

    HWND hDeskTop1;


    HWND destop = GetDesktopWindow();
    HWND hWorkerW = NULL;
    HWND hShellViewWin = NULL;
    do
    {
    hWorkerW = FindWindowEx(destop, hWorkerW, L"WorkerW", NULL);
    hDeskTop1 = FindWindowEx(hWorkerW, 0, L"SHELLDLL_DefView", 0);
    } while (hDeskTop1 == NULL && hWorkerW != NULL);


    hDeskTop=FindWindowEx(hDeskTop1,0, L"SysListView32", NULL);


    GetWindowThreadProcessId(hDeskTop, &dwProcessId);//通过桌面窗口句柄获取此窗口所在进程的PID,其实就是explorer进程
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);//打开zhi指定PID进程,取得进程句柄

    tagLVITEM64A *_lv, lvi;
    LPVOID lpvPt = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);//在指定进程里面申请一个POINI结构大小的空间.

    _lv = (tagLVITEM64A*)VirtualAllocEx(hProcess, NULL, sizeof(tagLVITEM64A), MEM_COMMIT, PAGE_READWRITE);//在指定进程里面申请一个文本结构大小的空间.


    char item[20] = { 0 };
    char *_item;
    POINT pt;
    POINT pt1;

    //获取窗口listbox 句柄 与 获取桌面图标信息无关 可忽略
    //HWND h_list = GetListHandle(h);
    int m_iconCount = ListView_GetItemCount(hDeskTop);
    _item = (char*)VirtualAllocEx(hProcess, NULL, 20, MEM_COMMIT, PAGE_READWRITE);


    ZeroMemory(&lvi, sizeof(LVITEM));
    //lv.mask = LVIF_TEXT;
    lvi.cchTextMax = 20;


    for (size_t i = 0; i < m_iconCount; i++)
    {
    //坐标
    ListView_GetItemPosition(hDeskTop, i, lpvPt);//获取第一个图标的坐标,存入lpvPt
    ReadProcessMemory(hProcess, lpvPt, &pt, sizeof(POINT), NULL);
    //名称
    lvi.iSubItem = 0;
    lvi.pszText = (INT64)_item;
    WriteProcessMemory(hProcess, _lv, &lvi, sizeof(LVITEM), NULL);
    SendMessage(hDeskTop, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lv);
    ReadProcessMemory(hProcess, _item, item, 20, NULL);
    wchar_t pt_char[MAXBYTE] = { 0 };
    //填充listbox
    //wsprintf(pt_char, L"%ld---%ld--name:%s", pt.x, pt.y, item); //一句话解决

    pt1.x = pt.x + 80;
    pt1.y = pt.y + 80;
    SendMessage(hDeskTop, LVM_SETITEMPOSITION, i, (LPARAM)&pt1);
    printf("%ld---%ld---name:%s ", pt.x, pt.y,item);
    //SendMessage(h_list, LB_ADDSTRING, 0, (LPARAM)pt_char);
    }
    //lpvPt不是本进程里面的,不能使用,所以就要
    //利用ReadProcessMemory从指定进程给读出来
    VirtualFreeEx(hProcess, lpvPt, 0, MEM_RELEASE);
    VirtualFreeEx(hProcess, _lv, 0, MEM_RELEASE);
    VirtualFreeEx(hProcess, _item, 0, MEM_RELEASE);
    //释放申请的空间
    CloseHandle(hProcess);//关闭句柄

    }

    #include <iostream>

    int main()
    {
    GetChromePT(NULL);
    getchar();
    }

  • 相关阅读:
    Delphi StrUtils-字符串函数RightStr、MidStr、LeftStr
    Delphi 错误:Could not convert variant to type(Null) into type (String)
    Delphi Variants-VarIsEmpty、VarIsNull 判断Variant变量是否为空、是否包含Null值
    Python使用openpyxl读写excel文件
    CentOS7设置为局域网固定ip
    Linux下ps aux命令中STAT的参数含义(转)
    Python生成8位随机字符串的方法分析
    php源码加密方法详解
    普通程序员 与 大牛 的区别 ???
    开始记录前端学习过程中的点点滴滴
  • 原文地址:https://www.cnblogs.com/tangyanzhi1111/p/14085941.html
Copyright © 2020-2023  润新知