コード例 #1
0
 protected void OnEndLabelEdit(LVITEM item)
 {
     if (EndLabelEdit != null)
     {
         EndLabelEdit(item);
     }
 }
コード例 #2
0
        private string GetIconNameAt(int i)
        {
            uint vNumberOfBytesRead = 0;
            var  iconNameBytes      = new byte[256];

            //前半. アイコン名の出力先アドレスを指定
            //配列形式にする理由はMarshalのAPIに渡すうえで都合いいから
            var lvItems = new LVITEM[]
            {
                new LVITEM()
                {
                    mask       = NativeMethods.LVIF_TEXT,
                    iItem      = i,
                    iSubItem   = 0,
                    cchTextMax = iconNameBytes.Length,
                    pszText    = VirtualMemoryAfterLvItemHandle
                }
            };

            NativeMethods.WriteProcessMemory(
                ProcessHandle,
                VirtualMemoryHandle,
                Marshal.UnsafeAddrOfPinnedArrayElement(lvItems, 0),
                Marshal.SizeOf <LVITEM>(),
                ref vNumberOfBytesRead
                );

            //後半. 指定したアドレスにアイコン名が書き込まれたハズなので取得
            NativeMethods.SendMessage(
                WindowHandle,
                NativeMethods.LVM_GETITEMW,
                i,
                VirtualMemoryHandle.ToInt32()
                );
            NativeMethods.ReadProcessMemory(
                ProcessHandle,
                VirtualMemoryAfterLvItemHandle,
                Marshal.UnsafeAddrOfPinnedArrayElement(iconNameBytes, 0),
                iconNameBytes.Length,
                ref vNumberOfBytesRead
                );

            //そのままだとnull終端になってない(固定長で256バイトとってるせい)ので受け取った後でトリムする(ちょっと効率悪いが)
            string result = Encoding
                            .Unicode
                            .GetString(iconNameBytes, 0, (int)vNumberOfBytesRead)
                            .TrimEnd('\0');

            var clear = new byte[iconNameBytes.Length];

            NativeMethods.WriteProcessMemory(
                ProcessHandle,
                VirtualMemoryAfterLvItemHandle,
                Marshal.UnsafeAddrOfPinnedArrayElement(clear, 0),
                clear.Length,
                ref vNumberOfBytesRead
                );

            return(result);
        }
コード例 #3
0
ファイル: Win32.cs プロジェクト: zzxxhhzxh/RssBandit
            public static int AddItemToGroup(IntPtr listHandle, int index, int groupID)
            {
                LVITEM apiItem;
                IntPtr ptrRetVal;

                try
                {
                    if (listHandle == IntPtr.Zero)
                    {
                        return(0);
                    }

                    apiItem          = new LVITEM();
                    apiItem.mask     = ListViewItemFlags.LVIF_GROUPID;
                    apiItem.iItem    = index;
                    apiItem.iGroupId = groupID;

                    ptrRetVal = SendMessage(listHandle, W32_LVM.LVM_SETITEMA, IntPtr.Zero, ref apiItem);

                    return(ptrRetVal.ToInt32());
                }
                catch (Exception ex)
                {
                    throw new Exception("An exception in API.AddItemToGroup occured: " + ex.Message);
                }
            }
コード例 #4
0
ファイル: ListView.cs プロジェクト: alexhanh/Botting-Library
        public string GetItem(int row, int column)
        {
            if (row >= ItemCount) return "";

            LVITEM item = new LVITEM();

            byte[] buffer = new byte[100];

            IntPtr external_buffer = window_process.AllocateMemory(buffer.Length);
            item.pszText = external_buffer;

            item.iItem = row;
            item.iSubItem = column;
            item.mask = LVIF_TEXT;
            item.cchTextMax = buffer.Length;

            unsafe
            {
                IntPtr item_pointer = new IntPtr((void*)&item);

                IntPtr external_item = window_process.AllocateMemory(Marshal.SizeOf(item));
                window_process.Write(item_pointer, external_item, Marshal.SizeOf(item));

                Interop.SendMessage(Handle, (uint)Messages.LVM_GETITEMA, IntPtr.Zero, external_item);

                window_process.Read(external_buffer, buffer, buffer.Length);

                window_process.FreeMemory(external_buffer);
                window_process.FreeMemory(external_item);
            }

            string text = new System.Text.ASCIIEncoding().GetString(buffer);

            return text.Substring(0, text.IndexOf((char)0));
        }
コード例 #5
0
ファイル: ListViewText.cs プロジェクト: zanderzhg/WBCPPrint
        /// <summary>
        /// 从内存中读取指定的LV控件的文本内容
        /// </summary>
        /// <param name="rows">要读取的LV控件的行数</param>
        /// <param name="cols">要读取的LV控件的列数</param>
        /// <returns>取得的LV控件信息</returns>
        private static string[,] GetListViewItmeValue(int rows, int cols)
        {
            string[,] tempStr = new string[rows, cols];//二维数组:保存LV控件的文本信息
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    byte[]   vBuffer = new byte[256];     //定义一个临时缓冲区
                    LVITEM[] vItem   = new LVITEM[1];
                    vItem[0].mask       = LVIF_TEXT;      //说明pszText是有效的
                    vItem[0].iItem      = i;              //行号
                    vItem[0].iSubItem   = j;              //列号
                    vItem[0].cchTextMax = vBuffer.Length; //所能存储的最大的文本为256字节
                    vItem[0].pszText    = (IntPtr)((int)pointer + Marshal.SizeOf(typeof(LVITEM)));
                    uint vNumberOfBytesRead = 0;

                    //把数据写到vItem中
                    //pointer为申请到的内存的首地址
                    //UnsafeAddrOfPinnedArrayElement:获取指定数组中指定索引处的元素的地址
                    WriteProcessMemory(process, pointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);

                    //发送LVM_GETITEMW消息给hwnd,将返回的结果写入pointer指向的内存空间
                    SendMessage(hwnd, LVM_GETITEMW, i, pointer);

                    //从pointer指向的内存地址开始读取数据,写入缓冲区vBuffer中
                    ReadProcessMemory(process, ((int)pointer + Marshal.SizeOf(typeof(LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead);

                    string vText = Encoding.Unicode.GetString(vBuffer, 0, (int)vNumberOfBytesRead);;
                    tempStr[i, j] = vText;
                }
            }
            VirtualFreeEx(process, pointer, 0, MEM_RELEASE); //在其它进程中释放申请的虚拟内存空间,MEM_RELEASE方式很彻底,完全回收
            CloseHandle(process);                            //关闭打开的进程对象
            return(tempStr);
        }
コード例 #6
0
        /// <summary>
        /// Devuelve el nombre de un elemento de una lista
        /// En este caso devuelve el nombre de un proceso activo (proceso.exe)
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        static string GetItemText(IntPtr handle, IntPtr index)
        {
            byte[]  str = new byte[50];
            UIntPtr bytesCount;
            uint    pid;
            LVITEM  process = new LVITEM();

            Rootkit.GetWindowThreadProcessId(handle, out pid);
            IntPtr hProcess            = Rootkit.OpenProcessHandle(pid);
            IntPtr SharedProcMem       = Rootkit.AllocExternalMemory((uint)Marshal.SizeOf(process), hProcess);
            IntPtr SharedProcMemString = Rootkit.AllocExternalMemory(50, hProcess);

            process.iItem      = index;
            process.iSubItem   = (IntPtr)0;
            process.cchTextMax = 50;
            process.pszText    = SharedProcMemString;

            Rootkit.WriteProcessMemory(hProcess, SharedProcMem, StructureToByteArray(process), (uint)Marshal.SizeOf(process), out bytesCount);
            Rootkit.SendMessage(handle, LVM_GETITEMTEXTA, index, SharedProcMem);
            Rootkit.ReadProcessMemory(hProcess, SharedProcMemString, str, 50, out bytesCount);
            Rootkit.FreeExternalMemory(hProcess, SharedProcMem, (uint)Marshal.SizeOf(process));
            Rootkit.FreeExternalMemory(hProcess, SharedProcMemString, 50);
            Rootkit.CloseProcessHandle(hProcess);
            return(Encoding.ASCII.GetString(str));
        }
コード例 #7
0
        public void SelectItem(int row)
        {
            if (row >= ItemCount)
            {
                return;
            }

            LVITEM item = new LVITEM();

            item.state     = LVIS_SELECTED | LVIS_FOCUSED;
            item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
            item.mask      = LVIF_STATE;

            Interop.SendMessage(Handle, (uint)Messages.LVM_ENSUREVISIBLE, new IntPtr(row), new IntPtr(0));

            unsafe
            {
                IntPtr item_pointer = new IntPtr((void *)&item);

                IntPtr external_item = window_process.AllocateMemory(Marshal.SizeOf(item));
                window_process.Write(item_pointer, external_item, Marshal.SizeOf(item));

                Interop.SendMessage(Handle, (uint)Messages.LVM_SETITEMSTATE, new IntPtr(row), external_item);

                window_process.FreeMemory(external_item);
            }
        }
コード例 #8
0
ファイル: SystemListView.cs プロジェクト: evilC/mwinapi
 /// <summary>
 /// A subitem (a column value) of an item of this list view.
 /// </summary>
 public SystemListViewItem this[int index, int subIndex]
 {
     get
     {
         LVITEM lvi = new LVITEM();
         lvi.cchTextMax = 300;
         lvi.iItem      = index;
         lvi.iSubItem   = subIndex;
         lvi.stateMask  = 0xffffffff;
         lvi.mask       = LVIF_IMAGE | LVIF_STATE | LVIF_TEXT;
         ProcessMemoryChunk tc = ProcessMemoryChunk.Alloc(sw.Process, 301);
         lvi.pszText = tc.Location;
         ProcessMemoryChunk lc = ProcessMemoryChunk.AllocStruct(sw.Process, lvi);
         ApiHelper.FailIfZero(SystemWindow.SendMessage(new HandleRef(sw, sw.HWnd), SystemListView.LVM_GETITEM, IntPtr.Zero, lc.Location));
         lvi = (LVITEM)lc.ReadToStructure(0, typeof(LVITEM));
         lc.Dispose();
         if (lvi.pszText != tc.Location)
         {
             tc.Dispose();
             tc = new ProcessMemoryChunk(sw.Process, lvi.pszText, lvi.cchTextMax);
         }
         byte[] tmp   = tc.Read();
         string title = Encoding.Default.GetString(tmp);
         if (title.IndexOf('\0') != -1)
         {
             title = title.Substring(0, title.IndexOf('\0'));
         }
         int  image = lvi.iImage;
         uint state = lvi.state;
         tc.Dispose();
         return(new SystemListViewItem(sw, index, title, state, image));
     }
 }
コード例 #9
0
        /// <summary>
        /// Obtains the cell text of the specified cell
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public string GetCellText(int row, int column)
        {
            var lvi = new LVITEM
            {
                mask       = LVIF_TEXT,
                cchTextMax = 512,
                iItem      = row,
                iSubItem   = column,
                pszText    = foreignTextBuffer
            };

            Marshal.StructureToPtr(lvi, localBuffer, false);
            //write to foreign process memory
            if (!KERNEL32.SafeNativeMethods.WriteProcessMemory(ProcessHandle, foreignItemBuffer, localBuffer, new IntPtr(512), out _))
            {
                throw new Exception("Could not write to foreign process.");
            }
            //tell control go give me the content
            USER32.SendMessage(ControlHandle, LVM_GETITEM, IntPtr.Zero, foreignItemBuffer);
            //read the result
            if (!KERNEL32.SafeNativeMethods.ReadProcessMemory(ProcessHandle, foreignTextBuffer, localBuffer, new IntPtr(512), out _))
            {
                throw new Exception("Could not read from foreign process.");
            }
            return(Marshal.PtrToStringAuto(localBuffer));
        }
コード例 #10
0
        public static int AddItemToGroup(XPListView lst, int index, int groupID)
        {
            LVITEM apiItem;
            int    ptrRetVal;

            try
            {
                if (lst == null)
                {
                    return(0);
                }

                apiItem          = new LVITEM();
                apiItem.mask     = LVIF_GROUPID;
                apiItem.iItem    = index;
                apiItem.iGroupId = groupID;

                ptrRetVal = (int)SendMessage(lst.Handle, ListViewAPI.LVM_SETITEM, 0, ref apiItem);

                return(ptrRetVal);
            }
            catch (Exception ex)
            {
                throw new System.Exception("An exception in ListViewAPI.AddItemToGroup occured: " + ex.Message);
            }
        }
コード例 #11
0
        public static string GetItemText(int idx)
        {
            // Declare and populate the LVITEM structure
            LVITEM lvi = new LVITEM();

            lvi.mask       = LVIF_TEXT;
            lvi.cchTextMax = 512;
            lvi.iItem      = idx;     // the zero-based index of the ListView item
            lvi.iSubItem   = 0;       // the one-based index of the subitem, or 0 if this
            //  structure refers to an item rather than a subitem
            lvi.pszText = Marshal.AllocHGlobal(512);

            // Send the LVM_GETITEM message to fill the LVITEM structure
            IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi));

            Marshal.StructureToPtr(lvi, ptrLvi, false);
            try
            {
                SendMessagePtr(ShellListViewHandle, LVM_GETITEM, IntPtr.Zero, ptrLvi);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            // Extract the text of the specified item
            string itemText = Marshal.PtrToStringAuto(lvi.pszText);

            return(itemText);
        }
コード例 #12
0
        public string[,] GetItemCellsText(int processHandle, int hwndListView, int rows, int cols)
        {
            string[,] strArray = new string[rows, cols];
            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 < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    byte[] arr       = new byte[dwSize];
                    LVITEM structure = new LVITEM
                    {
                        mask       = this.LVIF_TEXT,
                        iItem      = i,
                        iSubItem   = j,
                        cchTextMax = (int)dwSize,
                        pszText    = (IntPtr)num3
                    };
                    IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure));
                    Marshal.StructureToPtr(structure, ptr, false);
                    uint vNumberOfBytesRead = 0;
                    WindowsAPIHelper.WriteProcessMemory(processHandle, lpBaseAddress, ptr, Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);
                    WindowsAPIHelper.SendMessage(hwndListView, 0x102d, i, lpBaseAddress);
                    WindowsAPIHelper.ReadProcessMemory(processHandle, num3, Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0), arr.Length, ref vNumberOfBytesRead);
                    string str = Encoding.Default.GetString(arr, 0, (int)vNumberOfBytesRead);
                    strArray[i, j] = str;
                }
            }
            WindowsAPIHelper.VirtualFreeEx(processHandle, lpBaseAddress, 0, 0x8000);
            WindowsAPIHelper.VirtualFreeEx(processHandle, num3, 0, 0x8000);
            return(strArray);
        }
コード例 #13
0
 public static extern uint SendListViewMessage
 (
     [In] this IntPtr hWnd,
     uint Msg,
     uint wParam,
     ref LVITEM lParam
 );
コード例 #14
0
        /// <summary>
        /// Set the item state on the given item
        /// </summary>
        /// <param name="list">The listview whose item's state is to be changed</param>
        /// <param name="itemIndex">The index of the item to be changed</param>
        /// <param name="mask">Which bits of the value are to be set?</param>
        /// <param name="value">The value to be set</param>
        private static void SetItemState(ListView listView, int itemIndex, int mask, int value)
        {
            LVITEM lvItem = new LVITEM();

            lvItem.stateMask = mask;
            lvItem.state     = value;
            SendMessageLVItem(new HandleRef(listView, listView.Handle), LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #15
0
        /// <summary>
        /// Set the item state on the given item
        /// </summary>
        /// <param name="list">The listview whose item's state is to be changed</param>
        /// <param name="itemIndex">The index of the item to be changed</param>
        /// <param name="mask">Which bits of the value are to be set?</param>
        /// <param name="value">The value to be set</param>
        public static void SetItemState(IntPtr list, int itemIndex, int mask, int value)
        {
            var lvItem = new LVITEM {
                stateMask = mask, state = value
            };

            SendMessageLVItem(list, LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #16
0
        /// <summary>
        /// Set the item state on the given item
        /// </summary>
        /// <param name="list">The listview whose item's state is to be changed</param>
        /// <param name="itemIndex">The index of the item to be changed</param>
        /// <param name="mask">Which bits of the value are to be set?</param>
        /// <param name="value">The value to be set</param>
        public static void SetItemState(ListView list, int itemIndex, int mask, int value)
        {
            LVITEM lvItem = new LVITEM();

            lvItem.stateMask = mask;
            lvItem.state     = value;
            SendMessageLVItem(list.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #17
0
ファイル: DesktopIcon.cs プロジェクト: yzwbrian/winform-ui
        /// <summary>
        /// 获取桌面项目的名称
        /// </summary>
        /// <returns></returns>
        public string[] GetIcoName()
        {
            //桌面上SysListView32的窗口句柄
            IntPtr vHandle;

            //xp是Progman ; win7 网上说应该是 "WorkerW"  但是 spy++ 没找到 程序也不正常
            vHandle = FindWindow("Progman", null);
            vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SHELLDLL_DefView", null);
            vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SysListView32", null);
            int  vItemCount = ListView_GetItemCount(vHandle); //个数
            uint vProcessId;                                  //进程 pid

            GetWindowThreadProcessId(vHandle, out vProcessId);
            //打开并插入进程
            IntPtr vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
                                          PROCESS_VM_WRITE, false, vProcessId);
            IntPtr vPointer = VirtualAllocEx(vProcess, IntPtr.Zero, 4096,
                                             MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

            string[] tempStr = new string[vItemCount];
            try
            {
                for (int i = 0; i < vItemCount; i++)
                {
                    byte[]   vBuffer = new byte[256];
                    LVITEM[] vItem   = new LVITEM[1];
                    vItem[0].mask       = LVIF_TEXT;
                    vItem[0].iItem      = i;
                    vItem[0].iSubItem   = 0;
                    vItem[0].cchTextMax = vBuffer.Length;
                    vItem[0].pszText    = (IntPtr)((int)vPointer + System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM)));
                    uint vNumberOfBytesRead = 0;
                    /// 分配内存空间
                    WriteProcessMemory(vProcess, vPointer,
                                       System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),
                                       System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);
                    //发送信息 获取响应
                    SendMessage(vHandle, LVM_GETITEMW, i, vPointer.ToInt32());
                    ReadProcessMemory(vProcess,
                                      (IntPtr)((int)vPointer + System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM))),
                                      System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),
                                      vBuffer.Length, ref vNumberOfBytesRead);
                    string vText = System.Text.Encoding.Unicode.GetString(vBuffer, 0,
                                                                          (int)vNumberOfBytesRead).TrimEnd('\0');
                    tempStr[i] = vText;
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
            finally
            {
                VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
                CloseHandle(vProcess);
            }
            return(tempStr);
        }
コード例 #18
0
ファイル: NativeMethods.cs プロジェクト: etupper/PFM
        public static void SetItemState(ListView list, int itemIndex, int mask, int value)
        {
            LVITEM lvi = new LVITEM {
                stateMask = mask,
                state     = value
            };

            SendMessageLVItem(list.Handle, 0x102b, itemIndex, ref lvi);
        }
コード例 #19
0
        /// <summary>
        /// 全てのアイテムを選択状態にする
        /// ループで1つずつ設定すると遅いのでこれを使う
        /// </summary>
        public void SelectAllItems()
        {
            LVITEM lvitem = new LVITEM();

            lvitem.mask      = LVIF_STATE;
            lvitem.state     = LVIS_SELECTED;
            lvitem.stateMask = LVIS_SELECTED;
            SendMessage(this.Handle, LVM_SETITEMSTATE, (IntPtr)(-1), ref lvitem);
        }
コード例 #20
0
        /// <summary>
        /// Set the item state on the given item
        /// </summary>
        /// <param name="list">The listview whose item's state is to be changed</param>
        /// <param name="itemIndex">The index of the item to be changed</param>
        /// <param name="mask">Which bits of the value are to be set?</param>
        /// <param name="value">The value to be set</param>
        /// <param name="source">Gets the window handle. Added by stephen</param>
        /// reference sites:
        /// 1.http://stackoverflow.com/questions/1019388/adding-a-select-all-shortcut-ctrl-a-to-a-net-listview/1118396#1118396
        /// 2.http://www.abhisheksur.com/2010/12/win32-handle-hwnd-wpf-objects-note.html
        public static void SetItemState(ListView list, int itemIndex, int mask, int value)
        {
            LVITEM lvItem = new LVITEM();

            lvItem.stateMask = mask;
            lvItem.state     = value;
            HwndSource source = (HwndSource)HwndSource.FromVisual(list);

            SendMessageLVItem(source.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #21
0
ファイル: ListViewEx.cs プロジェクト: qeeg/TotalImage
        public static void SelectAllItems(this ListView listView)
        {
            var lvItem = new LVITEM()
            {
                state     = LVIS.SELECTED,
                stateMask = LVIS.SELECTED
            };

            SendMessage(listView.Handle, (uint)LVM.SETITEMSTATE, (nint)(-1), ref lvItem);
        }
コード例 #22
0
        /// <summary>
        /// For the given item and subitem, make it display the given image
        /// </summary>
        /// <param name="list">The listview to send a m to</param>
        /// <param name="itemIndex">row number (0 based)</param>
        /// <param name="subItemIndex">subitem (0 is the item itself)</param>
        /// <param name="imageIndex">index into the image list</param>
        public static void SetSubItemImage(ListView list, int itemIndex, int subItemIndex, int imageIndex)
        {
            LVITEM lvItem = new LVITEM();

            lvItem.mask     = LVIF_IMAGE;
            lvItem.iItem    = itemIndex;
            lvItem.iSubItem = subItemIndex;
            lvItem.iImage   = imageIndex;
            SendMessageLVItem(list.Handle, LVM_SETITEM, 0, ref lvItem);
        }
コード例 #23
0
        /// <summary>
        /// Set the item state on the given item.
        /// </summary>
        /// <param name="list">The ListView whose item's state is to be changed.</param>
        /// <param name="itemIndex">The index of the item to be changed.</param>
        /// <param name="mask">Which bits of the value are to be set.</param>
        /// <param name="value">The value to be set.</param>
        public static void SetItemState(ListView list, int itemIndex, int mask, int value)
        {
            var lvItem = new LVITEM
            {
                stateMask = mask,
                state     = value
            };

            ListViewSelectionUtils.SendMessageLVItem(list.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #24
0
ファイル: DesktopIcon.cs プロジェクト: panshuiqing/winform-ui
 /// <summary>
 /// 获取桌面项目的名称
 /// </summary>
 /// <returns></returns>
 public string[] GetIcoName()
 {
     //桌面上SysListView32的窗口句柄
     IntPtr vHandle;
     //xp是Progman ; win7 网上说应该是 "WorkerW"  但是 spy++ 没找到 程序也不正常
     vHandle = FindWindow("Progman", null);
     vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SHELLDLL_DefView", null);
     vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SysListView32", null);
     int vItemCount = ListView_GetItemCount(vHandle);//个数
     uint vProcessId; //进程 pid
     GetWindowThreadProcessId(vHandle, out vProcessId);
     //打开并插入进程
     IntPtr vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
         PROCESS_VM_WRITE, false, vProcessId);
     IntPtr vPointer = VirtualAllocEx(vProcess, IntPtr.Zero, 4096,
         MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
     string[] tempStr = new string[vItemCount];
     try
     {
         for (int i = 0; i < vItemCount; i++)
         {
             byte[] vBuffer = new byte[256];
             LVITEM[] vItem = new LVITEM[1];
             vItem[0].mask = LVIF_TEXT;
             vItem[0].iItem = i;
             vItem[0].iSubItem = 0;
             vItem[0].cchTextMax = vBuffer.Length;
             vItem[0].pszText = (IntPtr)((int)vPointer + System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM)));
             uint vNumberOfBytesRead = 0;
             /// 分配内存空间
             WriteProcessMemory(vProcess, vPointer,
                 System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),
                 System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);
             //发送信息 获取响应
             SendMessage(vHandle, LVM_GETITEMW, i, vPointer.ToInt32());
             ReadProcessMemory(vProcess,
                 (IntPtr)((int)vPointer + System.Runtime.InteropServices.Marshal.SizeOf(typeof(LVITEM))),
                 System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),
                 vBuffer.Length, ref vNumberOfBytesRead);
             string vText = System.Text.Encoding.Unicode.GetString(vBuffer, 0,
                 (int)vNumberOfBytesRead).TrimEnd('\0');
             tempStr[i] = vText;
         }
     }
     catch (Exception Ex)
     {
         throw Ex;
     }
     finally
     {
         VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
         CloseHandle(vProcess);
     }
     return tempStr;
 }
コード例 #25
0
ファイル: SystemListView.cs プロジェクト: evilC/mwinapi
        /// <summary>
        /// Sets the selected-state of the item.
        /// </summary>
        /// <param name="rowIndex">Index of the row.</param>
        /// <param name="selected">if set to <c>true</c> the item will be selected.</param>
        public void SetItemSelectedState(int rowIndex, bool selected)
        {
            LVITEM lvi = new LVITEM();

            lvi.stateMask = (uint)(ListViewItemState.LVIS_SELECTED);
            lvi.state     = selected ? (uint)(ListViewItemState.LVIS_SELECTED) : 0;
            ProcessMemoryChunk lc = ProcessMemoryChunk.AllocStruct(sw.Process, lvi);

            SystemWindow.SendMessage(new HandleRef(sw, sw.HWnd), LVM_SETITEMSTATE, new IntPtr(rowIndex), lc.Location);
            lc.Dispose();
        }
コード例 #26
0
ファイル: NativeMethods.cs プロジェクト: etupper/PFM
        public static void SetSubItemImage(ListView list, int itemIndex, int subItemIndex, int imageIndex)
        {
            LVITEM lvi = new LVITEM {
                mask     = 2,
                iItem    = itemIndex,
                iSubItem = subItemIndex,
                iImage   = imageIndex
            };

            SendMessageLVItem(list.Handle, 0x104c, 0, ref lvi);
        }
コード例 #27
0
        /// <summary>
        /// Get List view items
        /// </summary>
        /// <param name="p_hWnd">Handle to get the List from</param>
        /// <returns>List view items in string</returns>
        public static string GetListViewItems(IntPtr p_hWnd)
        {
            IntPtr        w_vHandle = p_hWnd;
            StringBuilder retVal    = new StringBuilder();

            if (w_vHandle == IntPtr.Zero)
            {
                return(string.Empty);
            }
            int  w_vItemCount = ListView_GetItemCount(w_vHandle);
            uint w_vProcessId;

            GetWindowThreadProcessId(w_vHandle, out w_vProcessId);

            IntPtr w_vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
                                            PROCESS_VM_WRITE, false, w_vProcessId);
            IntPtr w_vPointer = VirtualAllocEx(w_vProcess, IntPtr.Zero, 4096,
                                               MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

            try
            {
                for (int i = 0; i < w_vItemCount; i++)
                {
                    byte[]   w_vBuffer = new byte[256];
                    LVITEM[] w_vItem   = new LVITEM[1];
                    w_vItem[0].mask       = LVIF_TEXT;
                    w_vItem[0].iItem      = i;
                    w_vItem[0].iSubItem   = 0;
                    w_vItem[0].cchTextMax = w_vBuffer.Length;
                    w_vItem[0].pszText    = (IntPtr)((int)w_vPointer + Marshal.SizeOf(typeof(LVITEM)));
                    uint w_vNumberOfBytesRead = 0;

                    WriteProcessMemory(w_vProcess, w_vPointer,
                                       Marshal.UnsafeAddrOfPinnedArrayElement(w_vItem, 0),
                                       Marshal.SizeOf(typeof(LVITEM)), ref w_vNumberOfBytesRead);
                    SendMessage(w_vHandle, LVM_GETITEMW, i, w_vPointer.ToInt32());
                    ReadProcessMemory(w_vProcess,
                                      (IntPtr)((int)w_vPointer + Marshal.SizeOf(typeof(LVITEM))),
                                      Marshal.UnsafeAddrOfPinnedArrayElement(w_vBuffer, 0),
                                      w_vBuffer.Length, ref w_vNumberOfBytesRead);

                    string w_vText = Marshal.PtrToStringUni(
                        Marshal.UnsafeAddrOfPinnedArrayElement(w_vBuffer, 0));
                    retVal.AppendLine(w_vText);
                }
            }
            finally
            {
                VirtualFreeEx(w_vProcess, w_vPointer, 0, MEM_RELEASE);
                CloseHandle(w_vProcess);
            }

            return(retVal.ToString());
        }
コード例 #28
0
        /// <summary>
        /// 获取ViewList中的内容
        /// </summary>
        /// <param name="_element">AutomationElement对象</param>
        public Dictionary <string, DataItem> GetViewList(AutomationElement _element, int _column)
        {
            //获取list表里的行数
            int count = (int)SendMessage((IntPtr)_element.Current.NativeWindowHandle, LVM_GETITEMCOUNT, 0, 0);


            uint vProcessId;

            //根据句柄获取进程号
            GetWindowThreadProcessId((IntPtr)_element.Current.NativeWindowHandle, out vProcessId);

            IntPtr vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
                                          PROCESS_VM_WRITE, false, vProcessId);
            IntPtr vPointer = VirtualAllocEx(vProcess, IntPtr.Zero, 4096,
                                             MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

            for (int i = 0; i < count; i++)
            {
                DataItem item = new DataItem();
                item.data = new string[_column];
                for (int j = 0; j < _column; j++)
                {
                    byte[]   vBuffer = new byte[256];
                    LVITEM[] vItem   = new LVITEM[1];
                    vItem[0].mask       = LVIF_TEXT;
                    vItem[0].iItem      = i;
                    vItem[0].iSubItem   = j;
                    vItem[0].cchTextMax = vBuffer.Length;
                    vItem[0].pszText    = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(LVITEM)));
                    uint vNumberOfBytesRead = 0;
                    WriteProcessMemory(vProcess, vPointer,
                                       Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),
                                       Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);
                    SendMessage((IntPtr)_element.Current.NativeWindowHandle, LVM_GETITEMW, i, vPointer.ToInt32());
                    ReadProcessMemory(vProcess,
                                      (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(LVITEM))),
                                      Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),
                                      vBuffer.Length, ref vNumberOfBytesRead);

                    string vText = Marshal.PtrToStringUni(
                        Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0));
                    item.data[j] = vText;
                }
                if (!DataList.Keys.Contains(item.data[0]))
                {
                    DataList.Add(item.data[0], item);
                }
                else
                {
                    DataList[item.data[0]] = item;
                }
            }
            return(DataList);
        }
コード例 #29
0
        /// <summary>
        /// Set the item state on the given item
        /// </summary>
        /// <param name="list">The listview whose item's state is to be changed</param>
        /// <param name="itemIndex">The index of the item to be changed</param>
        /// <param name="mask">Which bits of the value are to be set?</param>
        /// <param name="value">The value to be set</param>
        private static void SetItemState(ListView list, int itemIndex, int mask, int value)
        {
            if (!list.IsHandleCreated)
            {
                return;
            }

            var lvItem = new LVITEM {
                stateMask = mask, state = value
            };

            SendMessageLVItem(list.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
        }
コード例 #30
0
        /// <summary>
        /// ListView のアイテムを選択された状態にします
        /// </summary>
        /// <param name="listView">対象となる ListView</param>
        /// <param name="index">選択するアイテムのインデックス</param>
        /// <returns>成功した場合は true、それ以外の場合は false</returns>
        public static bool SelectItem(ListView listView, int index)
        {
            // LVM_SETITEMSTATE では stateMask, state 以外のメンバーは無視される
            var lvitem = new LVITEM
            {
                stateMask = LVIS.SELECTED,
                state     = LVIS.SELECTED,
            };

            var ret = (int)SendMessage(listView.Handle, SendMessageType.LVM_SETITEMSTATE, (IntPtr)index, ref lvitem);

            return(ret != 0);
        }
コード例 #31
0
        public static List <string> GetItemsText(this IntPtr handle, List <int> rowIndex, int column)
        {
            List <string> texts = new List <string>();

            if (rowIndex != null)
            {
                int processid = 0;
                NativeMethods.GetWindowThreadProcessId(handle, ref processid);
                if (processid != 0)
                {
                    int process = NativeMethods.OpenProcess((int)(PROCESS.PROCESS_VM_OPERATION | PROCESS.PROCESS_VM_READ | PROCESS.PROCESS_VM_WRITE), false, processid);
                    var pointer = NativeMethods.VirtualAllocEx(process, IntPtr.Zero, (uint)4096, (uint)(MEM.MEM_RESERVE | MEM.MEM_COMMIT), (uint)PAGE.PAGE_READWRITE);

                    int count = handle.GetItemCount();
                    if (count > 0 && rowIndex.Count <= count)
                    {
                        foreach (int itemindex in rowIndex)
                        {
                            //定义一个临时缓冲区
                            byte[]   vBuffer = new byte[256];
                            LVITEM[] vItem   = new LVITEM[1];
                            vItem[0].mask     = LVIF_TEXT;
                            vItem[0].iItem    = itemindex;
                            vItem[0].iSubItem = column;

                            vItem[0].state     = 0;
                            vItem[0].stateMask = 0;

                            //所能存储的最大的文本为256字节
                            vItem[0].cchTextMax = vBuffer.Length;
                            vItem[0].pszText    = (IntPtr)((int)pointer + Marshal.SizeOf(typeof(LVITEM)));
                            uint vNumberOfBytesRead = 0;

                            //把数据写到vItem中
                            //pointer为申请到的内存的首地址
                            //UnsafeAddrOfPinnedArrayElement:获取指定数组中指定索引处的元素的地址
                            NativeMethods.WriteProcessMemory(process, pointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);

                            //发送LVM_GETITEMW消息给hwnd,将返回的结果写入pointer指向的内存空间
                            NativeMethods.SendMessage(handle, (int)SysListView32.LVM_GETITEMW, itemindex, pointer);
                            //从pointer指向的内存地址开始读取数据,写入缓冲区vBuffer中
                            NativeMethods.ReadProcessMemory(process, ((int)pointer + Marshal.SizeOf(typeof(LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead);

                            texts.Add(Encoding.Unicode.GetString(vBuffer, 0, (int)vNumberOfBytesRead));
                        }
                    }
                }
            }
            return(texts);
        }
コード例 #32
0
 public static void SetGhosted(this ListViewItem instance, bool state)
 {
     try
     {
         LVITEM lvItem = new LVITEM();
         lvItem.iItem     = instance.Index;
         lvItem.mask      = LVIF_STATE;
         lvItem.stateMask = LVIS_CUT;
         //Zero will clear the bit so it is sent when the property is set to false.
         lvItem.state = state ? LVIS_CUT : 0;
         int response = SendMessageA(instance.ListView.Handle, LVM_SETITEM, 0, ref lvItem);
     }
     catch
     {
     }
 }
コード例 #33
0
ファイル: Win32.cs プロジェクト: improvedk/Multi-Table-Helper
 public static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, ref LVITEM lvItem);
コード例 #34
0
 private bool ListView_BeginLabelEdit(LVITEM item) {
     if(QTUtility.IsVista || QTUtility.CheckConfig(Settings.ExtWhileRenaming)) {
         return false;
     }
     if(item.lParam != IntPtr.Zero) {
         IntPtr ptr2 = ShellMethods.ShellGetPath(this.ShellBrowser);
         if((ptr2 != IntPtr.Zero)) {
             IntPtr ptr3 = PInvoke.ILCombine(ptr2, item.lParam);
             HandleRenaming(listViewWrapper, ptr3, this);
             PInvoke.CoTaskMemFree(ptr2);
             PInvoke.CoTaskMemFree(ptr3);
         }
     }
     return false;
 }
コード例 #35
0
ファイル: Win32.cs プロジェクト: toptensoftware/UIAutoTest
 public static extern IntPtr SendMessage(IntPtr hWnd, uint message, IntPtr wParam, ref LVITEM item);
コード例 #36
0
ファイル: Win32Wrappers.cs プロジェクト: sillsdev/CarlaLegacy
		public static extern void SendMessage(IntPtr hWnd, LVMsgs msg, int wParam, ref LVITEM lParam);
コード例 #37
0
ファイル: QTDesktopTool.cs プロジェクト: Nicologies/QTTabBar
        private static RECT GetLVITEMRECT(IntPtr hwndListView, int iItem, bool fSubDirTip, FOLDERVIEWMODE fvm)
        {
            // get the bounding rectangle of item specified by iItem, in the screen coordinates.
            // fSubDirTip	true to get RECT depending on view style, false to get RECT by LVIR_BOUNDS

            const uint LVM_FIRST = 0x1000;
            const uint LVM_GETVIEW = (LVM_FIRST + 143);
            const uint LVM_GETITEMW = (LVM_FIRST + 75);
            const uint LVM_GETSTRINGWIDTHW = (LVM_FIRST + 87);
            const uint LVM_GETITEMSPACING = (LVM_FIRST + 51);
            const int LVIR_BOUNDS = 0;
            const int LVIR_ICON = 1;
            const int LVIR_LABEL = 2;
            const int LV_VIEW_ICON = 0x0000;
            const int LV_VIEW_DETAILS = 0x0001;
            const int LV_VIEW_LIST = 0x0003;
            const int LV_VIEW_TILE = 0x0004;
            const int LVIF_TEXT = 0x00000001;

            int view = (int)PInvoke.SendMessage(hwndListView, LVM_GETVIEW, IntPtr.Zero, IntPtr.Zero);
            int code = view == LV_VIEW_DETAILS ? LVIR_LABEL : LVIR_BOUNDS;

            bool fIcon = false; // for XP
            bool fList = false; // for XP

            if(fSubDirTip) {
                switch(view) {
                    case LV_VIEW_ICON:
                        fIcon = !QTUtility.IsVista;
                        code = LVIR_ICON;
                        break;

                    case LV_VIEW_DETAILS:
                        code = LVIR_LABEL;
                        break;

                    case LV_VIEW_LIST:
                        if(!QTUtility.IsVista) {
                            fList = true;
                            code = LVIR_ICON;
                        }
                        else {
                            code = LVIR_LABEL;
                        }
                        break;

                    case LV_VIEW_TILE:
                        code = LVIR_ICON;
                        break;

                    default:
                        // Here only in case of Vista LV_VIEW_SMALLICON.
                        code = LVIR_BOUNDS;
                        break;
                }
            }

            // get item rectangle
            RECT rct = PInvoke.ListView_GetItemRect(hwndListView, iItem, 0, code);

            // convert to screen coordinates
            PInvoke.MapWindowPoints(hwndListView, IntPtr.Zero, ref rct, 2);

            // adjust rct
            // these magic numbers have no logical meanings
            if(fIcon) {
                // XP, subdirtip.
                // THUMBNAIL, THUMBSTRIP or ICON.
                if(fvm == FOLDERVIEWMODE.FVM_THUMBNAIL || fvm == FOLDERVIEWMODE.FVM_THUMBSTRIP) {
                    rct.right -= 13;
                }
                else // fvm == FVM_ICON
                {
                    int currentIconSpacing =
                            (int)(long)PInvoke.SendMessage(hwndListView, LVM_GETITEMSPACING, IntPtr.Zero, IntPtr.Zero);
                    Size sz = SystemInformation.IconSize;
                    rct.right = rct.left + (((currentIconSpacing & 0xFFFF) - sz.Width)/2) + sz.Width + 8;
                    rct.bottom = rct.top + sz.Height + 6;
                }
            }
            else if(fList) {
                // XP, subdirtip.
                // calculate item text rectangle
                LVITEM lvitem = new LVITEM();
                lvitem.pszText = Marshal.AllocCoTaskMem(520);
                lvitem.cchTextMax = 260;
                lvitem.iItem = iItem;
                lvitem.mask = LVIF_TEXT;
                IntPtr pLI = Marshal.AllocCoTaskMem(Marshal.SizeOf(lvitem));
                Marshal.StructureToPtr(lvitem, pLI, false);

                PInvoke.SendMessage(hwndListView, LVM_GETITEMW, IntPtr.Zero, pLI);

                int w = (int)PInvoke.SendMessage(hwndListView, LVM_GETSTRINGWIDTHW, IntPtr.Zero, lvitem.pszText);
                w += 20;

                Marshal.FreeCoTaskMem(lvitem.pszText);
                Marshal.FreeCoTaskMem(pLI);

                rct.right += w;
                rct.top += 2;
                rct.bottom += 2;
            }

            return rct;
        }
コード例 #38
0
        public void highLightUser(string user = "")
        {
            int lvCount = SendMessage(_listHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, IntPtr.Zero);

            if (lvCount > 0)
            {

                int ProcessID = 0;
                IntPtr processHandle = IntPtr.Zero;
                IntPtr lvMemItem = IntPtr.Zero;
                LVITEM lvLocalItem = new LVITEM();

                try
                {
                    GetWindowThreadProcessId(_listHwnd, out ProcessID);

                    processHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, ProcessID);

                    //ListViewItem
                    lvLocalItem.mask = LVIF_STATE;
                    lvLocalItem.stateMask = LVIS_SELECTED;
                    lvLocalItem.state = 0;

                    IntPtr tmpOut = (IntPtr)0;  //dummy pointer

                    lvMemItem = VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(lvLocalItem), MEM_COMMIT, PAGE_READWRITE); // alloc memory for my whole ListviewItem

                    WriteProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut);

                    for (int i = 0; i < lvCount; i++) // unhighlight all
                    {
                        SendMessage(_listHwnd, LVM_SETITEMSTATE, i, lvMemItem);
                    }

                    if (user != "") // if there is a  user to highlight (argument is passed)
                    {
                        int index = getUserNameIndex(user, false);

                        if (index != -1)
                        {
                            VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
                            lvLocalItem.state = LVIS_SELECTED;
                            lvMemItem = VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(lvLocalItem), MEM_COMMIT, PAGE_READWRITE);
                            WriteProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut);
                            SendMessage(_listHwnd, LVM_SETITEMSTATE, index, lvMemItem);
                        }

                    }

                }
                catch (Exception e)
                {
                    errLog.Log("HighLightUser", e.Message);
                }

                finally
                {
                    try
                    {
                        VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
                        VirtualFreeEx(processHandle, lvLocalItem.pszText, 0, MEM_RELEASE);
                        CloseHandle(processHandle);
                    }
                    catch (Exception) { }
                }

            }//end if
        }
コード例 #39
0
ファイル: TwzWinAPI.cs プロジェクト: cimoh/twz-ptk-lib
 public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LVITEM lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);
コード例 #40
0
ファイル: ExtendedListView.cs プロジェクト: helgihaf/Alpha
 private static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam, ref LVITEM lParam);
コード例 #41
0
 private bool ListView_EndLabelEdit(LVITEM item) {
     if(item.pszText == IntPtr.Zero) {
         return false;
     }
     IShellView ppshv = null;
     IntPtr zero = IntPtr.Zero;
     IntPtr ptr5 = IntPtr.Zero;
     IntPtr pIDL = IntPtr.Zero;
     try {
         if(this.ShellBrowser.QueryActiveShellView(out ppshv) == 0) {
             IFolderView view2 = (IFolderView)ppshv;
             if(view2.Item(item.iItem, out zero) == 0) {
                 ptr5 = ShellMethods.ShellGetPath(this.ShellBrowser);
                 pIDL = PInvoke.ILCombine(ptr5, zero);
                 string displayName = ShellMethods.GetDisplayName(pIDL, true);
                 string str2 = Marshal.PtrToStringUni(item.pszText);
                 if(displayName != str2) {
                     this.HandleF5();
                 }
             }
         }
     }
     catch {
     }
     finally {
         if(ppshv != null) {
             Marshal.ReleaseComObject(ppshv);
         }
         if(zero != IntPtr.Zero) {
             PInvoke.CoTaskMemFree(zero);
         }
         if(ptr5 != IntPtr.Zero) {
             PInvoke.CoTaskMemFree(ptr5);
         }
         if(pIDL != IntPtr.Zero) {
             PInvoke.CoTaskMemFree(pIDL);
         }
     }
     return false;
 }
コード例 #42
0
 /// <summary>
 /// A subitem (a column value) of an item of this list view.
 /// </summary>
 public SystemListViewItem this[int index, int subIndex]
 {
     get
     {
         LVITEM lvi = new LVITEM();
         lvi.cchTextMax = 300;
         lvi.iItem = index;
         lvi.iSubItem = subIndex;
         lvi.stateMask = 0xffffffff;
         lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_TEXT;
         ProcessMemoryChunk tc = ProcessMemoryChunk.Alloc(sw.Process, 301);
         lvi.pszText = tc.Location;
         ProcessMemoryChunk lc = ProcessMemoryChunk.AllocStruct(sw.Process, lvi);
         ApiHelper.FailIfZero(SystemWindow.SendMessage(new HandleRef(sw, sw.HWnd), SystemListView.LVM_GETITEM, IntPtr.Zero, lc.Location));
         lvi = (LVITEM)lc.ReadToStructure(0, typeof(LVITEM));
         lc.Dispose();
         if (lvi.pszText != tc.Location)
         {
             tc.Dispose();
             tc = new ProcessMemoryChunk(sw.Process, lvi.pszText, lvi.cchTextMax);
         }
         byte[] tmp = tc.Read();
         string title = Encoding.Default.GetString(tmp);
         if (title.IndexOf('\0') != -1) title = title.Substring(0, title.IndexOf('\0'));
         int image = lvi.iImage;
         uint state = lvi.state;
         tc.Dispose();
         return new SystemListViewItem(sw, index, title, state, image);
     }
 }
コード例 #43
0
ファイル: ListView.cs プロジェクト: alexhanh/Botting-Library
        public void SelectItem(int row)
        {
            if (row >= ItemCount) return;

            LVITEM item = new LVITEM();

            item.state = LVIS_SELECTED | LVIS_FOCUSED;
            item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
            item.mask = LVIF_STATE;

            Interop.SendMessage(Handle, (uint)Messages.LVM_ENSUREVISIBLE, new IntPtr(row), new IntPtr(0));

            unsafe
            {
                IntPtr item_pointer = new IntPtr((void*)&item);

                IntPtr external_item = window_process.AllocateMemory(Marshal.SizeOf(item));
                window_process.Write(item_pointer, external_item, Marshal.SizeOf(item));

                Interop.SendMessage(Handle, (uint)Messages.LVM_SETITEMSTATE, new IntPtr(row), external_item);

                window_process.FreeMemory(external_item);
            }
        }
コード例 #44
0
ファイル: Win32Wrappers.cs プロジェクト: sillsdev/CarlaLegacy
		// TODO-Linux: Implement if needed
		public static void SendMessage(IntPtr hWnd, LVMsgs msg, int wParam, ref LVITEM lParam)
		{
			Console.WriteLine("Warning using unimplemented method SendMessage");
		}
コード例 #45
0
 /// <summary>
 /// Set the item state on the given item
 /// </summary>
 /// <param name="list">The listview whose item's state is to be changed</param>
 /// <param name="itemIndex">The index of the item to be changed</param>
 /// <param name="mask">Which bits of the value are to be set?</param>
 /// <param name="value">The value to be set</param>
 public static void SetItemState(ListView list, int itemIndex, int mask, int value)
 {
     LVITEM lvItem = new LVITEM();
     lvItem.stateMask = mask;
     lvItem.state = value;
     SendMessageLVItem(list.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
 }
コード例 #46
0
ファイル: Win32.cs プロジェクト: RoDaniel/featurehouse
 public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref LVITEM lvi);
コード例 #47
0
        public string[] getUserNames(bool highLighted = false, bool lowerCase = false)
        {
            /* if highLighted is true then the function will function will return
             * the highlighted item only. If there is none an empty will be retuned
             */

            int lvCount = SendMessage(_listHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, IntPtr.Zero);

            if (lvCount == 0) return null;

            int ProcessID = 0;
            IntPtr processHandle = IntPtr.Zero;
            IntPtr lvMemItem     = IntPtr.Zero;
            LVITEM lvLocalItem   = new LVITEM();

            string[] userNameArray = new string[lvCount];

            try
            {
                GetWindowThreadProcessId(_listHwnd, out ProcessID);
                processHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, ProcessID);

                //ListViewItem
                lvLocalItem.mask       = LVIF_TEXT;
                lvLocalItem.iSubItem   = wndParams.ListIndex;
                lvLocalItem.cchTextMax = MAX_LVMSTRING;
                lvLocalItem.pszText    = VirtualAllocEx(processHandle, IntPtr.Zero, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE); // alloc memory for the username string

                lvMemItem = VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(lvLocalItem), MEM_COMMIT, PAGE_READWRITE); // alloc memory for my whole ListviewItem

                IntPtr tmpOut = (IntPtr)0;  // null pointer to use with Read/Write process memory (last parameter)

                WriteProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut);

                int strLen = 0;
                StringBuilder strBuffer = new StringBuilder();

                if (highLighted)
                {
                    for (int i = 0; i < lvCount; i++)
                    {
                        if (SendMessage(_listHwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED) != 0) // if the username is selected
                        {
                            strLen = SendMessage(_listHwnd, LVM_GETITEMTEXT, i, lvMemItem);
                            ReadProcessMemory(processHandle, lvLocalItem.pszText, strBuffer, strLen, out tmpOut);
                            userNameArray[0] = strBuffer.ToString().Substring(0, strLen);

                            if (lowerCase)
                                userNameArray[0] = userNameArray[0].ToLower();
                            break;
                        }
                    }
                    strBuffer.Clear();
                }
                else
                {
                    for( int i = 0; i < lvCount; i++)
                    {
                        strLen = SendMessage(_listHwnd, LVM_GETITEMTEXT, i, lvMemItem);
                        ReadProcessMemory(processHandle, lvLocalItem.pszText, strBuffer, strLen, out tmpOut);
                        userNameArray[i] = strBuffer.ToString().Substring(0, strLen);

                        if (lowerCase)
                            userNameArray[i] = userNameArray[i].ToLower();
                    }
                    strBuffer.Clear();
                }

            }
            catch (Exception e)
            {
                errLog.Log("getUserNames", e.Message);
            }

            finally
            {
                try
                {
                    VirtualFreeEx(processHandle, lvLocalItem.pszText, 0, MEM_RELEASE);
                    VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
                    CloseHandle(processHandle);
                }
                catch (Exception) { }
            }

            return userNameArray;
        }
コード例 #48
0
ファイル: Win32.cs プロジェクト: improvedk/Multi-Table-Helper
        public static extern bool WriteProcessMemory( int hProcess, int lpBaseAddress, 
			ref LVITEM buffer, int dwSize, int lpNumberOfBytesWritten );
コード例 #49
0
        //reddot onmic raisehand
        public int getUserNameStatus(string strUser)
        {
            int lvCount = SendMessage(_listHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, IntPtr.Zero);
            int itemIndex = getUserNameIndex(strUser, false);
            int ret = 255;

            if (lvCount != 0 && itemIndex != -1)
            {

                int ProcessID           = 0;
                LVITEM lvLocalItem      = new LVITEM();
                IntPtr processHandle    = IntPtr.Zero;
                IntPtr lvMemItem        = IntPtr.Zero;
                IntPtr tmpOut           = (IntPtr)0;  // null pointer to use with Read/Write process memory (last parameter)

                try
                {

                    GetWindowThreadProcessId(_listHwnd, out ProcessID);
                    processHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, ProcessID);

                    //ListViewItem
                    lvLocalItem.mask = LVIF_IMAGE;
                    lvLocalItem.iItem = itemIndex;
                    lvLocalItem.iSubItem = 0;

                    lvMemItem = VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(lvLocalItem), MEM_COMMIT, PAGE_READWRITE); // alloc memory for my whole ListviewItem
                    WriteProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut);
                    SendMessage(_listHwnd, LVM_GETITEM, itemIndex, lvMemItem);

                    if (ReadProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut))
                    {
                        ret = lvLocalItem.iImage;
                        Debug.Print(strUser + ">state:" + ret.ToString());
                    }
                }
                catch (Exception e)
                {
                    errLog.Log("getUserStatus", e.Message);
                }
                finally
                {
                    try
                    {
                        VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
                        CloseHandle(processHandle);
                    }
                    catch (Exception) { }

                }

            }//end if lvCount

            return ret;
        }
コード例 #50
0
ファイル: ListviewAPI.cs プロジェクト: arangas/MediaPortal-1
    public static int AddItemToGroup(XPListView lst, int index, int groupID)
    {
      LVITEM apiItem;
      int ptrRetVal;

      try
      {
        if (lst == null)
        {
          return 0;
        }

        apiItem = new LVITEM();
        apiItem.mask = LVIF_GROUPID;
        apiItem.iItem = index;
        apiItem.iGroupId = groupID;

        ptrRetVal = (int)SendMessage(lst.Handle, ListViewAPI.LVM_SETITEM, 0, ref apiItem);

        return ptrRetVal;
      }
      catch (Exception ex)
      {
        throw new System.Exception("An exception in ListViewAPI.AddItemToGroup occured: " + ex.Message);
      }
    }
コード例 #51
0
ファイル: TwzWinAPI.cs プロジェクト: cimoh/twz-ptk-lib
 public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LVITEM buffer, int size, out IntPtr lpNumberOfBytesRead);
コード例 #52
0
ファイル: ListviewAPI.cs プロジェクト: arangas/MediaPortal-1
 public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVITEM lParam);
コード例 #53
0
    private void ProcessCustomDrawPostPaint(ref Message m, User32.NMLVCUSTOMDRAW nmlvcd, Int32 index, IntPtr hdc, IListItemEx sho, Color? textColor) {
      if (nmlvcd.clrTextBk != 0 && nmlvcd.dwItemType == 0 && this._CurrentDrawIndex == -1) {
        //var perceivedType = (PerceivedType)sho.GetPropertyValue(SystemProperties.PerceivedType, typeof(PerceivedType)).Value;
        this._CurrentDrawIndex = index;
        var itemBounds = nmlvcd.nmcd.rc;
        var lvi = new LVITEMINDEX();
        lvi.iItem = index;
        lvi.iGroup = this.GetGroupIndex(index);
        var iconBounds = new User32.RECT() { Left = 1 };
        User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref iconBounds);
        var lvItem = new LVITEM() {
          iItem = index,
          iGroupId = lvi.iGroup,
          iGroup = lvi.iGroup,
          mask = LVIF.LVIF_STATE,
          stateMask = LVIS.LVIS_SELECTED
        };
        var lvItemImageMask = new LVITEM() {
          iItem = index,
          iGroupId = lvi.iGroup,
          iGroup = lvi.iGroup,
          mask = LVIF.LVIF_STATE,
          stateMask = LVIS.LVIS_STATEIMAGEMASK
        };

        if (sho != null) {
          var cutFlag = (User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMSTATE, index, LVIS.LVIS_CUT) & LVIS.LVIS_CUT) ==
                                                                  LVIS.LVIS_CUT;
          if (this.IconSize == 16) {
            this.SmallImageList.DrawIcon(hdc, index, sho, iconBounds,
                    sho.IsHidden || cutFlag || this._CuttedIndexes.Contains(index), (nmlvcd.nmcd.uItemState & CDIS.HOT) == CDIS.HOT);
          } else {
            this.LargeImageList.DrawIcon(hdc, index, sho, iconBounds,
                    sho.IsHidden || cutFlag || this._CuttedIndexes.Contains(index), (nmlvcd.nmcd.uItemState & CDIS.HOT) == CDIS.HOT);
          }

          if (!sho.IsInitialised) sho.IsInitialised = true;
        }
        m.Result = (IntPtr)CustomDraw.CDRF_SKIPDEFAULT;
      } else {
        m.Result = IntPtr.Zero;
      }

      this._CurrentDrawIndex = -1;
    }
コード例 #54
0
 private void ListView_EndLabelEdit(LVITEM item) {
     if(item.pszText != IntPtr.Zero) {
         using(IDLWrapper wrapper = ShellBrowser.GetItem(item.iItem)) {
             if(wrapper.DisplayName != Marshal.PtrToStringUni(item.pszText)) {
                 HandleF5();
             }
         }
     }
     return;
 }
コード例 #55
0
ファイル: Win32.cs プロジェクト: improvedk/Multi-Table-Helper
 public static extern int SendMessage(int hWnd, Int32 msg, Int32 wParam, ref LVITEM lvItem);
コード例 #56
0
 public static extern uint SendListViewMessage
 (
     [In] this IntPtr hWnd,
     uint Msg,
     uint wParam,
     ref LVITEM lParam
 );
コード例 #57
0
 public static extern IntPtr SendMessageLVItem(IntPtr hWnd, int msg, int wParam, ref LVITEM lvi);
コード例 #58
0
ファイル: NativeMethods.cs プロジェクト: spx268/OpenTween
        /// <summary>
        /// ListView のアイテムを選択された状態にします
        /// </summary>
        /// <param name="listView">対象となる ListView</param>
        /// <param name="index">選択するアイテムのインデックス</param>
        /// <returns>成功した場合は true、それ以外の場合は false</returns>
        public static bool SelectItem(ListView listView, int index)
        {
            // LVM_SETITEMSTATE では stateMask, state 以外のメンバーは無視される
            var lvitem = new LVITEM
            {
                stateMask = LVIS.SELECTED,
                state = LVIS.SELECTED,
            };

            var ret = (int)SendMessage(listView.Handle, SendMessageType.LVM_SETITEMSTATE, (IntPtr)index, ref lvitem);
            return ret != 0;
        }
コード例 #59
0
 /// <summary>
 /// For the given item and subitem, make it display the given image
 /// </summary>
 /// <param name="list">The listview to send a m to</param>
 /// <param name="itemIndex">row number (0 based)</param>
 /// <param name="subItemIndex">subitem (0 is the item itself)</param>
 /// <param name="imageIndex">index into the image list</param>
 public static void SetSubItemImage(ListView list, int itemIndex, int subItemIndex, int imageIndex)
 {
     LVITEM lvItem = new LVITEM();
     lvItem.mask = LVIF_IMAGE;
     lvItem.iItem = itemIndex;
     lvItem.iSubItem = subItemIndex;
     lvItem.iImage = imageIndex;
     SendMessageLVItem(list.Handle, LVM_SETITEM, 0, ref lvItem);
 }
コード例 #60
0
ファイル: NativeMethods.cs プロジェクト: spx268/OpenTween
 private extern static IntPtr SendMessage(
     IntPtr hwnd,
     SendMessageType wMsg,
     IntPtr wParam,
     ref LVITEM lParam);