zoukankan      html  css  js  c++  java
  • VC Windows API获得桌面所有窗口句柄的方法

    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:programfilesx86microsoftvisualstudio10vcatlmfcincludeafx.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

  • 相关阅读:
    Codeforces 401C Team 贪心法
    C++ 编译,执行过程 具体解释。
    [从头学数学] 第156节 概率初步
    关于flex,好像有12个属性非常重要
    数据清洗小记(12):姓与名的提取
    理解Angular中的$apply()以及$digest()
    Oracle开发者守则
    黑马程序猿——25,打印流,合并流,对象序列化,管道流,RandomAccessFile
    GPU 编程入门到精通(四)之 GPU 程序优化
    Python 面向对象编程 继承 和多态
  • 原文地址:https://www.cnblogs.com/roucheng/p/GetDesktopWindow.html
Copyright © 2011-2022 走看看