using System.Runtime.InteropServices;
// The signature for the callback method.
public delegate bool CallBack(IntPtr hwnd, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack callback, int param);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpString, int nMaxCount);
static void Main(string[] args)
{
// Request that the operating system enumerate all windows,
// and trigger your callback with the handle of each one.
EnumWindows(DisplayWindowInfo, 0);
Console.ReadLine();
}
// The method that will receive the callback. The second
// parameter is not used, but is needed to match the
// callback's signature.
public static bool DisplayWindowInfo(IntPtr hWnd, int lParam)
{
int chars = 100;
StringBuilder buf = new StringBuilder(chars);
if (GetWindowText(hWnd, buf, chars) != 0)
{
Console.WriteLine(buf);
}
return true;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const int CS_DROPSHADOW = 0x00020000;
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ClassStyle |= CS_DROPSHADOW;
return p;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Opacity = 1;
for (int i = 0; i < 100; i++)
{
this.Opacity -= 0.01;
Application.DoEvents();
}
}
bool b = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
b = true;
a.Clear();
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
b = false;
}
ArrayList a = new ArrayList();
Point[] p = new Point[50];
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (b == true)
{
a.Add(new Point(e.X, e.Y));
if (a.Count >= 50)
{
for (int i = 0; i < a.Count - 50; i++)
{
a.RemoveAt(i);
}
a.CopyTo(p);
}
else
{
a.CopyTo(p);
}
Bitmap bp = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Pen pn = new Pen(Brushes.Black);
pn.Width = 2;
pn.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLines(pn, p);
this.BackgroundImage = bp;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define polygon.
Point point1 = new Point(30, 50);
Point point2 = new Point(100, 25);
Point point3 = new Point(200, 5);
Point point4 = new Point(250, 50);
Point point5 = new Point(270, 100);
Point point6 = new Point(250, 250);
Point[] curvePoints = {point1, point2, point3, point4, point5, point6};
// Draw polygon to screen.
g.DrawPolygon(blackPen, curvePoints);
// Fill polygon
g.FillPolygon(Brushes.Red, curvePoints);
}