[DllImport("user32.dll")]
private static extern IntPtr GetProcessWindowStation();
delegate bool EnumDesktopProc([MarshalAs(UnmanagedType.LPTStr)] string desktopName, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern bool EnumDesktops(IntPtr windowStation, EnumDesktopProc callback, int lParam);
private StringBuilder returnName = new StringBuilder();
private void button5_Click(object sender, EventArgs e)
{
returnName.Length = 0;
EnumDesktopProc pro = enumDesktop;
if (EnumDesktops(GetProcessWindowStation(), pro, 0))
{
MessageBox.Show(returnName.ToString());
}
}
private bool enumDesktop(string desktopName, int lParam)
{
returnName.Append(String.Format("DesktopName: {0:},\t lParam: {1}\r\n", desktopName, lParam));
return true;
}