当前位置:首页 » 《随便一记》 » 正文

c# 模拟第三方程序按钮的单击

17 人参与  2022年12月21日 08:17  分类 : 《随便一记》  评论

点击全文阅读


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);

            
        }
    }
}


点击全文阅读


本文链接:http://zhangshiyu.com/post/50086.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1