当前位置: 代码迷 >> VC/MFC >> 如何获取ListView20WndClass内容
  详细解决方案

如何获取ListView20WndClass内容

热度:87   发布时间:2016-05-02 03:40:38.0
怎么获取ListView20WndClass内容
这个是C#代码,请问vc代码应该怎么写

public List<string> GetColumnsHeaderText(int processHandle, int headerhwnd, int colCount)
        {
            List<string> list = new List<string>();
            uint dwSize = 0x100;
            int lpBaseAddress = WindowsAPIHelper.VirtualAllocEx(processHandle, IntPtr.Zero, (uint) Marshal.SizeOf(typeof(HDITEM)), 0x3000, 4);
            int num3 = WindowsAPIHelper.VirtualAllocEx(processHandle, IntPtr.Zero, dwSize, 0x3000, 4);
            for (int i = 0; i < colCount; i++)
            {
                byte[] arr = new byte[dwSize];
                HDITEM structure = new HDITEM {
                    mask = (uint) this.HDI_TEXT,
                    fmt = 0,
                    cchTextMax = (int) dwSize,
                    pszText = (IntPtr) num3
                };
                IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure));
                Marshal.StructureToPtr(structure, ptr, false);
                uint vNumberOfBytesRead = 0;
                bool flag = WindowsAPIHelper.WriteProcessMemory(processHandle, lpBaseAddress, ptr, Marshal.SizeOf(typeof(HDITEM)), ref vNumberOfBytesRead);
                WindowsAPIHelper.SendMessage(headerhwnd, 0x1203, i, lpBaseAddress);
                WindowsAPIHelper.ReadProcessMemory(processHandle, num3, Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0), (int) dwSize, ref vNumberOfBytesRead);
                string str = Encoding.Default.GetString(arr, 0, (int) vNumberOfBytesRead);
                string item = "";
                foreach (char ch in str)
                {
                    if (ch == '\0')
                    {
                        break;
                    }
                    item = item + ch;
                }
                list.Add(item);
            }
            WindowsAPIHelper.VirtualFreeEx(processHandle, lpBaseAddress, 0, 0x8000);
            WindowsAPIHelper.VirtualFreeEx(processHandle, num3, 0, 0x8000);
            return list;
        }

------解决思路----------------------
引用:
自己解决了~~~

------解决思路----------------------
帮结帖+蹭分
------解决思路----------------------
LS +1
  相关解决方案