Some knowledge of the handle

Control (control), font (font), resource (resource), comprising an icon (icon), the cursor (cursor), string (string) and the like, GDI objects (GDI object), including bitmap (bitmap), brushes ( brush), the meta file (metafile), the palette (palette), pen (pen), the region (region), and a device description table (device context).  
   
  >> << WINDOWS programming fast track (Nanjing University Press):  
          The handle is a unique integer identifier used WONDOWS object is created or application program, WINDOWS using various application instance identifier, such as a handle, the window control , bitmaps, and so the GDI objects. WINDOWS handles a bit like a file handle in the C language.  
   
  Two, MFC source:  
   
  #ifdef the STRICT  
  typedef void * HANDLE;  
  #define DECLARE_HANDLE (name) __ ## struct {int unused name;}; typedef struct name ## __ * name  
  #else  
  typedef HANDLE PVOID;  
  #define DECLARE_HANDLE (name ) typedef HANDLE name  
  #endif  
   
  DECLARE_HANDLE (the HMODULE);  
  DECLARE_HANDLE (the HINSTANCE);  
  DECLARE_HANDLE (HLOCAL);  
  DECLARE_HANDLE (the HGLOBAL);  
  DECLARE_HANDLE (the HDC);  
  DECLARE_HANDLE (HRGN);  
  DECLARE_HANDLE (the HWND);  
  DECLARE_HANDLE (the HMENU);  
  DECLARE_HANDLE (HACCEL);  
  DECLARE_HANDLE (hTask);  
   
   
  Third, understand:  
          hANDLE is PVOID, which is untyped pointer,  
          handle handles on top of these resources are nothing but a pointer to struct pointer as to the usefulness of this struct, and even M $ say unused, now explain to M $ do meaning, this is called data encapsulation, you can put the internal structure of M $ pointers passed around in your program, but you do not know what it is in the end point of the content yes.  
   
          Handle with pointers really are two completely different concepts. Only handle a 32-bit integer, the WIN32 marking objects for a system or process, the object can be understood as an index (M $ since the related art is not completely disclosed, only in that way a certain degree), this index like is a mapping relationship (mapping from the handle to the object pointer), rather than "array subscript" pure sense.  
   
   
            Handle can be appreciated that for the identifier of the memory point or a "resources", which resources such as: file (File), the memory block (block of memory), the menu (menu) and the like. To locate core operating system objects and system resources through the handle.  
          Pointer points to is the "data or instructions" a memory unit.  
   
 Said the exact point handle is actually a pointer to a resource, but there are differences with the pointer: pointer corresponds to a data address in memory, you can get a pointer to freely modify the data. Windows generally do not want to modify its internal data structure, because it is too unsafe. So Windows for each memory area such as the use of GlobalAlloc function declaration specifies a handle (remains essentially a pointer, but do not directly operate it), you usually just call the API functions use this handle when to say which segment of memory to operate.  
   
           
  Fourth, allusion:  
        shepherd boy points Xinghuacun  
        shepherd pointer hand, makes for a handle of xing, hotel Xinghuacun instance of an object.  
   
   
  Note: the three methods to obtain the window handle  
   
  1.HWND FindWindow (LPCTSTR lpClassName, LPCTSTR lpWindowName   )
   
        HWND FindWindowEx (HWND hwndParent, HWND hwndChildAfter   , LPCTSTR lpClassName, LPCTSTR lpWindowName)
   
  2.HWND WindowFromPoint (POINT & Point) // get the current position of the mouse cursor window the HWND  
   
  3.BOOL CALLBACK EnumChildProc (HWND the HWND, LPARAM the lParam)  
   
        BOOL CALLBACK the EnumChildWindows (the HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM the lParam)  
   
        BOOL CALLBACK the EnumWindows (WNDENUMPROC lpEnumFunc, lParam lPARAM)  
   
        BOOL CALLBACK EnumWindowsProc (HWND hwnd, lPARAM lParam)

Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2011/11/06/2238885.html

Guess you like

Origin blog.csdn.net/weixin_34190136/article/details/93766838