Ejemplo n.º 1
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);
                        }
                    }
                }
            }