基本信息
源码名称:C# 模拟鼠标点击网页(实现淘宝快速抽奖功能)
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2016-01-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

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;
using System.Threading;

namespace E01_天猫201311
{
    public partial class Form1 : Form
    {

        #region 调用外部API

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); 

        #endregion

        public Form1()
        {
            InitializeComponent();
            LoadData();
        }

        /*                     Fields                    */

        /// <summary>
        /// 双11抽奖的lodingDiv层
        /// </summary>
        private string _loadingDiv;

        /// <summary>
        /// 【亲品牌】按钮的id
        /// <para>格式:AC_RandomKiss 天数;eq:AC_RandomKiss03,表示第三天</para>
        /// </summary>
        private string _ac_randomkiss;

        /// <summary>
        /// 【再来一次】按钮的id
        /// <para>格式:AC_PlayAgain 天数;eq:AC_PlayAgain3,表示第三天</para>
        /// </summary>
        private string _ac_playagain;

        /*                      Methods                 */
        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            int day = DateTime.Now.Date.Day;
            this._loadingDiv = "J_KhcLoading";
            this._ac_randomkiss = "AC_RandomKiss"   day.ToString("D2");
            this._ac_playagain = "AC_PlayAgain"   day;
            WbTmall.Url = new Uri(txtAddress.Text);
            WbTmall.ScriptErrorsSuppressed = true;
        }

        /// <summary>
        /// 【开始狂欢】按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            HtmlDocument html = WbTmall.Document;
           // J_KhcLoading div :页面进去时的loadingdiv
            HtmlElement loading_div = html.GetElementById(_loadingDiv);
            if (loading_div != null) {
                //1.隐藏loading Div
                string CloseLoadingDiv_Js = "javascript:document.getElementById('"   _loadingDiv   "').style.display='none';void(0)";
                WbTmall.Navigate(CloseLoadingDiv_Js);
            }
        }

        /// <summary>
        /// 亲品牌
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnChanggePa_Click(object sender, EventArgs e)
        {
            string js = "javascript:document.getElementById('" this._ac_randomkiss "').click()";
            WbTmall.Navigate(js);
        }

        /// <summary>
        /// 玩游戏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartGame_Click(object sender, EventArgs e)
        {
            #region 模拟鼠标
            int x = 100; // X coordinate of the click 
            int y = 100; // Y coordinate of the click 
            IntPtr handle = WbTmall.Handle;
            StringBuilder className = new StringBuilder(100);
            while (className.ToString() != "Internet Explorer_Server") // The class control for the browser 
            {
                handle = GetWindow(handle, 5); // Get a handle to the child window 
                GetClassName(handle, className, className.Capacity);
            }

            IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates 
            IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl) 
            const uint downCode = 0x201; // Left click down code 
            const uint upCode = 0x202; // Left click up code 

            #endregion


            //关闭【再来一次】
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o)
            {
                while (true)
                {
                    try
                    {
                        string GameStart_js = "javascript:document.getElementById('"   this._ac_playagain   "').click()";
                        //运行点击【再来一次】的按钮
                        WbTmall.Navigate(GameStart_js);
                    }
                    catch (Exception)
                    {

                    }
                    Thread.Sleep(20 * 1000);//20秒一次:3秒倒计时 游戏8秒 结果等待时间
                }
            }));
            ////偏移量,作用鼠标点击间隔和坐标
            //Random offset = new Random(20);

            //模拟鼠标单击,300毫秒一次,一直循环
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o)
            {
                while (true)
                {
                    Thread.Sleep(300);//鼠标点击的间隔
                    SendMessage(handle, downCode, wParam, lParam); // Mouse button down 
                    SendMessage(handle, upCode, wParam, lParam); // Mouse button up 
                }
            }));
        }


        private void btnLocalHref_Click(object sender, EventArgs e)
        {
           WbTmall.Url = new Uri("http://1111.tmall.com");
        }
    }
}