VC Windows API获得桌面所有窗口句柄的方法

VCWindowsAPI应用之GetDesktopWindow——获得桌面所有窗口句柄的方法WindowsAPIWindows这个多作业系统除了协调应用程序的执行、分配内存、管理资源…之

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

VC Windows API应用之GetDesktopWindow ——获得桌面所有窗口句柄的方法

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>
// 何问起 hovertree.com
//错误    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;
}

推荐:http://www.cnblogs.com/roucheng/p/3456005.html

http://www.cnblogs.com/roucheng/p/wendang.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/120553.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号