日期:2014-05-17  浏览次数:21197 次

关于使用SendMessage PostMessage 实现模拟鼠标的一些问题
想实现一个通过PostMessage 或者 SendMessage在后台对一个DX游戏的窗口进行鼠标的模拟。
以下为代码:

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 WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        static extern bool PostMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam); 
        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);

        public static uint WM_LBUTTONDOWN = 0x201; 
        //按下鼠标左键
        public static uint WM_LBUTTONUP = 0x202;
        //释放鼠标左键

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        public static IntPtr gethWnd() 
        {
            String s = "EVE - xxxxx";
            IntPtr hWnd =  FindWindow("triuiScreen", s);
            if (hWnd == IntPtr.Zero)
        {
                MessageBox.Show("error");
        return IntPtr.Zero;
        }else
            {
                return hWnd;
            }
        }

        IntPtr hWnds = gethWnd();

     &