VC Windows API应用之GetDesktopWindow ——获得桌面所有窗口句柄的方法
2015-04-19 14:49
886 查看
Windows API
Windows 这个多作业系统除了协调应用程序的执行、分配内存、管理资源…之外, 它同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务就是一个函数),可以帮应用程式达到开启视窗、描绘图形、使用周边设备等目的,由于这些函数服务的对象是应用程序(Application), 所以便称之为 Application Programming Interface,简称 API 函数。WIN32 API也就是Microsoft Windows 32位平台的应用程序编程接口。GetDesktopWindow
函数功能:该函数返回桌面窗口的句柄。桌面窗口覆盖整个屏幕。桌面窗口是一个要在其上绘制所有的图标和其他窗口的区域。函数原型:HWND GetDesktopWindow(VOID)
参数:无。
返回值:函数返回桌面窗口的句柄。
速查:Windows NT:3.1以上版本;Windows:95以上版本:;
头文件:Winuser.h;库文件:user32.lib。
【声明】
vb
Public Declare Function GetDesktopWindow Lib “user32” Alias “GetDesktopWindow” () As Long
vb_net
Public Declare Function GetDesktopWindow Lib “user32” Alias “GetDesktopWindow” () As Integer
c#
[DllImport(“user32.dll”, EntryPoint = “GetDesktopWindow”, CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr GetDesktopWindow();
【说明】
获得代表整个屏幕的一个窗口(桌面窗口)句柄
【返回值】
Long,桌面窗口的句柄
获得桌面所有窗口句柄的方法
创建项目
文件->新建->项目…编写方法
// GetDesktopWindow.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h" #define _AFXDLL #include <afxwin.h> //错误 1 error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. //Please #define _AFXDLL or do not use /MD[d] e:\programfilesx86\microsoftvisualstudio10\vc\atlmfc\include\afx.h 24 1 GetDesktopWindow int _tmain(int argc, _TCHAR* argv[]) { //1.先获得桌面窗口 CWnd* pDesktopWnd = CWnd::GetDesktopWindow(); //2.获得一个子窗口 CWnd* pWnd = pDesktopWnd->GetWindow(GW_CHILD); //3.循环取得桌面下的所有子窗口 while(pWnd != NULL) { //获得窗口类名 CString strClassName = _T(""); ::GetClassName(pWnd->GetSafeHwnd(),strClassName.GetBuffer(256),256); //获得窗口标题 CString strWindowText = _T(""); ::GetWindowText(pWnd->GetSafeHwnd(),strWindowText.GetBuffer(256),256); //继续下一个子窗口 pWnd = pWnd->GetWindow(GW_HWNDNEXT); } return 0; }
相关文章推荐
- C# Windows API应用之GetDesktopWindow ——获得桌面所有窗口句柄的方法
- C# Windows API应用之基于GetDesktopWindow获得桌面所有窗口句柄的方法
- VC Windows API获得桌面所有窗口句柄的方法
- Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
- Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
- WinAPI: GetDesktopWindow - 返回桌面窗口的句柄
- 隐藏控制台程序运行时的窗口(Windows API ShowWindow的应用)
- VC中获得窗口句柄的方法总结
- 易语言-API 取窗口或者组件句柄的 屏幕坐标并限制区域 GetWindowRect ClipCursor getwindowrect GetClientRect WindowFromPoint
- UIWindow的常用方法。makeKeyWindow、makeKeyAndVisible、获取当前应用的主窗口和所有窗口
- Windows下获得窗口实例句柄的3种方法
- C# Windows API应用之基于FlashWindowEx实现窗口闪烁的方法
- Delphi的TService的輸入桌面切換(服务程序)(windows登录界面如何截图)(使用了OpenDesktop和GetThreadDesktop等API)
- ios-day11-01(UIWindow的常用方法。makeKeyWindow、makeKeyAndVisible、获取当前应用的主窗口和所有窗口)
- C# Windows API应用之FlashWindowEx ——实现窗口闪烁的方法
- VC各种方法获得的窗口句柄
- ios-day11-01(UIWindow的常用方法。makeKeyWindow、makeKeyAndVisible、获取当前应用的主窗口和所有窗口)
- 用Windows Native API枚举所有句柄及查找文件句柄对应文件名的方法
- go语言使用go-sciter创建桌面应用(七) view对象常用方法,文件选择,窗口弹出,请求
- C#用API如何遍历所有窗口句柄