findwindow\sendmessage向第三方软件发送消息演示
这里仅仅是以putty作为演示消息发送机制和控件搜索机制
程序一:代填IP和端口,并建立远程连接
#include"stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
HWND FindTextBox(HWND hWnd,DWORD select_edit=1)
{
HWND hEdit = NULL;
hEdit = FindWindowExW(hWnd, hEdit, L"Edit", 0);
switch (select_edit)
{
case 1:
return hEdit;
case 2:
hEdit=GetNextWindow(hEdit,2);
hEdit=GetNextWindow(hEdit,2);
return hEdit;
default:
break;
}
/*遍历子窗体
if (hEdit != NULL) return hEdit;
HWND hChild = NULL;
while(true) {
hChild = FindWindowExW(hWnd, hChild, 0, 0);
if (hChild == NULL)
break;
hEdit = FindTextBox(hChild);
if (hEdit != NULL)
break;
}
*/
return hEdit;
}
HWND FindButton(HWND hWnd,DWORD select_button=0){
HWND hButton=NULL;
hButton=FindWindowExW(hWnd,hButton,L"Button",0);
return hButton;
}
int _tmain (int argc, LPTSTR argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess("C:\\Program Files\\sunsi\\third\\putty\\putty.exe", // No module name (use command line)
NULL, // Command line //简单的方法是调用putty传递参数,把NULL改为"-ssh -l root -pw 123456 -P 22 1.1.1.1"即可
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}
// Wait until child process exits.
// WaitForSingleObject( pi.hProcess, INFINITE ); //之前忘记注释这一行,导致失败,丢大发了。。。
Sleep(2000);//等待窗体打开
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
puts("-------------------------------");
HWND hWnd=FindWindowW(0,L"PuTTY Configuration");
if(hWnd==0){
puts("search failed!");
system("pause");
return 1;
}
HWND hEditIp=NULL;
HWND hEditPort=NULL;
HWND hButton=NULL;
hEditIp=FindTextBox(hWnd,1);
hEditPort=FindTextBox(hWnd,2);
hButton=FindButton(hWnd);
if(hEditIp!=NULL&&hEditPort!=NULL){
SendMessageW(hEditIp,WM_SETTEXT,0,(LPARAM)L"172.18.4.202");
SendMessageW(hEditPort,WM_SETTEXT,0,(LPARAM)L"422");
}else{
puts("search edit frame failed!");
system("pause");
return 1;
}
if(hButton!=NULL){
SendMessageW(hButton,WM_LBUTTONDOWN,0,0);
SendMessageW(hButton,WM_LBUTTONUP,0,0);
system("pause");
}else{
puts("search button failed!");
system("pause");
return 1;
}
//system("pause");
return 0;
}
程序二:获取文本框内容
#include "stdafx.h"
#include "windows.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HWND hText;
HWND hWnd=::FindWindowW(NULL,L"PuTTY Configuration");
char ch[100];//用于接收获取到的文本框的内容
if(hWnd==NULL)
cout<<"error"<<endl;
else{
hText=GetWindow(hWnd,GW_CHILD); //获取子窗口句柄
hText=GetWindow(hText,GW_HWNDFIRST);//该句可不加
while(hText)
{
//cout<<GetWindowLong(hText,GWL_STYLE)<<endl; //获取文本框的样式,为下面判断做准备,可通过spy++查看,但spy出来的是十六进制,需要转换。
if(1342242944==GetWindowLong(hText,GWL_STYLE)){
SendMessage(hText,WM_GETTEXT,100,(LPARAM)ch);//获取文本内容,存到ch中
cout<<ch<<endl;
}
hText=GetWindow(hText,GW_HWNDNEXT);
}
}
system("pause");
}
findwindow\sendmessage向第三方软件发送消息演示的更多相关文章
- Spring Boot+Socket实现与html页面的长连接,客户端给服务器端发消息,服务器给客户端轮询发送消息,附案例源码
功能介绍 客户端给所有在线用户发送消息 客户端给指定在线用户发送消息 服务器给客户端发送消息(轮询方式) 项目搭建 项目结构图 pom.xml <?xml version="1.0&q ...
- Delphi实现获取句柄并发送消息的方法(FindWindow、FindWindowEx、EnumChildWindows、SendMessage)
Delphi实现获取句柄并发送消息的方法 本文以实例形式详细说明了Delphi获取句柄并发送消息的方法,具体用法说明如下: 查找另外一个窗口的句柄: handle := FindWindow(nil, ...
- Delphi中SendMessage使用说明(所有消息说明) good
Delphi中SendMessage使用说明 SendMessage基础知识 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数Po ...
- SendMessage函数的常用消息及其应用大全
来源:http://www.360doc.com/content/09/0814/10/19147_4907488.shtml,非常全面的解释. 文本框控件通常用于输入和编辑文字.它属于标准 Wind ...
- 发送消息执行记事本的“另存为”菜单功能(通过WM_COMMAND控制使用别的程序的菜单命令)
发送消息执行记事本的“另存为”菜单功能procedure TForm1.FormCreate(Sender: TObject);var hNotepad: Cardinal;begin hNotepa ...
- [转] C#中发送消息给指定的窗口,以及接收消息
原文C#中发送消息给指定的窗口,以及接收消息 public class Note { //声明 API 函数 [DllImport("User32.dll", EntryPoint ...
- Winform 程序嵌入WPF程序 并发送消息
废话不多说,先看解决方案目录 WindowsFormsDemo是主程序,WpfApp是嵌入的WPF程序,先看WPF程序,程序默认启动的页面是MainWindow.xaml,这里注释掉App.xaml里 ...
- 关于 使用python向qq好友发送消息(对爬虫的作用----当程序执行完毕或者报错无限给自己qq发送消息,直到关闭)
以前看到网上一些小程序,在处理完事物后会自动发送qq消息,但是一直搞不懂是说明原理.也在网上找过一些python登陆qq发送消息的文字,但是都太复杂了.今天偶然看到一篇文章,是用python调用win ...
- 【转】python win32api win32gui win32con 简单操作教程(窗口句柄 发送消息 常用方法 键盘输入)
作者:https://blog.csdn.net/qq_16234613/article/details/79155632 附:https://www.programcreek.com/python/ ...
随机推荐
- [转载]Struts2.1.6+Spring2.5.6+Hibernate3.3.
原文地址:Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(一)(转载大象)作者:沉睡森林 在JavaEE企业级开发中,以SSH2框架为核心的应用非常广,大 ...
- JavaWeb -- 四个域对比 request,servletContext, Session, pageContext
requsest: 程序产生数据,用完了就没有用了, 用request, 作用范围:一个请求范围. Session: 程序产生数据,用完了 等一下还要使用, 用Session, 作用范围: 一个会话范 ...
- Eclipse里面新建servlet 是否需要配置web.xml
在新建的时候可选时候映射,如果选择了映射,那么就会在servle开头的地方有一行@servlet(""),这就完成了映射.注释掉这行就需要在web.xml中设置了
- C# WPF DataGrid 隔行变色及内容居中对齐
C# WPF DataGrid 隔行变色及内容居中对齐. dqzww NET学习0 先看效果: 前台XAML代码: <!--引入样式文件--> <Window.Resourc ...
- 抓包tcpdump
tcpdump是基于Unix系统的命令行式的数据包嗅探工具 tcpdump 可以监测真机或者模拟器 2g/3g/wifi下数据流动,前提手机必须root过. fillder也可以检测客户端数据包 ...
- python中的类和对象
类和对象 1. 类和对象和概念 类:共性事物的抽象,是对某一类具有共同事物的描述,是具有相同属性和方法的集合 对象:类的实例,是共性事物的一个体现,是这类事物中的每个个体 2. 总结: 类是对象的模板 ...
- Container容器调用构造函数
- Oracle Index Clustering Factor(集群因子)
一.本文说明: 今天在做测试的时候发现字段上有索引,但是执行计划就是不走索引,经过在网上查找才发现原来是索引的集群因子过高导致的.本文属于转载 二.官网说明 The index clustering ...
- hadoop_异常_02_ExitCodeException exitCode=1: chmod: changing permissions of `/ray/hadoop/dfs/data': Operation not permitted
一.异常现象 启动hadoop时,datanode启动失败,出现如下异常: 2018-03-23 14:39:09,962 WARN org.apache.hadoop.hdfs.server.dat ...
- Chrome MarkDown Preview Plus
/************************************************************************** * Chrome MarkDown Previe ...