当前位置:网站首页>Call another interface button through win32API
Call another interface button through win32API
2022-06-29 10:26:00 【zlbcdn】
Functional specifications
There are two independent teams created by two teams winform Interface , One of the teams, without knowing the source code , Operating the interface of another team button.
Exhibition
The main interface is as follows : 
The sub interface is as follows : 
The sub interface has a button ( test ), Click this button , eject “ Prompt content of word form ” Prompt box .
When clicking on the parent form (Form1) Button on (button1) when , You can manipulate subforms ( The form of the subform ) The button ( test ), And a prompt box appears
Code
Subform code :
namespace TestForm
{
public partial class MyTestForm : Form
{
public MyTestForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(" Prompt contents of subform !");
}
}
}The code of the parent form
public partial class Form1 : Form
{
[DllImport("user32.dll", EntryPoint = "FindWindowA", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
private static extern void SetForegroundWindow(IntPtr hwnd);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//Process.Start("TestForm.exe");
const int WM_CLICK = 0x00F5;// Mouse click message , Values of various messages , You can refer to MSDN
string lpszName_TestChild = " The form of the subform ";// The title of the subform (Text Property value )
string lpszName_btnYes = " test ";// On subform button The title of the (Text Property value )
IntPtr hwndTestChild = new IntPtr();// Handle to the subform
IntPtr hwndbtnYes = new IntPtr();// On subform button The handle of
hwndTestChild = FindWindow(null, lpszName_TestChild);// Get the handle of the subform
hwndbtnYes = FindWindowEx(hwndTestChild, 0, null, lpszName_btnYes);// Get on the subform button The handle of
if (hwndTestChild != IntPtr.Zero)
{
SendMessage(hwndbtnYes, WM_CLICK, 0, 0);// On the subform button Send a mouse click message ,
}
else
{
MessageBox.Show(" Not found !");
}
}
catch (System.Exception ex)
{
throw ex;
}
}
}Other instructions
1、 Method description :
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
here EntryPoint = “FindWindow” or EntryPoint = “FindWindowA” All possible .
My environment VS2010,Win7 The flagship . Before FindWindow The return result of is always 0. But I don't know why .
2、 About session0 Related issues :
1、 About the part WIN32 API stay WIN 7 Problem of lower failure
2、Session 0 Isolation
3、FindWindow Always return 0
3、 Reference material
边栏推荐
- Time varying and non time varying
- Application of Pgp in encryption technology
- Is it safe to open a stock account with the QR code given by the manager of a securities firm? I want to open an account
- Oracle重置序列发生器(非重建)
- EDA与VHDL题库
- Codeforces Round #657 Div. 2
- Codeforces Round #641 Div2
- mysql中的if [not] exists
- Function pointer, function pointer array, calculator + transfer table, etc
- L2-3 这是二叉搜索树吗?-题解超精彩哦
猜你喜欢

Installing and configuring wmware esxi 6.5.0 in VMware Workstation

Nacos registry cluster

Recyclerview sticky (suspended) head

Recurrence of vulnerability analysis for Cisco ASA, FTD and hyperflex HX

Seaweedfs security configuration

Codeforces Round #645 (Div. 2)

View CSDN blog rankings

This open source project is super wow, and handwritten photos are generated Online

HDU 6778 Car (分组枚举-->状压 dp)

Using rancher to build kubernetes cluster
随机推荐
DevExpress的双击获取单元格数据
解决zxing的QR码包含中文时乱码的问题
蛇形填数
Rikka with cake (segment tree + segment tree)
任务调度器之Azkaban的使用
Download control 1 of custom control (downloadview1)
Codeforces Round #657 Div. 2
Codeforces Round #659 (Div. 2)
Simulation problem of two stacks
山科 的C语言2018练习题(电信)
Serpentine filling number
L2-031 go deep into the tiger's den (25 points)
L2-025 divide and rule (25 points)
MySQL中update一条record的过程
在VMware workstation中安装WMware ESXi 6.5.0并进行配置
Text of the basic component of the shutter
Codeforces Round #652 (Div. 2)
September 17, 2020 gateway business process has two tasks: referer certification and non commodity Templating
信号作品:时变和时不变
MySQL innodb每行数据长度的限制