What is a handle? (Reproduced)

zhaozj2021-02-12  141

First look at some of the authority of the piece: ... typedef unsigned int HANDLE; #define DECLARE_HANDLE (name) typedef UINT name DECLARE_HANDLE (HMODULE); DECLARE_HANDLE (HINSTANCE); DECLARE_HANDLE (HLOCAL); DECLARE_HANDLE (HGLOBAL); DECLARE_HANDLE (HDC); DECLARE_HANDLE (HRGN); DECLARE_HANDLE (HWND); declare_handle (hmenu); declare_handle (haccel); declare_handle (htask); ... #define declare_handle (x) typedef word x ... // ----- -------------------------------------------------- ---------------- // Declare_handle macro // -------------------------- ---------------------------------------------- #ifndef Declare_handle # Define declare_handle ## __ {dword unused;}; / typef struct name ## __ _far * name #ENDIF ... know the essence ~~~~~ Windows program is not using physical address to identify A memory block, file, task, or dynamic load module, for the contrary, Windows API assigns a determined handle to these items and returns the handle to the application, and then operates through the handle. This is said in the << Windows Programming Sentimentality >> (Nanjing University Press): The handle is the unique integer used by Wondows to identify or use the object being applied or used by the application. Windows uses a variety of handle ID Such as applications, windows, controls, bitmaps, GDI objects, and more. The Windows handle is a bit icon in a C language. From the above 2 definitions we can see, the handle is an identifier, which is to identify objects or projects. It is like our name, everyone will have one, different people's names, However, there may be a name as you like you. From the data type, it is just a 16-bit unsigned integer. Applications almost always get a handle by calling a Windows function, then other Windows functions can use the handle to reference the corresponding object. A large number of handles can be used in Windows programming, such as Hinstance (EQ), HBitmap, HDC (Device Description Table Handle), Hicon (Icon Handle), etc., this is also a universal handle It is Handle, such as the following statement: Hinstance Hinstance; can be changed to: Handle Hinstance; the second sentence above is right. A Windows application can get a handle of a particular item with a different method. Many API functions, Return values ​​such as CREATEWINDOW, GLOBALLOC, OpenFile are one handle value.

转载请注明原文地址:https://www.9cbs.com/read-7482.html

New Post(0)