Difference between HANDLE and HWND in Windows API?

前端 未结 3 1132
春和景丽
春和景丽 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 09:12

    A "handle" is the general term used to refer to a token that identifies a resource on the system (a menu, a DLL module, a block of memory, etc). Often referred to as a "magic cookie", it's normally returned when you first create the resource. You then pass that handle to other functions in the API responsible for processing the resource. You normally need not know what the handle is however. Sometimes it may be a pointer, other times a number, perhaps a structure, or whatever. That's why they hide it using names like HWND which is simply the handle used to identify a window (returned by the API function "CreateWindow()"). You therefore don't convert a "handle" to an HWND and back again since an HWND is already a "handle" (one that merely identifies windows you create).

    Found here http://forums.codeguru.com/showthread.php?135438-Handle-and-HWND

    You can use FindWindow to get the hwnd from an application http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx

    This should allow you to get the HWND provided you have the handle to what you're looking for C++ Handle as HWND?

提交回复
热议问题