Screen vom Desktop

zioProduct

Erfahrenes Mitglied
Huhu,

Nur so als erstes ne Frage in die Runde.
Ich hab ein Programm, das einen Printscreen vom Desktop macht, doch macht er mir nur ein schwarzes Image -.-*

Weiss einer gerade an was das liegen könnte, ansonsten Poste ich den Code, aber ich vermute dass es wieder so ein DeppenFehler von mir ist, der bei euch gleich *Klick-Anfängerfehler* im Kopf macht :D

Thx für die Hilfe

mfg
ziop
 
Argh mag doch nicht alles umschreiben nur weil es nur schwarz wird :(
Dann poste ich halt meinen Code :D
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace DesktopScreenshot_Realisieren
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		internal System.Windows.Forms.PictureBox pictureBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;



		private const int SRCCOPY = 0xCC020;

		[DllImport("gdi32.dll")]
		private  static extern int  BitBlt(IntPtr  hDestDC,int  x,int  y,int  nWidth,
			int  nHeight,IntPtr  hSrcDC,int  xSrc,int  ySrc,int  dwRop);

		[DllImport("user32.dll")]
		private  static extern IntPtr  GetDC(int  hwnd);

		[DllImport("user32.dll")]
		private  static extern int  ReleaseDC(int  hwnd,IntPtr hdc);


		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		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.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(16, 16);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(168, 40);
			this.button1.TabIndex = 0;
			this.button1.Text = "Speichern";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(16, 56);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(168, 40);
			this.button2.TabIndex = 1;
			this.button2.Text = "Show";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(16, 400);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(168, 40);
			this.button3.TabIndex = 2;
			this.button3.Text = "Quit";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// pictureBox1
			// 
			this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.pictureBox1.Location = new System.Drawing.Point(200, 16);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(464, 424);
			this.pictureBox1.TabIndex = 3;
			this.pictureBox1.TabStop = false;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(688, 454);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			Graphics g1;
			IntPtr dc1,dc2;
			Image img;

			img = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
			g1 = Graphics.FromImage(img);

			dc1=GetDC(0);
			dc2=g1.GetHdc();

			BitBlt(dc2,0,0,Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height,dc1,0,0,SRCCOPY);

			ReleaseDC(0,dc1);
			g1.ReleaseHdc(dc1);

			img.Save("c:\\Form1.png",System.Drawing.Imaging.ImageFormat.Png);
			MessageBox.Show("Desktop-Screenshot gespeichert","info");

		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			Graphics g1;
			IntPtr dc1, dc2;
      
      
			this.Visible = false;
			Image img = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
			g1 = Graphics.FromImage(img);

			dc1 = GetDC(0);
			dc2 = g1.GetHdc();
			BitBlt(dc2, 0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, dc1, 0, 0, SRCCOPY);
			ReleaseDC(0, dc1);
			g1.ReleaseHdc(dc1);
			pictureBox1.Image = img;
			this.Visible = true;
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			this.Close();

		}
	}
}

Hmm das aber gross :( Naja, ihr wisst Bestimmt wo der Fehler liegen muss, nicht das ihr alles durchlesen müsstet :(

mfg
ziop
 

Neue Beiträge

Zurück