c# Findwindow sendMessage
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TencentMsg
{ public class Win32API
{ [DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); ///<summary>
/// 设置指定窗口为当前活动窗口
///</summary>
///<param name="hWnd">窗口句柄</param>
[DllImport("User32.DLL")]
private static extern bool SetForegroundWindow(IntPtr hWnd); ///<summary>
/// 向指定窗口发送字符串
///</summary>
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); [DllImport("shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
[DllImport("user32.dll")]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lparam);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]//查找窗口
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);
static IntPtr Game; const int BM_CLICK = 0xF5; public static bool FindWind(string sTitle){
IntPtr hwnd = FindWindow(null, sTitle);
return (hwnd != IntPtr.Zero) ; } public class WindowInfo { public IntPtr hWnd;
public string szClassName;
public string szWindowName; } //寻找系统的全部窗口
public static WindowInfo[] GetAllDesktopWindows()
{
List<WindowInfo> wndList = new List<WindowInfo>();
EnumWindows(delegate(IntPtr hWnd, int lParam)
{
WindowInfo wnd = new WindowInfo();
StringBuilder sb = new StringBuilder(256);
//get hwnd
wnd.hWnd = hWnd;
//get window name
GetWindowTextW(hWnd, sb, sb.Capacity);
wnd.szWindowName = sb.ToString();
//get window class
GetClassNameW(hWnd, sb, sb.Capacity);
wnd.szClassName = sb.ToString();
//Console.WriteLine("Window handle=" + wnd.hWnd.ToString().PadRight(20) + " szClassName=" + wnd.szClassName.PadRight(20) + " szWindowName=" + wnd.szWindowName);
//add it into list
if (wnd.szClassName == "TXGuiFoundation" && wnd.szWindowName=="查找")
{
wndList.Add(wnd);
} return true;
}, 0);
return wndList.ToArray();
} public static bool FindSearchWind(){ IntPtr maindHwnd = FindWindow("TXGuiFoundation", ""); if(maindHwnd != IntPtr.Zero){ IntPtr childHwnd = FindWindowEx(maindHwnd, IntPtr.Zero, null, "登录");
if (childHwnd != IntPtr.Zero)
{
SendMessage(childHwnd, BM_CLICK, 0, 0);
}
else
{
MessageBox.Show("没有找到子窗口");
} } return (maindHwnd != IntPtr.Zero) ; } }
}
more: https://www.cnblogs.com/tary2017/articles/8031782.html
c# Findwindow sendMessage的更多相关文章
- FindWindow SendMessage
FindWindow 用来根据类名和窗口名来得到窗口句柄的.但是这个函数不能查找子窗口,也不区分大小写. 如果要从一个窗口的子窗口中查找需要使用FindWindowEX. 1.在C#中使用方法如下: ...
- findwindow\sendmessage向第三方软件发送消息演示
这里仅仅是以putty作为演示消息发送机制和控件搜索机制 程序一:代填IP和端口,并建立远程连接 #include"stdafx.h"#include <windows.h& ...
- MFC消息-自定义消息
转:http://blog.csdn.net/penpenandtongtong/article/details/18598907 像MFC的窗口发送消息,可以进行自定义的动作行为,因此很多时候非常有 ...
- visual_c++外挂教程(详细)
课程分四个大章节 初级篇,中级篇,进阶篇,高级篇 初级篇内容:编写一个完整的,简单的外挂 C++的数据类型:Byte,Word,DWORD,int,float API函数的调mouse_event,G ...
- C#关于外挂汉化的一些思考(API函数FindWindow,FindWindowEx,SendMessage)(转)
这次我们试着运用C#的API函数去修改别的程序的标题文本(适用范围C#) 其实这是FindWindow,FindWindowEx,SendMessage的应用举例之一 也就是所谓的外挂汉化. 附:Wi ...
- C#根据弹窗标题获取窗体句柄并模拟点击按钮(FindWindow,FindWindowEx,SendMessage)
任务:将下面弹窗自动关闭 /// <summary> /// 找到窗口 /// </summary> /// <param name="lpClassName& ...
- Delphi实现获取句柄并发送消息的方法(FindWindow、FindWindowEx、EnumChildWindows、SendMessage)
Delphi实现获取句柄并发送消息的方法 本文以实例形式详细说明了Delphi获取句柄并发送消息的方法,具体用法说明如下: 查找另外一个窗口的句柄: handle := FindWindow(nil, ...
- C#调用SendMessage 用法
函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. 函数原型:LRESUL ...
- [原创]C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
首先介绍基本WindowsApi: public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 函 ...
随机推荐
- 葡萄城报表 SP2新特性(2)— 智能钻取下级报表
中国式复杂报表常常会因为一些特殊的行业规范存在着一些复杂的需求,对于报表的功能要求不仅要广而全,还要精细到行业内部,葡萄城报表近几年来也一直致力于解决中国式复杂报表的需求,一直持续增强中国式复杂报表的 ...
- Express4.X中的bin/www是作什么用的?为什么没有后缀?
使用Express4.X的同学会发现,相比Express3.X初始化项目时多了一个bin目录,并且下面还有一个www文件,那么它们有什么用呢? 在Express 3.x中集成了很多中间件,www和ap ...
- Mac走moneky
1. 安装卸载apk ① 安装apk:下载apk到电脑 ,adb install -r 拖动apk adb install /Users/yangdan/Downloads/tutor-6.18.0. ...
- SEO-搜索引擎优化
一.定义 SEO(Search Engine Optimization):汉译为搜索引擎优化.是一种方式:利用搜索引擎的规则提高网站在有关搜索引擎内的自然排名.目的是:为网站提供生态式的自我营销解决方 ...
- MySQL基础之 索引
MySQL索引讲解 索引的好处: MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果合理的设计且使用索引的MySQL是一辆兰博基尼的话,那么 ...
- Javaweb学习(二):Http通信协议
当我们开始jsp/servlet编程之旅之前,我们还需要知道一些关于网络通讯方面的一些知识.这样能更加有助于我们的理解,希望大家能看懂我的描述,而不至于在学习的路上一知半解.(手动比❤) 认识Ht ...
- C#中单问号(?)和双问号(??)的用法整理
1.单问号(?) 1.1 表示Nullable类型 C#2.0里面实现了Nullable数据类型 //A.比如下面一句,直接定义int为null是错误的,错误提示为无法将null转化成int,因为后者 ...
- 8.2Solr API使用(Facet查询)
转载请出自出处:http://eksliang.iteye.com/blog/2165882 一)概述 Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验.在搜索关键字的同时,能够 ...
- 关于requests.exceptions.SSLError: HTTPSConnectionPool
问题: requests.exceptions.SSLError: HTTPSConnectionPool(host='mall.christine.com.cn', port=443): Max r ...
- Swift: Associated Types--为什么协议使用关联类型而不是泛型
关联类型的形式为类型的引用进而进行约束提供了条件: 同时能够简化语法形式. Swift: Associated Types http://www.russbishop.net/swift-associ ...