|
■No87984 (Ante さん) に返信
> 環境:Windows10
> C#で、エクスプローラー->表示->レイアウト->中アイコン、に設定したいです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var sizes = new Dictionary<uint, string>
{
{256u, "特大"},
{96u, "大"},
{48u, "中"},
{16u, "小"},
};
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.DataSource = sizes.ToArray();
comboBox1.ValueMember = "Key";
comboBox1.DisplayMember = "Value";
comboBox1.SelectedIndex = 2;
}
private void button1_Click(object sender, EventArgs e)
{
foreach (var w in GetExplorer())
{
if(Confirm(w.Path, w.LocationName))
{
var sfv = w.Document;
sfv.CurrentViewMode = 1u;
sfv.IconSize = comboBox1.SelectedValue;
Marshal.ReleaseComObject(sfv);
}
}
}
private bool Confirm(string path, string location)
{
return DialogResult.Yes == MessageBox.Show(
this,
"このフォルダのアイコンサイズを変更しますか?\r\n" + location + "\r\n" + path,
"確認",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
}
private IEnumerable<dynamic> GetExplorer()
{
dynamic exp = Activator.CreateInstance(Type.GetTypeFromCLSID(Guid.Parse("{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")));
System.Runtime.InteropServices.ComTypes.IEnumVARIANT f = exp._NewEnum;
object[] varRes = new object[1];
while (f.Next(1, varRes, IntPtr.Zero) == 0)
{
dynamic w = varRes.FirstOrDefault();
if (w != null)
{
if (Path.GetFileName(w.FullName).ToLowerInvariant() == "explorer.exe")
{
yield return w;
}
if (Marshal.IsComObject(w))
{
Marshal.ReleaseComObject(w);
}
}
}
if(Marshal.IsComObject(f))
{
Marshal.ReleaseComObject(f);
}
Marshal.ReleaseComObject(exp);
}
}
|