Windows的所有句柄类型定义

编者:李国帅

qq:9611153 微信lgs9611153

时间:2012-11-21

问题相关:

包含4个内容:常见句柄类型,全部句柄及描述,句柄函数宏定义,MFC中GDI类使用

常见句柄类型:

文件:ntdll.h

类型:OB_TYPE_TYPE

句柄类型 说明

HBITMP:标示位图句柄

HBRUSH:标示画刷句柄

HCOURSOR:标示鼠标光标句柄

HDC:标示设备环境句柄

HFONT:标示字体句柄

HICON:标示图标句柄

HINSTANCE:标示当前实例句柄

HMENU:标示菜单句柄

HPALETTE:颜色调色板句柄

HPEN:标示画笔句柄

HWND:标示窗口句柄

HFILE:标示文件句柄

全部句柄及描述:

Object      Description

Access token

The handle is returned by the CreateRestrictedToken, DuplicateToken, DuplicateTokenEx, OpenProcessToken, or OpenThreadToken function.

Change notification

The handle is returned by the FindFirstChangeNotification function.

Communications device

The handle is returned by the CreateFile function.

Console input

The handle is returned by the CreateFile function when CONIN$ is specified, or by the GetStdHandle function when STD_INPUT_HANDLE is specified. Console handles can be duplicated for use only in the same process.

Console screen buffer

The handle is returned by the CreateFile function when CONOUT$ is specified, or by the GetStdHandle function when STD_OUTPUT_HANDLE is specified. Console handles can be duplicated for use only in the same process.

Desktop

The handle is returned by the GetThreadDesktop function.

Event

The handle is returned by the CreateEvent or OpenEvent function.

File

The handle is returned by the CreateFile function.

File mapping

The handle is returned by the CreateFileMapping function.

Job

The handle is returned by the CreateJobObject function.

Mailslot

The handle is returned by the CreateMailslot function.

Mutex

The handle is returned by the CreateMutex or OpenMutex function.

Pipe

A named pipe handle is returned by the CreateNamedPipe or CreateFile function. An anonymous pipe handle is returned by the CreatePipe function.

Process

The handle is returned by the CreateProcess, GetCurrentProcess, or OpenProcess function.

Registry key

The handle is returned by the RegCreateKey, RegCreateKeyEx, RegOpenKey, or RegOpenKeyEx function. Note that registry key handles returned by the RegConnectRegistry function cannot be used in a call to DuplicateHandle.

Windows Me/98/95:  You cannot use DuplicateHandle to duplicate registry key handles.

Semaphore

The handle is returned by the CreateSemaphore or OpenSemaphore function.

Socket

The handle is returned by the socket or accept function.

Thread

The handle is returned by the CreateProcess, CreateThread, CreateRemoteThread, or GetCurrentThread function

Timer

The handle is returned by the CreateWaitableTimer or OpenWaitableTimer function.

Window station

The handle is returned by the GetProcessWindowStation function.

句柄函数宏定义:

很多宏看上去很形象,但实际上隐藏了细节

文件:windowsx.h

/****** KERNEL Macro APIs ****************************************************/

#define     GetInstanceModule(hInstance) (HMODULE)(hInstance)

#define     GlobalPtrHandle(lp)    ((HGLOBAL)GlobalHandle(lp))

#define     GlobalLockPtr(lp)    ((BOOL)GlobalLock(GlobalPtrHandle(lp)))

#define     GlobalUnlockPtr(lp)    GlobalUnlock(GlobalPtrHandle(lp))

#define     GlobalAllocPtr(flags, cb)   (GlobalLock(GlobalAlloc((flags), (cb))))

#define     GlobalReAllocPtr(lp, cbNew, flags)  (GlobalUnlockPtr(lp), GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags))))

#define     GlobalFreePtr(lp)  (GlobalUnlockPtr(lp), (BOOL)(ULONG_PTR)GlobalFree(GlobalPtrHandle(lp)))

/****** GDI Macro APIs *******************************************************/

#define     DeletePen(hpen)      DeleteObject((HGDIOBJ)(HPEN)(hpen))

#define     SelectPen(hdc, hpen)    ((HPEN)SelectObject((hdc), (HGDIOBJ)(HPEN)(hpen)))

#define     GetStockPen(i)       ((HPEN)GetStockObject(i))

#define     DeleteBrush(hbr)     DeleteObject((HGDIOBJ)(HBRUSH)(hbr))

#define     SelectBrush(hdc, hbr)   ((HBRUSH)SelectObject((hdc), (HGDIOBJ)(HBRUSH)(hbr)))

#define     GetStockBrush(i)     ((HBRUSH)GetStockObject(i))

#define     DeleteRgn(hrgn)      DeleteObject((HGDIOBJ)(HRGN)(hrgn))

#define     CopyRgn(hrgnDst, hrgnSrc)               CombineRgn(hrgnDst, hrgnSrc, 0, RGN_COPY)

#define     IntersectRgn(hrgnResult, hrgnA, hrgnB)  CombineRgn(hrgnResult, hrgnA, hrgnB, RGN_AND)

#define     SubtractRgn(hrgnResult, hrgnA, hrgnB)   CombineRgn(hrgnResult, hrgnA, hrgnB, RGN_DIFF)

#define     UnionRgn(hrgnResult, hrgnA, hrgnB)      CombineRgn(hrgnResult, hrgnA, hrgnB, RGN_OR)

#define     XorRgn(hrgnResult, hrgnA, hrgnB)        CombineRgn(hrgnResult, hrgnA, hrgnB, RGN_XOR)

#define     DeletePalette(hpal)     DeleteObject((HGDIOBJ)(HPALETTE)(hpal))

#define     DeleteFont(hfont)            DeleteObject((HGDIOBJ)(HFONT)(hfont))

#define     SelectFont(hdc, hfont)  ((HFONT)SelectObject((hdc), (HGDIOBJ)(HFONT)(hfont)))

#define     GetStockFont(i)      ((HFONT)GetStockObject(i))

#define     DeleteBitmap(hbm)       DeleteObject((HGDIOBJ)(HBITMAP)(hbm))

#define     SelectBitmap(hdc, hbm)  ((HBITMAP)SelectObject((hdc), (HGDIOBJ)(HBITMAP)(hbm)))

#define     InsetRect(lprc, dx, dy) InflateRect((lprc), -(dx), -(dy))

...

MFC的CGdiObject对象不需要手动释放句柄:

对于MFC的CGdiObject对象,并不需要手动释放,离栈自动释放句柄。例如

CBitmap BmpSlider;

BmpSlider.LoadBitmap(IDB_TOOLBK);

//BmpSlider.DeleteObject();//不需要手动删除对象,CBitmap离栈自动释放句柄

代码跟踪:

 class CBitmap : public CGdiObjectclass CGdiObject : public CObject_AFXWIN_INLINE CGdiObject::~CGdiObject(){AFX_BEGIN_DESTRUCTORDeleteObject();AFX_END_DESTRUCTOR}

Windows的所有句柄类型定义相关推荐

  1. linux 句柄类型,句柄问题分析

    什么是句柄 句柄就是一个对象的标识符,只要获得对象的句柄,我们就可以对对象进行任意的操作,包括窗口,按钮,图标,输出设备,控件或者文件等: 句柄是一种特殊的智能指针,用一个唯一的整数值标识一个对象(即 ...

  2. XML之文档类型定义和合法性(转)

    来至:liang--liang博客:http://www.cnblogs.com/liang--liang/archive/2008/01/15/1039277.html 好牛 XML被作为一种元标记 ...

  3. C++ 笔记-结构体-枚举-类型定义

    文章目录 为什么要使用"结构"(结构体) 还有一种特别的,结构体包含结构体,这种可以用于统计一个班人员信息等 结构数组 指向结构体的指针 使用结构体传递值 枚举 类型定义 为什么要 ...

  4. 编译型和解释型、动态语言和静态语言、强类型定义语言和弱类型定义语言

    一.编译型与解释型语言 我们编写程序也就是源代码基本是用高级编程语言,比如JavaScript, java, c等等,这些语言计算机是不理解的,所以需要转化(翻译)成计算机理解的机器语言,或者说目标C ...

  5. Go 知识点(05)— 类型别名与类型定义

    1. 类型别名 类型别名需要在别名和原类型之间加上赋值符号 = ,使用类型别名定义的类型与原类型等价,Go 语言内建的基本类型中就存在两个别名类型. byte 是 uint8 的别名类型: rune ...

  6. Go 学习笔记(27)— type 关键字(类型定义、类型别名、类型查询、定义接口、定义结构体)

    1. 类型别名定义 定义类型别名的写法为: type TypeAlias = Type 类型别名规定: TypeAlias 只是 Type 的别名,本质上 TypeAlias 与 Type 是同一个类 ...

  7. 为什么阿里巴巴强制要求使用包装类型定义属性?

    欢迎关注方志朋的博客,回复"666"获面试宝典 在阿里巴巴Java开发手册中,对于POJO中如何选择变量的类型也有着一些规定: 这里强制要求使用包装类型,原因是什么呢? 我们来看一 ...

  8. DTD(文档类型定义)概述

    DTD(文档类型定义)的作用是定义 XML 文档的合法构建模块.DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. DTD 简介 文档类型定义(DTD)可定义合法的XML文档构建模块.它 ...

  9. 枚举的定义枚举类型定义

    枚举的定义枚举类型定义的一般形式为: enum 枚举名 { 枚举值表 }; 在枚举值表中应罗列出所有可用值.这些值也称为枚举元素. 例如: enum weekday { sun,mou,tue,wed ...

最新文章

  1. 悉尼科技大学入选 CVPR 2021 的 9 篇论文,都研究什么?
  2. 北大博士整理B站实战项目!yyds!
  3. 01矩阵等比放大(Java代码、ACM格式)--2021.9.7百度笔试研发A卷
  4. JavaScript 爆红后,微软为何还要开发 TypeScript?
  5. java 状态迁移图_kafka 实战笔记
  6. css vertical-align
  7. cf1208G Polygons 欧拉函数
  8. python 读取地震道头数据_python地震数据可视化详解
  9. 用CComPtr吧,COM接口指针很危险
  10. php编程输出心形图案_如何用C语言先输出一段文字如何再输出心形图案?
  11. 开发WCF/Silverlight须知
  12. ios通过url下载显示图片
  13. Windows程序设计_Chap03_窗口与消息_学习笔记
  14. 主数据管理(MDM)的成熟度
  15. 【STM32H7教程】第2章 STM32H7的开发环境搭建
  16. 微信小程序后台服务器搭建
  17. 习题3.3 506寝室小组
  18. 小狗AI自动建站系统
  19. “2020(第二届)中国食品供应链大会”于8月27-28日在湖南长沙召开
  20. vmware workstation15 清理磁盘

热门文章

  1. 搜索引擎技术 —— 索引技术
  2. Mac电脑百度网盘登录卡死现象解决方案
  3. matlab 如何输出gif,MATLAB生成GIF动画,PhotoShop制作GIF动画
  4. 投资组合分析1(ZTEHK VA ZTEA)方法2(OLS+adfuller)
  5. 超级不可能的路Super Impossible Road Mac(竞速游戏)原生版
  6. 计算机毕业设计 java web网上购物商城系统(源码+论文)
  7. 红帽认证学习笔记-老版本与新版本命令区别与重置linux密码
  8. PTA 一 列车调度
  9. 目标跟踪 — DSST
  10. 以太坊的「帝国模式」