C# 在使用FindWindowEx的参数使用详解

来源:互联网 发布:东方财富mac 编辑:程序博客网 时间:2024/06/13 22:04
C# code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 WindowsApplication128
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern int GetClassName(IntPtr Handle, [Out] StringBuilder ClassName, int MaxCount);
 
        [DllImport("user32.dll")]
        static extern int SendMessage(IntPtr Handle, int WParam, int LParam);
 
        [DllImport("user32.dll")]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
 
        Button B = new Button();
 
        public Form1()
        {
            InitializeComponent();
 
            B.Parent = this;
            B.Click += new EventHandler(B_Click);
 
            this.Shown += new EventHandler(Form1_Shown);
        }
 
 
        private void B_Click(object sender, EventArgs e)
        {
            MessageBox.Show("!!!");
        }
 
        void Form1_Shown(object sender, EventArgs e)
        {
            int WM_CLICK = 0x00F5;
 
            StringBuilder ClassName = new StringBuilder(256);
            GetClassName(B.Handle, ClassName, ClassName.Capacity);
 
            IntPtr Handle = FindWindowEx(this.Handle, IntPtr.Zero, ClassName.ToString(), String.Empty);
            SendMessage(Handle, WM_CLICK, 0);
        }
    }
}

0 0
原创粉丝点击