Få alle moduler som processen bruger: (den første må være stien til selve programmet, som vi skal hente ikonet ud fra)
//Get all modules inside the process Process[] ObjModulesList = Process.GetProcessesByName("devenv");
// Populate the module collection. ProcessModuleCollection ObjModules = ObjModulesList[0].Modules;
// Iterate through the module collection. foreach (ProcessModule objModule in ObjModules) { //Get valid module path strModulePath =GetValidString(objModule.FileName.ToString()); //If the module exists if (File.Exists(objModule.FileName.ToString())) { //Get version string strFileVersion = GetValidString(objModule. FileVersionInfo.FileVersion.ToString()); //Get File size string strFileSize = GetValidString (objModule.ModuleMemorySize.ToString()); //Get Modification date FileInfo objFileInfo = new FileInfo(objModule.FileName.ToString()); string strFileModificationDate = GetValidString (objFileInfo.LastWriteTime.ToShortDateString()); //Get File description string strFileDescription = GetValidString (objModule.FileVersionInfo. FileDescription.ToString()); //Get Product Name string strProductName = GetValidString (objModule.FileVersionInfo.ProductName.ToString()); //Get Product Version string strProductVersion = GetValidString (objModule.FileVersionInfo.ProductVersion.ToString()); } }
Hente ikon fra fil:
GetFileIcon is used to obtain icons for files, and uses three parameters:
name - Complete file and path names to read. size - Whether to obtain 16x16 or 32x32 pixels, uses the IconSize enumeration. linkOverlay - Specify whether the returned icon should include the small link overlay. It is a static member function since it doesn't need to store any state, and is intended primarily as an added layer of abstraction. If I needed to obtain a file's icon in the future (and not store it in an ImageList etc.) then I could do so using this class. Once I had a type that wrapped up the necessary API functions to obtain file icons I would then build another type to manage large and small ImageLists that would enable me to make a single call to add an icon, and if it was already added, return the index that the icon was in the ImageList.
if (true == linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;
/* Check the size specified for return. */ if (IconSize.Small == size) { flags += Shell32.SHGFI_SMALLICON ; // include the small icon flag } else { flags += Shell32.SHGFI_LARGEICON ; // include the large icon flag }
// Copy (clone) the returned icon to a new object, thus allowing us // to call DestroyIcon immediately System.Drawing.Icon icon = (System.Drawing.Icon) System.Drawing.Icon.FromHandle(shfi.hIcon).Clone(); User32.DestroyIcon( shfi.hIcon ); // Cleanup return icon; }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices;
namespace WindowsApplication1 { public partial class Form1 : Form { [DllImport("Shell32.dll")] public static extern IntPtr SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags );
[StructLayout(LayoutKind.Sequential)] public struct SHFILEINFO { public IntPtr hIcon; public IntPtr iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public string szTypeName; }; [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto)] extern static bool DestroyIcon(IntPtr handle);
public const uint SHGFI_ICON = 0x100; public const uint SHGFI_LARGEICON = 0x0; // 'Large icon public const uint SHGFI_SMALLICON = 0x1; // 'Small icon public const uint SHGFI_USEFILEATTRIBUTES = 0x10; public const uint SHGFI_LINKOVERLAY = 0x8000; public const uint FILE_ATTRIBUTE_NORMAL = 0x80;
øh, okay. Mange tak! Meget detaljeret svar ;) Så skal jeg bare finde ud af hvordan man ændre position og størrelse på en anden proces's vindue, men det laver jeg lige et andet spørgsmål til...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.