سلام دوستان میتونید این کد رو توضیح بدین که به چه طریق کار میکنه؟
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr parentHwnd, IntPtr childAfterHwnd, string className, string windowTitle);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string LpClassName, string LpWindowName);
[DllImport("user32.dll")]
private static extern bool GetClientRect(IntPtr hwnd, out Rectangle LpRect);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, out Rectangle LpRect);
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int nWidh, int nHeight, bool bRepaint);
public Form1()
{
InitializeComponent();
}
private Int32 xPos, yPos, H, W, maxX;
private IntPtr trayBarHandle;
private int deltaX = 0;
private void button1_Click(object sender, EventArgs e)
{
IntPtr hwnd = FindWindow("Shell_TrayWnd", null);
if (hwnd != IntPtr.Zero)
{
trayBarHandle = FindWindowEx(hwnd, IntPtr.Zero, "TrayNotifyWnd", null);
Rectangle rect;
GetWindowRect(trayBarHandle, out rect);
xPos = rect.X - 2;
yPos = 0;
H = 40;
W = 169;
GetClientRect(hwnd, out rect);
maxX = rect.Width - rect.X - 1 - W;
timer1.Start();
deltaX = -1;
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (trayBarHandle != IntPtr.Zero)
{
if (xPos == 0) deltaX = -deltaX;
if (xPos == maxX) deltaX = -deltaX;
xPos += deltaX;
MoveWindow(trayBarHandle, xPos, yPos, W, H, true);
this.Text = string.Format("X={0} ,Y={1},W={2},H={3}", xPos, yPos, W, H);
}
}
}
}