码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-04-19 16:17:44      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:vc   windowapi   获得桌面   窗口句柄   应用   

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;
}

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

标签:vc   windowapi   获得桌面   窗口句柄   应用   

原文地址:http://blog.csdn.net/testcs_dn/article/details/45129145

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!