C# 模拟鼠标单击事件 FindWindow实例

        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        private void button2_Click(object sender, EventArgs e)
        {
            IntPtr formHandle = FindWindow(null, "窗口标题");//0x0175015f十六进制坐标,十进制转十六进制(x高位,y低位)(0175)x=373,(015F)y=351
            SendMessage(formHandle, 0x0201, 0, (int)0x0175015f); //发送WM_LBUTTONDOWN=0x0201 左键按下
            SendMessage(formHandle, 0x0202, 0, (int)0x0175015f); //发送WM_LBUTTONUP=0x0202  左键抬起   
        }
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s