windows获取窗口句柄
1、使用FindWindow函数获取窗口句柄
示例:使用FindWindow函数获取窗口句柄,然后获得窗口大小和标题,并且移动窗口到指定位置。
- #include <Windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <iostream.h>
- int main(int argc, char* argv[])
- {
- //根据窗口名获取QQ游戏登录窗口句柄
- HWND hq=FindWindow(NULL,"QQ2012");
- //得到QQ窗口大小
- RECT rect;
- GetWindowRect(hq,&rect);
- int w=rect.right-rect.left,h=rect.bottom-rect.top;
- cout<<"宽:"<<w<<" "<<"高:"<<h<<endl;
- //移动QQ窗口位置
- MoveWindow(hq,100,100,w,h,false);
- //得到桌面窗口
- HWND hd=GetDesktopWindow();
- GetWindowRect(hd,&rect);
- w=rect.right-rect.left;
- h=rect.bottom-rect.top;
- cout<<"宽:"<<w<<" "<<"高:"<<h<<endl;
- return 0;
- }
2、使用EnumWindows和EnumChildWindows函数以及相对的回调函数EnumWindowsProc和EnumChildWindowsProc获取所有顶层窗口以及它们的子窗口(有些窗口做了特殊处理,比如QQ是不能通过这个方法获得的)
示例:
- #include "stdafx.h"
- #include <Windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #include <string.h>
- #include <iostream.h>
- //EnumChildWindows回调函数,hwnd为指定的父窗口
- BOOL CALLBACK EnumChildWindowsProc(HWND hWnd,LPARAM lParam)
- {
- char WindowTitle[100]={0};
- ::GetWindowText(hWnd,WindowTitle,100);
- printf("%s\n",WindowTitle);
- return true;
- }
- //EnumWindows回调函数,hwnd为发现的顶层窗口
- BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM lParam)
- {
- if (GetParent(hWnd)==NULL && IsWindowVisible(hWnd) ) //判断是否顶层窗口并且可见
- {
- char WindowTitle[100]={0};
- ::GetWindowText(hWnd,WindowTitle,100);
- printf("%s\n",WindowTitle);
- EnumChildWindows(hWnd,EnumChildWindowsProc,NULL); //获取父窗口的所有子窗口
- }
- return true;
- }
- int main(int argc, _TCHAR* argv[])
- {
- //获取屏幕上所有的顶层窗口,每发现一个窗口就调用回调函数一次
- EnumWindows(EnumWindowsProc ,NULL );
- return 0;
- }
3、使用GetDesktopWindow和GetNextWindow函数得到所有的子窗口
示例:
- #include "stdafx.h"
- #include <Windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #include <string.h>
- #include <iostream.h>
- int main(int argc, _TCHAR* argv[])
- {
- //得到桌面窗口
- HWND hd=GetDesktopWindow();
- //得到屏幕上第一个子窗口
- hd=GetWindow(hd,GW_CHILD);
- char s[200]={0};
- //循环得到所有的子窗口
- while(hd!=NULL)
- {
- memset(s,0,200);
- GetWindowText(hd,s,200);
- /*if (strstr(s,"QQ2012"))
- {
- cout<<s<<endl;
- SetWindowText(hd,"My Windows");
- }*/
- cout<<s<<endl;
- hd=GetNextWindow(hd,GW_HWNDNEXT);
- }
- return 0;
- }
windows获取窗口句柄的更多相关文章
- [WinAPI] 获取窗口句柄的几种方法
1.使用FindWindow函数获取窗口句柄 示例:使用FindWindow函数获取窗口句柄,然后获得窗口大小,并且移动窗口到指定位置. 我们想获得酷我音乐盒的窗口句柄并移动它,该怎么办呢? 首先打开 ...
- c++ windows 获取mac地址
c++ windows 获取mac地址 GetAdaptersInfo 用windows api获取mac地址和硬盘id编号 aa
- windows获取本机MAC地址并写入文件的bat
windows获取本机MAC地址并写入文件的bat MAC(Media Access Control)地址,或称为 MAC地址.硬件地址,用来定义网络设备的位置. bat代码例如以下: @echo o ...
- Windows 获取控制台窗口句柄
详细信息 因为多个窗口可能具有相同的标题,您应该更改当前的控制台窗口标题为唯一的标题.这将有助于防止返回不正确的窗口句柄.使用 SetConsoleTitle() 来更改当前的控制台窗口标题.下面是此 ...
- Windows获取其他进程中Edit控件的内容
最近做的MFC项目中,有个获取其他进程中Edit控件内容的需求,本来以为是个很简单的问题,但是来来回回折腾了不少时间,发博记录一下. 刚开始拿到这个问题,很自然的就想到GetDlgItemText() ...
- Windows获取文件大小
Windows最初的设计允许我们处理非常大的文件,所以最初的设计者选用64位值来表示文件大小.但是我们在日常处理过程中文件大小一般不会超过4GB.故Windows提供了两个联合类型的数据结构表示文件大 ...
- windows获取时间的方法
介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执 行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记录 ...
- 1.RABBITMQ 入门 - WINDOWS - 获取,安装,配置
一. 背景: 公司项目有所改动,要求微信(移动端调用的接口),日志接口换位log4net,全部改成以rabbitMQ作为服务支持, 二.本地环境: windows 10 enterpr ...
- Windows获取进程完整路径
#include <stdio.h> #include <locale.h> #include <windows.h> #include <tlhelp32. ...
随机推荐
- unity3d应用内分享(微信、微博等)的实现
问题:如何在unity3d的游戏中实现分享功能,如图 思路: 1.分享功能的实现方式有多种,较方便快捷的一种是直接调用android的API来调出系统的分享界面 2.unity3d里面调用androi ...
- submit与button区别提交区别
提交表单时使用submit会自动提交form表单数据, 如果使用jquery的form表单插件时需要将提交按钮改为button时$("#表单id").ajaxSubmit({}); ...
- unity3d引擎程序员养成
标准流程:1. c++ Primer 英文版(第四或第五版)全部看完习题做完是必须的.渲染程序设计比较复杂,后期会用到c++的全部特性.c++学的越好后面越轻松.要看英文版,计算机翻来覆去就那么几个单 ...
- [转]StructLayout特性
转自:http://www.cnblogs.com/JessieDong/archive/2009/07/21/1527553.html StructLayout特性 StructLayout特性 ...
- 在SpringMVC利用MockMvc进行单元测试
spring在线文档:https://docs.spring.io/spring/docs/current/javadoc-api/index.html?index-files/index-13.ht ...
- eclipse中切换jre后报错:Java compiler level does not match the version of the installed Java project facet.
项目移除原来的jre环境lib后,添加本地的jre,报错如下: Java compiler level does not match the version of the installed Java ...
- 如何使用PHP实现一个WebService
WSDL WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问.这种文 ...
- Nagios+msn+fetion自定义时间发送报警消息
转自http://blog.csdn.net/deccmtd/article/details/6063467 Nagios+fetion发送手机报警使用了几个月.每次报警短信来都要看下手机.感觉麻烦. ...
- tomcat配置301重定向(urlRewrite URL重写)
tomcat默认情况下不带www的域名是不会跳转到带www的域名的,而且也无法像apache那样通过配置.htaccess来实现.如果想要把不带“www'的域名重定向到带”www"域名下,又 ...
- FreeMarker 乱码解决方案 生成静态html文件
读取模板的时候有一个编码: Template template = this.tempConfiguration.getTemplate(templatePath,"UTF-8") ...