当前位置:网站首页>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
边栏推荐
- HDU 6778 Car (分组枚举-->状压 dp)
- 十六制计数器和流水灯
- L2-031 go deep into the tiger's den (25 points)
- Web vulnerability manual detection and analysis
- 2019.11.20 training summary
- std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
- IIS服务器相关错误
- Nacos environmental isolation
- Analysis of liferayportal jsonws deserialization vulnerability (cve-2020-7961)
- HDU 6778 car (group enumeration -- > shape pressure DP)
猜你喜欢
随机推荐
Codeforces Round #641 Div2
C#使用WinExec调用exe程序
2019.11.13 training summary
Codeforces - 1151b thinking
Codeforces Round #645 (Div. 2)
Time varying and non time varying
Nacos registry cluster
EDA and VHDL question bank
Summary after the 2009 ICPC Shanghai regional competition
逆向思维-小故事
EDA与VHDL题库
Voir le classement des blogs pour csdn
Reverse thinking - short story
Use of Azkaban in task scheduler
《CLR via C#》读书笔记-加载与AppDomain
MySQL innodb每行数据长度的限制
Analyze in detail the PBOT mining virus family behavior and the principle of exploited vulnerabilities, and provide detailed protection suggestions for the blue army
1021 Deepest Root (25 分)
Recurrence of vulnerability analysis for Cisco ASA, FTD and hyperflex HX
URAL1517 Freedom of Choice 【后缀数组:最长公共连续子串】







