Wie an die Farbtiefe herankommen?

wertzui

Mitglied
Da ich in meinem Programm die Auflösung und auch Farbtiefe ändere muss ich sie ja auch beim Beenden wieder zurücksetzen.
Wie ich an die Auflösung herankomme weiß ich mittlerweile, aber leider konnte mir keiner sagen, wie ich an die Farbtiefe herankomme.
Wäre echt toll, wenn hier jemand ne Antwort parat hätte.

cu wertzui
 
Diese beiden Möglichkeiten habe ich gefunden:
PHP:
Screen.GetBounds(this).Width
SystemInformation.PrimaryMonitorSize.Width()
Aber ich habe schon geguckt (Vs.net zeigt ja immer so eine Liste, mit den möglichen Ausdrücken an) und habe da nix gefunden.
 
Erstell ein leeres File und kopiere den Code hinein, dann siehst wies geht :)

Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace ScreenResolution

{
	public class Form1 : System.Windows.Forms.Form
	{

		public enum DMDO
		{
			DEFAULT = 0,
			D90 = 1,
			D180 = 2,
			D270 = 3
		}

		[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]

		struct DEVMODE
		{
			public const int DM_PELSWIDTH = 0x80000;
			public const int DM_PELSHEIGHT = 0x100000;
			private const int CCHDEVICENAME = 32;
			private const int CCHFORMNAME = 32;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)]
			public string dmDeviceName;
			public short dmSpecVersion;
			public short dmDriverVersion;
			public short dmSize;
			public short dmDriverExtra;
			public int dmFields;
			public int dmPositionX;
			public int dmPositionY;
			public DMDO dmDisplayOrientation;
			public int dmDisplayFixedOutput;
			public short dmColor;
			public short dmDuplex;
			public short dmYResolution;
			public short dmTTOption;
			public short dmCollate;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHFORMNAME)]
			public string dmFormName;
			public short dmLogPixels;
			public int dmBitsPerPel;
			public int dmPelsWidth;
			public int dmPelsHeight;
			public int dmDisplayFlags;
			public int dmDisplayFrequency;
			public int dmICMMethod;
			public int dmICMIntent;
			public int dmMediaType;
			public int dmDitherType;
			public int dmReserved1;
			public int dmReserved2;
			public int dmPanningWidth;
			public int dmPanningHeight;
		}

		//--------------------------------\
		[DllImport("user32.dll", CharSet=CharSet.Auto)]

		//static extern int ChangeDisplaySettings( DEVMODE lpDevMode,  int dwFlags);
		// should I use this line?

		static extern int ChangeDisplaySettings( [In] ref DEVMODE lpDevMode,  int dwFlags);

		/// <summary>
		/// Required designer variable.
		/// </summary>

		private System.ComponentModel.Container components = null;

		public Form1()

		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>

		private void InitializeComponent()

		{
			this.components = new System.ComponentModel.Container();
			this.Size = new System.Drawing.Size(300,300);
			this.Text = "Form1";
		}

		#endregion

		static void Main()

		{
			Form1 r = new Form1();
			r.ChangeRes();
			Application.Run(new Form1());
		}

		void ChangeRes()

		{
			Form1 t = new Form1();
			long RetVal=0;
			DEVMODE dm = new DEVMODE();
			dm.dmSize= (short)Marshal.SizeOf(typeof(DEVMODE));
			dm.dmPelsWidth = 1024;
			dm.dmPelsHeight= 768;
			dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT;
			RetVal = ChangeDisplaySettings(ref dm, 0);

		}
	}
}
 
Sorry, aber ich noch ein Neuling in C#, bitte entschuldige, wenn ich es falsch verstehe.
Aber so vom lesen des Codes sieht es einfach so aus, als würde man die Auflösung öndern.
Ist es nicht einfach möglich, so, wie bei width und heigh die Farbtiefe herauszubekommen?
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück