handle

 A handle is an ordinal, it is not a memory address .

 

  It is used to manage Windows kernel objects . For example, when a user opens a file, Windows will create a file kernel object . The so-called kernel object is a memory structure that contains information such as file path, file size, and current file pointer. The Windows system will open a lot of files, so there are many file kernel objects, and the Windows system will also create many, many other types of kernel objects. How to manage so many kernel objects? Windows records the addresses of kernel objects by creating something called a handle table. Each element in the table is the starting address of a kernel object, and then each object corresponds to a sequence number, which is the handle.

 

1
2
3
4
5
6
//句柄表类似于下面的结构,像0、1、2这样的序号即为句柄
----------------------------------------------------
0    第一个内核对象的地址
1    第二个内核对象的地址
2    第三个内核对象的地址
----------------------------------------------------

 

 

 

For example, use HWND hwnd=::FIndWindow("xx", "xxxx") to get the handle of the window, and then you can perform other operations, 
such as calling ShowWindow(hwnd, nCmdShow) in the display window;
where hwnd is the window handle.


The handle HANDLE in VC is actually a void * type. Like FILE in C language, it is a structure, and FILE * is actually a structure address type. A handle is similar to a pointer in Windows, it is a pointer type, but it is different from a pointer. For example, allocating a piece of movable memory, you can get a fixed handle, but the pointer to this memory is not fixed. There are many other types of handles, which are defined by HANDLE. In Windows programming, handle represents the only object in the system, such as file handle , icon handle, font handle, bitmap handle, brush handle, device environment handle, application module handle, process handle, window handle , etc. Since Windows is closed, Microsoft provides many ready-made functions (Windows API), and the handle is a "pointer" to access such objects, and these objects can be accessed through the handle.

The HANDLE type is defined in the Windows SDK header file as follows:
typedef void *PVOID;
typedef PVOID HANDLE; // file handle , process handle, etc.
typedef HANDLE HICON; //icon handle
typedef HANDLE HFONT; //font handle
typedef HANDLE HBITMAP; //bit figure handle
typedef HANDLE HBRUSH; //Brush handle
typedef HANDLE HDC; //Device environment handle
typedef HANDLE HMODULE; //Module handle
typedef HANDLE HWND; // There are many other handle types for window handle .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325131810&siteId=291194637