C# デスクトップアイコンの数
Posted: 2010年11月25日(木) 22:42
こんばんは。 デスクトップアイコンの数を取得するコードを書いたのですが、(ほとんどコピー)
普通はこれを実行するとデスクトップアイコンの数が表示されます。
しかし、一度壁紙を変えると、explorer.exeを再起動するまで、何度やっても「0」としか表示されなくなります。
これは何が原因でどうすれば直るのでしょうか?
僕にはまったく分からないので困っています。
環境はVisual C# 2010です。
どなたか教えてくださる方いらっしゃいますでしょうか?
よろしくお願いします。
コードです↓
(編集):コードタグ入力機能で言語名を入力しました。
普通はこれを実行するとデスクトップアイコンの数が表示されます。
しかし、一度壁紙を変えると、explorer.exeを再起動するまで、何度やっても「0」としか表示されなくなります。
これは何が原因でどうすれば直るのでしょうか?
僕にはまったく分からないので困っています。
環境はVisual C# 2010です。
どなたか教えてくださる方いらっしゃいますでしょうか?
よろしくお願いします。
コードです↓
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName);
[DllImport("user32", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
public const int LVM_GETITEMCOUNT = 0x1004;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hWnd;
hWnd = FindWindow("Progman", "Program Manager");
hWnd = FindWindowEx(hWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
hWnd = FindWindowEx(hWnd, IntPtr.Zero, "SysListView32", null);
int nItemCount = SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);
label1.Text = nItemCount.ToString();
}
}
}