using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 模拟三方程序窗口的按钮
{
public partial class Form1 : Form
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
const uint BM_CLICK = 0xF5;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr ParenthWnd = new IntPtr(0);
ParenthWnd = FindWindow(null, "aaa");
IntPtr btnPtr = FindWindowEx(ParenthWnd, IntPtr.Zero, null, "开");
SendMessage(btnPtr, BM_CLICK, 0, 0);
}
private void button2_Click(object sender, EventArgs e)
{
IntPtr ParenthWnd = new IntPtr(0);
ParenthWnd = FindWindow(null, "aaa");
IntPtr btnPtr = FindWindowEx(ParenthWnd, IntPtr.Zero, null, "关");
PostMessage(btnPtr, BM_CLICK, 0, 0);
}
}
}