Laden...

Ring - Fenster-Animation

Erstellt von Programmierhans vor 18 Jahren Letzter Beitrag vor 18 Jahren 4.608 Views
Programmierhans Themenstarter:in
4.221 Beiträge seit 2005
vor 18 Jahren
Ring - Fenster-Animation

Den folgenden Code könnte man auch in die eigenen Apps einbauen um z.B: Kunden darauf aufmerksam zu machen, dass noch eine Eingabe von ihm erwartet wird.

Was der Code genau macht findet selber raus🙂




using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;


namespace WindowsApplication19
{
	/// <summary>
	/// Class for getting images of the desktop.
	/// </summary>
	/// <threadsafety static="false" instance="false"/>
	/// <note type="caution">This class is not thread safe.</note>
	/// <remarks>This class has been scaled back to the essentials for capturing a segment of
	/// the desktop in order to keep Cropper as small as possible.</remarks>
	internal class Desktop
	{
		private const int SRCCOPY = 0x00CC0020;

		#region Dll Imports

		[DllImport("user32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=false)]
		static extern IntPtr GetDesktopWindow();

		[DllImport("user32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=false)]
		private static extern IntPtr GetWindowDC(IntPtr hwnd);

		[DllImport("user32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=false)]
		private static extern int ReleaseDC(IntPtr hwnd, IntPtr dc);
    
		[DllImport("gdi32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=false)]
		private static extern UInt64 BitBlt
			(IntPtr hDestDC, int x, int y, int nWidth, int nHeight,
			IntPtr hSrcDC, int xSrc, int ySrc, System.Int32 dwRop);

		#endregion

		private Desktop(){}

		/// <summary>
		/// Gets a segment of the desktop as an image.
		/// </summary>
		/// <param name="x">Starting point X coordinate.</param>
		/// <param name="y">Starting point Y coordinate.</param>
		/// <param name="width">The width of the area to capture.</param>
		/// <param name="height">The height of the area to capture.</param>
		/// <returns>A <see cref="System.Drawing.Image"/> containg an image of the desktop
		/// at the specified coordinates</returns>
		internal static Image GetBitmap(int x, int y, int width, int height)
		{
			Graphics desktopGraphics;
			Image desktopImage;
			Graphics drawGraphics;
			Image drawImage;
			Rectangle virtualScreen = SystemInformation.VirtualScreen;

			//Create the image and graphics to capture the desktop.
			//
			using(desktopImage = new Bitmap(virtualScreen.Width, virtualScreen.Height))
			{
				using(desktopGraphics = Graphics.FromImage(desktopImage))
				{
					//Pointers for window handles
					//
					IntPtr ptrDesktop = desktopGraphics.GetHdc();
					IntPtr ptrDesktopWindow = GetDesktopWindow();
					IntPtr ptrWindowDC = GetWindowDC(ptrDesktopWindow);

					//Grap the entire virtual desktop
					//
					BitBlt(ptrDesktop,
						0,
						0,
						virtualScreen.Width,
						virtualScreen.Height,
						ptrWindowDC,
						virtualScreen.X,
						virtualScreen.Y,
						SRCCOPY);

					//Release and dispose the graphics object so we have an image to work with.
					//
					ReleaseDC(ptrDesktopWindow, ptrWindowDC);
					desktopGraphics.ReleaseHdc(ptrDesktop);
                    
					//Set pointers to zero.
					//
					ptrDesktop = IntPtr.Zero;
					ptrDesktopWindow = IntPtr.Zero;
					ptrWindowDC = IntPtr.Zero;
				}

				//Create a new image and graphics object the size we want so we can 'crop' it out of the desktop.
				//
				drawImage = new Bitmap(width, height);
				using(drawGraphics = Graphics.FromImage(drawImage))
				{
					//Draw the area of the desktop we want into the new image.
					//
					drawGraphics.DrawImage(
						desktopImage,
						new Rectangle(new Point(0,0), new Size(width, height)),
						new Rectangle((virtualScreen.X - x) *-1, (virtualScreen.Y - y) *-1, width, height),
						GraphicsUnit.Pixel);

				}
			}

			//Return a referance to our image.  
			//Don't forget to dispose it in the client code when finished.
			//You will have memory leaks if not.
			//
			return drawImage;
		}
	}
}




using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication19
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private Rectangle _RectScreen=Screen.PrimaryScreen.WorkingArea;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.Size=new Size(this._RectScreen.Width+100,this._RectScreen.Height+100);
			this.BackgroundImage =Desktop.GetBitmap(0,0,1280,1024);
			
		}

		/// <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.components = new System.ComponentModel.Container();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Interval = 5000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Name = "Form1";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "Form1";

		}
		#endregion

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

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			this.Ring();
		}

		private void Ring()
		{
			this.BackgroundImage=Desktop.GetBitmap(0,0,1280,1024);
			this.Show();

			for (int i=0;i<10;i++)
			{
				
				this.Location=new Point(this.Location.X-20,this.Location.Y);
				Application.DoEvents();
				this.Location=new Point(this.Location.X+40,this.Location.Y);
				Application.DoEvents();
				this.Location=new Point(this.Location.X-20,this.Location.Y);
				Application.DoEvents();
				
			}
			this.Hide();
			this.BackgroundImage.Dispose();
			this.BackgroundImage=null;
		}
	}
}



😉

Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...

X
2.051 Beiträge seit 2004
vor 18 Jahren

wie kommt man bloß auf so eine idee?! 8o

aber ist lustig! 😁

Programmierhans Themenstarter:in
4.221 Beiträge seit 2005
vor 18 Jahren

Ist halt für alle die schon alles haben 🙂 und Zeit für einen Spass muss man sich nehmen.

Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...

S
709 Beiträge seit 2005
vor 18 Jahren

Cool. Den Code werd ich verwenden um meinem Freund mal einen Schreck einzujagen 😁

Gruß,
SimonKnight6600

I
1.739 Beiträge seit 2005
vor 18 Jahren

"wie kommt man bloß auf so eine idee?! "

Eindeutig ein Fall von zuviel Freizeit. 😉