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);
}
}
}
|
C# 在使用FindWindowEx的参数使用详解
最新推荐文章于 2023-04-12 11:38:10 发布