حرکت TrayBar به چپ و راست در TaskBar؟ - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

حرکت TrayBar به چپ و راست در TaskBar؟

0 امتیاز

سلام دوستان میتونید این کد رو توضیح بدین که به چه طریق کار میکنه؟

 

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);
            }
        }

       
    }
}


 

سوال شده اردیبهشت 2, 1393  بوسیله ی daniyaltjm (امتیاز 840)   47 88 103
ویرایش شده اردیبهشت 2, 1393 بوسیله ی daniyaltjm

پاسخ شما

اسم شما برای نمایش (دلخواه):
از ایمیل شما فقط برای ارسال اطلاعات بالا استفاده میشود.
تایید نامه ضد اسپم:

برای جلوگیری از این تایید در آینده, لطفا وارد شده یا ثبت نام کنید.
...