Difference between HANDLE and HWND in Windows API?

前端 未结 3 1131
春和景丽
春和景丽 2020-12-24 08:30

I\'m trying to use function SetForegroundWindow(HWND hWnD). I have some handles but it\'s not working as parameter of above function. My handle is a thread and

3条回答
  •  悲哀的现实
    2020-12-24 08:50

    They are just abstract data types.

    According to MSDN, HANDLE and HWND are defined as:

    • HANDLE is a handle to an object.
    • HWND is a handle to a window.

    So, a HWND is a HANDLE, but not all HANDLEs are HWND. In fact:

    typedef void *PVOID;
    typedef PVOID HANDLE;
    typedef HANDLE HWND;
    

    Example

    You should only pass HWND to SetForegroundWindow unless you know what you are doing.

    HWND hWnd = FindWindow(NULL, "Calculator");
    SetForegroundWindow(hWnd);
    

    This first gets the handle to a window titled "Calculator" with FindWindow and then brings that window to foreground.

提交回复
热议问题