摘要:[C#],[WinFrom]C# 關於API函數PostMessage(),SendMessage()的滑鼠單擊坐標參數lParam
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.MouseClick+=new MouseEventHandler(Form1_MouseClick);
}
void Form1_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show("X :" + e.X.ToString() + "Y :" + e.Y.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
int x=58;
int y=32;
//寫法1
PostMessage(this.Handle, WM_LBUTTONDOWN, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
//SendMessage(this.Handle, WM_LBUTTONDOWN, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
PostMessage(this.Handle, WM_LBUTTONUP, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
//SendMessage(this.Handle, WM_LBUTTONUP, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
// 簡化下其實就是Y坐標左移16位,然後再加上X坐標
PostMessage(this.Handle, WM_LBUTTONDOWN, 0, x + (y<<16));
//SendMessage(this.Handle, WM_LBUTTONDOWN, 0, x + (y<<16));
PostMessage(this.Handle, WM_LBUTTONUP, 0, x+(y<<16));
//SendMessage(this.Handle, WM_LBUTTONUP, 0, x + (y<<16));
}
uint WM_LBUTTONDOWN = 0x201;
uint WM_LBUTTONUP = 0x202;
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
}
}
我只是個小小的入門者