What is the difference between HANDLE and HWND?
Printable View
What is the difference between HANDLE and HWND?
Technically, not much. Look at the definition for HWND to see how similar all the H* types are. Conceptually, quite a lot is different. I'm not sure if you can pass an HWND to a HANDLE or vice versa but possibly.
To elaborate on what parksie said: HANDLE is a handle to any Kernel32 object, while HWND is a handle to a specific User32 object (window).
They're not parts of the same Win32 library, so I would say the chance that you can use a HANDLE value as a HWND and vice versa is pretty, well, tiny :rolleyes:
I used handle on just one time when creating a file.
Everywehre else, for graphics or windws creation, I use hwnd
So is handle used to works with the kernel (files manipulation).
Im pretty sure that you can pass an HWND as a HANDLE. Someone check the typedefs (I cant at the moment, 16-bit DOS compiler only =( ). I THINK that typedef DWORD HANDLE; and typedef HANDLE HWND; should exist.
Z.
A handle is actually a pointer to a struct, I think.
From what I remember, it goes something like this:Quote:
Originally posted by parksie
A handle is actually a pointer to a struct, I think.
There are two compile modes - STRICT mode and non-STRICT mode. (In VC++ 5, non-STRICT was the default, and in VC++ 6, STRICT was the default.)
In non-STRICT mode, the handles are defined like this:
In STRICT mode, the handles are defined like this:Code:typedef void* HANDLE;
typedef void* HWND;
// etc.
But I'm not sure... :rolleyes:Code:typedef struct __tagHANDLE { DWORD __unused; } *HANDLE;
typedef struct __tagHWND { DWORD __unused; } *HWND;
Sec, checking.
...
...
...
AHA! There it is, in winnt.h:
And in other header files:Code:#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
Which means the handles are declared like this:Code:DECLARE_HANDLE(HWND);
DECLARE_HANDLE(HGDIOBJ);
// etc.
Whew, that was fun :rolleyes:Code:// STRICT mode:
typedef void* HANDLE;
typedef struct HWND__ { int unused; } *HWND;
typedef struct HGDIOBJ__ { int unused; } *HGDIOBJ;
// etc.
// Non-STRICT mode:
typedef PVOID HANDLE; // PVOID is pretty much the same as void* though
typedef HANDLE HWND;
typedef HANDLE HGDIOBJ;
// etc.