获取窗口句柄
来源:互联网 发布:af淘宝旗舰店真假 编辑:程序博客网 时间:2024/05/22 04:47
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;}
- 获取窗口句柄
- 获取桌面窗口句柄
- 获取窗口句柄
- 获取窗口句柄
- 获取console窗口句柄
- 获取窗口句柄
- 窗口句柄获取神器
- WPF获取窗口句柄
- MFC 窗口句柄获取
- 获取窗口句柄
- mfc获取窗口句柄
- 获取窗口句柄
- C++ 获取窗口句柄
- 获取窗口句柄
- 获取窗口句柄
- qt 获取窗口句柄
- 获取窗口句柄
- 获取鼠标点窗口句柄
- spring in action Third (第一章)
- 根据二叉树的前序和中序序列来重建二叉树
- HTML&CSS快速入门
- SSE指令介绍及其C、C++应用(2)
- C#操纵进程及相关
- 获取窗口句柄
- 64位WIN7+oracle11g+plsql安装
- Boost.Lambda是什么?
- SQL语句
- Java实现大文件分割
- linux c/c++ 注意
- pythonPkg_xml.etree.ElementTree
- 使用Amoeba for mysql实现mysql读写分离
- Java实现读取PDF