Ejemplo n.º 1
0
        public void SetItemDisplay(int row, int column, ItemDisplay displayMode, int imageIndex)
        {
            LV_ITEM item = new LV_ITEM();

            item.iItem    = row;
            item.iSubItem = column;
            switch (displayMode)
            {
            case ItemDisplay.Text:
                item.mask    = ( uint )LVIF.LVIF_TEXT;
                item.pszText = new StringBuilder(this.GetItemText(row, column));
                break;

            case ItemDisplay.Image:
                item.mask = ( uint )LVIF.LVIF_IMAGE;
                break;

            case ItemDisplay.ImageAndText:
                item.mask    = ( uint )(LVIF.LVIF_IMAGE | LVIF.LVIF_TEXT);
                item.pszText = new StringBuilder(this.GetItemText(row, column));
                break;
            }
            item.iImage = imageIndex;
            SendMessage(this.Handle, ( int )LVM.LVM_SETITEM, 0, ref item);
        }
Ejemplo n.º 2
0
        public bool SetIndentation()
        {
            if (!IsInATreeListView)
            {
                return(false);
            }
            bool    result = true;
            LV_ITEM lParam = default(LV_ITEM);

            lParam.iItem   = base.Index;
            lParam.iIndent = Level;
            if (TreeListView.ShowPlusMinus)
            {
                lParam.iIndent++;
            }
            lParam.mask = ListViewItemFlags.INDENT;
            try
            {
                SendMessage(ListView.Handle, ListViewMessages.SETITEM, 0, ref lParam);
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set the indentation using the level of this item
        /// </summary>
        /// <returns>True if successfull, false otherwise</returns>
        public bool SetIndentation()
        {
            if (!IsInATreeListView)
            {
                return(false);
            }
            bool    res = true;
            LV_ITEM lvi = new LV_ITEM();

            lvi.iItem   = Index;
            lvi.iIndent = Level;
            if (TreeListView.ShowPlusMinus)
            {
                lvi.iIndent++;
            }
            lvi.mask = ListViewItemFlags.INDENT;
            try
            {
                SendMessage(ListView.Handle, ListViewMessages.SETITEM, 0, ref lvi);
            }
            catch
            {
                res = false;
            }
            return(res);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// アイコン一覧の取得
            /// </summary>
            public static void ReadIconList()
            {
                int    dwBufferSize  = 1024;
                IntPtr lpLocalBuffer = Marshal.AllocHGlobal(dwBufferSize);

                lock (iconInfoList)
                {
                    iconInfoList.Clear();
                    IntPtr hDesktopListView = GetFindDesktopListViewWnd.getDesktopListViewAddress();
                    IntPtr baseAddress      = SharedMemory.getRemoteBufferAddress();
                    int    IconCount        = ListView_GetItemCount(hDesktopListView);

                    try
                    {
                        for (int IconNo = 0; IconNo < IconCount; IconNo++)
                        {
                            IntPtr ipIconNo = (IntPtr)IconNo;
                            // テキスト取得
                            LV_ITEM LocalItem = new LV_ITEM();
                            LocalItem.mask       = LVIF_TEXT;
                            LocalItem.iItem      = 0;
                            LocalItem.pszText    = (IntPtr)(baseAddress.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)));
                            LocalItem.cchTextMax = 256;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalItem, Marshal.SizeOf(typeof(LV_ITEM)));
                            int Len = SendMessage(hDesktopListView, LVM_GETITEMTEXT, ipIconNo, baseAddress);
                            // char[] LocalText = new char[256];
                            // System.Runtime.InteropServices.Marshal.StructureToPtr(LocalText, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, dwBufferSize);
                            string iconText = Marshal.PtrToStringAnsi((IntPtr)(lpLocalBuffer.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM))));

                            // アイコン矩形取得&チェック
                            RECT LocalRect = new RECT();
                            LocalRect.left = LVIR_ICON;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalRect, Marshal.SizeOf(typeof(RECT)));
                            SendMessage(hDesktopListView, LVM_GETITEMRECT, (IntPtr)IconNo, baseAddress);
                            Marshal.StructureToPtr(LocalRect, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, Marshal.SizeOf(typeof(RECT)));
                            LocalRect = (RECT)Marshal.PtrToStructure(lpLocalBuffer, typeof(RECT));
                            setIconList(LocalRect, iconText);
                            // テキスト矩形取得&チェック
                            LocalRect.left = LVIR_LABEL;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalRect, Marshal.SizeOf(typeof(RECT)));
                            SendMessage(hDesktopListView, LVM_GETITEMRECT, (IntPtr)IconNo, baseAddress);
                            Marshal.StructureToPtr(LocalRect, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, Marshal.SizeOf(typeof(RECT)));
                            LocalRect = (RECT)Marshal.PtrToStructure(lpLocalBuffer, typeof(RECT));
                            setIconList(LocalRect, iconText);
                        }
                    }
                    finally
                    {
                        if (lpLocalBuffer != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(lpLocalBuffer);
                        }
                    }
                }
            }
Ejemplo n.º 5
0
 private string GetItemText( int row, int column )
 {
     LV_ITEM item = new LV_ITEM();
     item.iSubItem = column;
     item.pszText = new StringBuilder( 512 );
     item.cchTextMax = 512;
     SendMessage( this.Handle, ( int )LVM.LVM_GETITEMTEXT, row, ref item );
     return item.pszText.ToString();
 }
Ejemplo n.º 6
0
        private string GetItemText(int row, int column)
        {
            LV_ITEM item = new LV_ITEM();

            item.iSubItem   = column;
            item.pszText    = new StringBuilder(512);
            item.cchTextMax = 512;
            SendMessage(this.Handle, ( int )LVM.LVM_GETITEMTEXT, row, ref item);
            return(item.pszText.ToString());
        }
Ejemplo n.º 7
0
        public static void AddIconToSubItem(this ListView listView, int row, int column, int iconIndex)
        {
            var lvi = new LV_ITEM
            {
                iItem    = row,
                iSubItem = column,
                uiMask   = LVIF_IMAGE,
                iImage   = iconIndex
            };

            SendMessage(listView.Handle, LVM_SETITEM, 0, ref lvi);
        }
Ejemplo n.º 8
0
        public static string GetItem(int row, int subitem, SafeProcessHandle hProcess)
        {
            IntPtr  ptr;
            LV_ITEM lpBuffer = new LV_ITEM();

            lpBuffer.cchTextMax = 260;
            lpBuffer.mask       = 1;
            lpBuffer.iItem      = row;
            lpBuffer.iSubItem   = subitem;
            StringBuilder builder = new StringBuilder(260);

            try
            {
                IntPtr ptr2;
                ptr = VirtualAllocEx(hProcess, IntPtr.Zero, 260, 0x1000, 4);
                lpBuffer.pszText = ptr;
                try
                {
                    ptr2 = VirtualAllocEx(hProcess, IntPtr.Zero, lpBuffer.Size(), 0x1000, 4);
                    int lpNumberOfBytesWritten = 0;
                    if (!WriteProcessMemory(hProcess, ptr2, ref lpBuffer, lpBuffer.Size(), ref lpNumberOfBytesWritten))
                    {
                        throw new Win32Exception();
                    }
                    SendMessage(listViewHandle, 0x102d, row, ptr2);
                    lpNumberOfBytesWritten = 0;
                    if (!ReadProcessMemory(hProcess, ptr, builder, 260, ref lpNumberOfBytesWritten))
                    {
                        throw new Win32Exception();
                    }
                    lpNumberOfBytesWritten = 0;
                    if (!ReadProcessMemory(hProcess, ptr2, ref lpBuffer, Marshal.SizeOf(lpBuffer), ref lpNumberOfBytesWritten))
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    if (!ptr2.Equals(IntPtr.Zero) && !VirtualFreeEx(hProcess, ptr2, 0, 0x8000))
                    {
                        throw new Win32Exception();
                    }
                }
            }
            finally
            {
                if (!ptr.Equals(IntPtr.Zero) && !VirtualFreeEx(hProcess, ptr, 0, 0x8000))
                {
                    throw new Win32Exception();
                }
            }
            return(builder.ToString());
        }
Ejemplo n.º 9
0
        // Add an icon to a subitem.
        public static void AddIconToSubitem(this ListView lvw, int row, int col, int icon_num)
        {
            LV_ITEM lvi = new LV_ITEM();

            lvi.iItem    = row;                     // Row.
            lvi.iSubItem = col;                     // Column.
            lvi.uiMask   = LVIF_IMAGE;              // We're setting the image.
            lvi.uiState  = 50;
            lvi.iImage   = icon_num;                // The image index in the ImageList.

            // Send the LVM_SETITEM message.
            SendMessage(lvw.Handle, LVM_SETITEM, 0, ref lvi);
        }
Ejemplo n.º 10
0
 public static string GetItem(int row, int subitem, SafeProcessHandle hProcess)
 {
     IntPtr ptr;
     LV_ITEM lpBuffer = new LV_ITEM();
     lpBuffer.cchTextMax = 260;
     lpBuffer.mask = 1;
     lpBuffer.iItem = row;
     lpBuffer.iSubItem = subitem;
     StringBuilder builder = new StringBuilder(260);
     try
     {
         IntPtr ptr2;
         ptr = VirtualAllocEx(hProcess, IntPtr.Zero, 260, 0x1000, 4);
         lpBuffer.pszText = ptr;
         try
         {
             ptr2 = VirtualAllocEx(hProcess, IntPtr.Zero, lpBuffer.Size(), 0x1000, 4);
             int lpNumberOfBytesWritten = 0;
             if (!WriteProcessMemory(hProcess, ptr2, ref lpBuffer, lpBuffer.Size(), ref lpNumberOfBytesWritten))
             {
                 throw new Win32Exception();
             }
             SendMessage(listViewHandle, 0x102d, row, ptr2);
             lpNumberOfBytesWritten = 0;
             if (!ReadProcessMemory(hProcess, ptr, builder, 260, ref lpNumberOfBytesWritten))
             {
                 throw new Win32Exception();
             }
             lpNumberOfBytesWritten = 0;
             if (!ReadProcessMemory(hProcess, ptr2, ref lpBuffer, Marshal.SizeOf(lpBuffer), ref lpNumberOfBytesWritten))
             {
                 throw new Win32Exception();
             }
         }
         finally
         {
             if (!ptr2.Equals(IntPtr.Zero) && !VirtualFreeEx(hProcess, ptr2, 0, 0x8000))
             {
                 throw new Win32Exception();
             }
         }
     }
     finally
     {
         if (!ptr.Equals(IntPtr.Zero) && !VirtualFreeEx(hProcess, ptr, 0, 0x8000))
         {
             throw new Win32Exception();
         }
     }
     return builder.ToString();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Set the indentation using the level of this item
        /// </summary>
        public void SetIndentation()
        {
            if (this.ListView == null)
            {
                return;
            }
            LV_ITEM lvi = new LV_ITEM();

            lvi.iItem   = this.Index;
            lvi.iIndent = this.Level;
            lvi.mask    = ListViewMessages.LVIF_INDENT;
            SendMessage(
                this.ListView.Handle,
                ListViewMessages.LVM_SETITEM,
                0,
                ref lvi);
        }
Ejemplo n.º 12
0
 public void SetItemDisplay( int row, int column, ItemDisplay displayMode, int imageIndex )
 {
     LV_ITEM item = new LV_ITEM();
     item.iItem = row;
     item.iSubItem = column;
     switch( displayMode )
     {
         case ItemDisplay.Text:
             item.mask = ( uint )LVIF.LVIF_TEXT;
             item.pszText = new StringBuilder( this.GetItemText( row, column ) );
             break;
         case ItemDisplay.Image:
             item.mask = ( uint )LVIF.LVIF_IMAGE;
             break;
         case ItemDisplay.ImageAndText:
             item.mask = ( uint )( LVIF.LVIF_IMAGE | LVIF.LVIF_TEXT );
             item.pszText = new StringBuilder( this.GetItemText( row, column ) );
             break;
     }
     item.iImage = imageIndex;
     SendMessage( this.Handle, ( int )LVM.LVM_SETITEM, 0, ref item );
 }
        //
        public void SetCellImg ( int nLine , int nCol , int nImgIndex )
        {
            LV_ITEM lvi = new LV_ITEM ();

            lvi.mask = XListView.LVIF_IMAGE | XListView.LVIF_TEXT;
            lvi.iItem = nLine;
            lvi.iSubItem = nCol;
            lvi.iImage = nImgIndex;
            lvi.pszText = GetCellText ( nLine , nCol );
            SendMessage ( Handle , LVM_SETITEM , 0 , ref lvi );
        }
 static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
                                       ref LV_ITEM buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
        public static string ReadListViewItem(IntPtr hWnd, int item)
        {
            const int dwBufferSize = 1024;

            int     dwProcessID;
            LV_ITEM lvItem;
            string  retval;
            bool    bSuccess;
            IntPtr  hProcess       = IntPtr.Zero;
            IntPtr  lpRemoteBuffer = IntPtr.Zero;
            IntPtr  lpLocalBuffer  = IntPtr.Zero;
            IntPtr  threadId       = IntPtr.Zero;

            try
            {
                lvItem        = new LV_ITEM();
                lpLocalBuffer = Marshal.AllocHGlobal(dwBufferSize);
                // Get the process id owning the window
                threadId = GetWindowThreadProcessId(hWnd, out dwProcessID);
                if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
                {
                    throw new ArgumentException("hWnd");
                }

                // Open the process with all access
                hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessID);
                if (hProcess == IntPtr.Zero)
                {
                    throw new ApplicationException("Failed to access process");
                }

                // Allocate a buffer in the remote process
                lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, dwBufferSize, MEM_COMMIT,
                                                PAGE_READWRITE);
                if (lpRemoteBuffer == IntPtr.Zero)
                {
                    throw new SystemException("Failed to allocate memory in remote process");
                }

                // Fill in the LVITEM struct, this is in your own process
                // Set the pszText member to somewhere in the remote buffer,
                // For the example I used the address imediately following the LVITEM stuct
                lvItem.mask       = LVIF_TEXT;
                lvItem.iItem      = 0;
                lvItem.pszText    = (IntPtr)(lpRemoteBuffer.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)));
                lvItem.cchTextMax = 50;

                // Copy the local LVITEM to the remote buffer
                bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem,
                                              Marshal.SizeOf(typeof(LV_ITEM)), IntPtr.Zero);
                if (!bSuccess)
                {
                    throw new SystemException("Failed to write to process memory");
                }

                // Send the message to the remote window with the address of the remote buffer
                SendMessage(hWnd, LVM_GETITEM, 0, lpRemoteBuffer);

                // Read the struct back from the remote process into local buffer
                bSuccess = ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, dwBufferSize,
                                             IntPtr.Zero);
                if (!bSuccess)
                {
                    throw new SystemException("Failed to read from process memory");
                }

                // At this point the lpLocalBuffer contains the returned LV_ITEM structure
                // the next line extracts the text from the buffer into a managed string
                retval = Marshal.PtrToStringAnsi((IntPtr)(lpLocalBuffer.ToInt32() +
                                                          Marshal.SizeOf(typeof(LV_ITEM))));
            }
            finally
            {
                if (lpLocalBuffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpLocalBuffer);
                }
                if (lpRemoteBuffer != IntPtr.Zero)
                {
                    VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
                }
                if (hProcess != IntPtr.Zero)
                {
                    CloseHandle(hProcess);
                }
            }
            return(retval);
        }
Ejemplo n.º 16
0
 private static extern bool SendMessage( IntPtr handle, int msg, int wparam, ref LV_ITEM lparam );
Ejemplo n.º 17
0
 internal static extern bool SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ref LV_ITEM lParam);
Ejemplo n.º 18
0
   internal static extern bool SendMessage(IntPtr hWnd, ListViewMessages msg,
 Int32 wParam, ref LV_ITEM lParam);
Ejemplo n.º 19
0
 private static extern bool SendMessage(IntPtr handle, int msg, int wparam, ref LV_ITEM lparam);
 static extern IntPtr SendMessage(IntPtr hWnd, WM Msg, IntPtr wParam, ref LV_ITEM lParam);
 public static extern bool SendMessage (
     IntPtr hWnd ,		// handle to destination window 
     Int32 msg ,			// message 
     Int32 wParam ,
     ref LV_ITEM lParam );// pointer to struct of LV_ITEM
Ejemplo n.º 22
0
 private static extern bool ReadProcessMemory(SafeProcessHandle hProcess, IntPtr lpBaseAddress, ref LV_ITEM lpBuffer, int nSize, ref int bytesRead);
Ejemplo n.º 23
0
 private static extern bool WriteProcessMemory(SafeProcessHandle hProcess, IntPtr lpBaseAddress, ref LV_ITEM lpBuffer, int nSize, ref int lpNumberOfBytesWritten);
        // Sets text to emptyh string if failed to find an item, or another error
        internal static int GetListViewSelectedItemInfo(IntPtr hwndList, out string text, out System.Windows.Rect bounds)
        {
            string listViewClassName = GetClassName(hwndList);
            //Debug.Assert(listViewClassName != "SysListView32");

            var selectedItemIndex = (int)SendMessage(hwndList, WM.LVM_GETNEXTITEM, new IntPtr(-1), new IntPtr((int)WM.LVNI_SELECTED));

            if (selectedItemIndex == -1)
            {
                text   = string.Empty;
                bounds = System.Windows.Rect.Empty;
                return(selectedItemIndex);
            }
            // Debug.Print(string.Format("#### PopupList SelectedItemIndex: {selectedItemIndex}");

            // First get text

            LV_ITEM item = new LV_ITEM();

            item.mask     = /*public const int LVIF_TEXT = */ 0x00000001;
            item.iSubItem = 0;
            IntPtr nativeBuffer = Marshal.AllocHGlobal(512 * 2);    // There might be a more elegant way to do this, sith a StringBuilder or something...

            for (int i = 0; i < 512; ++i)
            {
                Marshal.WriteInt16(nativeBuffer, i * 2, '\0');
            }

            try
            {
                item.pszText    = nativeBuffer;
                item.cchTextMax = 512;

                uint length = (uint)SendMessage(hwndList, WM.LVM_GETITEMTEXTW, new IntPtr(selectedItemIndex), ref item);
                if (length > 0)
                {
                    text = Marshal.PtrToStringUni(item.pszText, (int)length);
                }
                else
                {
                    text = string.Empty;
                }
            }
            finally
            {
                Marshal.FreeHGlobal(nativeBuffer);
            }

            // Now get bounds
            RECT rect = new RECT();

            rect.Left = LVIR_BOUNDS;
            uint ok = (uint)SendMessage(hwndList, WM.LVM_GETITEMRECT, new IntPtr(selectedItemIndex), ref rect);

            if (ok != 0)
            {
                bounds = new System.Windows.Rect(rect.Left, rect.Top, rect.Right - rect.Left + 1, rect.Bottom - rect.Top + 1);
            }
            else
            {
                bounds = System.Windows.Rect.Empty;
            }

            Debug.Print(string.Format("#### >>> {0} / {1} / ({2}, {3}, {4}, {5}) / {6}", selectedItemIndex, ok, rect.Left, rect.Top, rect.Right, rect.Bottom, bounds));

            return(selectedItemIndex);
        }
Ejemplo n.º 25
0
 public static extern bool SendMessage(
     IntPtr hWnd,                    // handle to destination window
     Int32 msg,                      // message
     Int32 wParam,
     ref LV_ITEM lParam);            // pointer to struct of LV_ITEM
Ejemplo n.º 26
0
 private static extern bool ReadProcessMemory(SafeProcessHandle hProcess, IntPtr lpBaseAddress, ref LV_ITEM lpBuffer, int nSize, ref int bytesRead);
Ejemplo n.º 27
0
 private static extern bool WriteProcessMemory(SafeProcessHandle hProcess, IntPtr lpBaseAddress, ref LV_ITEM lpBuffer, int nSize, ref int lpNumberOfBytesWritten);
Ejemplo n.º 28
0
 private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, ref LV_ITEM item_info);
Ejemplo n.º 29
0
 /// <summary>
 /// Set the indentation using the level of this item
 /// </summary>
 public void SetIndentation()
 {
     if(this.ListView == null) return;
       LV_ITEM lvi = new LV_ITEM();
       lvi.iItem = this.Index;
       lvi.iIndent = this.Level;
       lvi.mask = ListViewMessages.LVIF_INDENT;
       SendMessage(
     this.ListView.Handle,
     ListViewMessages.LVM_SETITEM,
     0,
     ref lvi);
 }