zoukankan      html  css  js  c++  java
  • 获取可用驱动器(本地磁盘,光驱,U盘)列表

    GetLogicalDrives()可以实现。具体代码:

    [StructLayout(LayoutKind.Sequential)]
    		public struct SHFILEINFO 
    		{
    			public IntPtr hIcon; 
    			public int iIcon;
    			public int dwAttributes; 
    			public string szDisplayName; 
    			public string szTypeName; 
    		}
    
    		[DllImport("shell32")]
    		private static extern int SHGetFileInfo(string pszPath,int dwFileAttributes,ref SHFILEINFO psfi,int cbFileInfo,int uFlags);
    		const int SHGFI_ICON = 0x0100;
    		const int SHGFI_LARGEICON = 0x0000; 
    
    		static string[] drives;
    		ImageList img=new ImageList();
    
    		private void Form1_Load(object sender, System.EventArgs e)
    		{
    			this.listView1.LargeImageList=img;
    			this.listView1.SmallImageList=img;
    			this.listView1.StateImageList=img;
    
    			drives=Environment.GetLogicalDrives();
    			for(int i=0;i<drives.Length;i++)
    			{
    				string str_temp=drives[i];
    				this.listView1.Items.Add(str_temp);
    				this.listView1.Items[i].ImageIndex=i;
    			}
    			for(int i=0;i<drives.Length;i++)
    			{
    				SHFILEINFO FileInfo=new SHFILEINFO();
    				SHGetFileInfo(drives[i],0,ref FileInfo,Marshal.SizeOf(FileInfo),SHGFI_ICON | SHGFI_LARGEICON);
    
    				Icon myIcon;
    				myIcon=Icon.FromHandle(FileInfo.hIcon);
    				img.Images.Add(myIcon); 
    			}
    		}


  • 相关阅读:
    BZOJ1000 A+B Problem
    网络最大流
    树形结构
    BZOJ2521 最小生成树 最小割
    HDU5266 LCA 树链剖分LCA 线段树
    BZOJ3991 寻宝游戏 LCA 虚树 SET
    深度优先搜索DFS
    斯特林数
    Noip2017 普及 T3 Chess
    键盘自动机
  • 原文地址:https://www.cnblogs.com/fornet/p/2976176.html
Copyright © 2011-2022 走看看