Results 1 to 7 of 7

Thread: What is the difference between HANDLE and HWND

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    What is the difference between HANDLE and HWND

    What is the difference between HANDLE and HWND?
    Baaaaaaaaah

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    I used handle and hwnd

    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).
    Baaaaaaaaah

  5. #5
    Zaei
    Guest
    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.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    A handle is actually a pointer to a struct, I think.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Originally posted by parksie
    A handle is actually a pointer to a struct, I think.
    From what I remember, it goes something like this:
    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:
    Code:
    typedef void* HANDLE;
    typedef void* HWND;
    // etc.
    In STRICT mode, the handles are defined like this:
    Code:
    typedef struct __tagHANDLE { DWORD __unused; } *HANDLE;
    typedef struct __tagHWND { DWORD __unused; } *HWND;
    But I'm not sure...
    Sec, checking.
    ...
    ...
    ...
    AHA! There it is, in winnt.h:
    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
    And in other header files:
    Code:
    DECLARE_HANDLE(HWND);
    DECLARE_HANDLE(HGDIOBJ);
    // etc.
    Which means the handles are declared like this:
    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.
    Whew, that was fun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width