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. ...
随机推荐
- 在linux下配置Nginx+Java+PHP的环境
Apache对Java的支持很灵活,它们的结合度也很高,例如Apache+Tomcat和Apache+resin等都可以实现对Java应用 的支持.Apache一般采用一个内置模块来和Java应用服务 ...
- AWK 介绍
一.模式和动作 awk脚本是由模式和操作组成的:pattern {action} pattern与{action}两者是可选的.如果没有模式,则action应用到全部记录,如果没有action,则输出 ...
- Python-Day1 Python基础学习
一.Python3.5.X安装 1.Windows Windows上找度娘搜索“Python for windows下载”就OK了,安装的时候可以勾选设置环境变量,也可以安装完手动设置,这样在cmd中 ...
- WPF 概述
WPF 全称是:Windows Presentation Foundation,直译为Windows表示基础.WPF是专门为GUI(Graphic User Interface)程序开发设计的. 在过 ...
- hdu 4679 Terrorist’s destroy 树形DP
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679 题意:给定一颗树,每条边有一个权值w,问切掉哪条边之后,分成的两颗树的较大的直径*切掉边的权值最小? ...
- PIL 安装
1.安装依赖包 1.1 ubuntu安装 apt-get install python-devapt-get install libjpeg-dev apt-get install libjpeg8- ...
- showModalDialog 超过问题
a.aspx页面打开一个弹出模式对话框b.aspx. a.aspx 页面页面代码: function SetPlay() { window.showModalDialog('SetAdvertisin ...
- easy ui window 相关属性
<div class="easyui-window" title="提示" style="width:550px;height:500px;pa ...
- 微软职位内部推荐-Senior Network Engineer
微软近期Open的职位: Global Foundation Services is the team behind the cloud. GFS is responsible for deliver ...
- 1053: [HAOI2007]反素数ant - BZOJ
Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数 ...