Getting HWND of current Process

后端 未结 7 914
攒了一身酷
攒了一身酷 2020-12-17 10:33

I have a process in c++ in which I am using window API. I want to get the HWND of own process. Kindly guide me how can I make it possible.

7条回答
  •  被撕碎了的回忆
    2020-12-17 11:04

    Get your console window

    GetConsoleWindow();
    


    "The return value is a handle to the window used by the console associated with the calling process or NULL if there is no such associated console."

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms683175(v=vs.85).aspx

    Get other windows

    GetActiveWindow() might NOT be the answer, but it could be useful
    "The return value is the handle to the active window attached to the calling thread's message queue. Otherwise, the return value is NULL." > msdn GetActiveWindow() docs

    However, the graphical windows are not just popping up - so you should retrieve the handle from the place you/your app've created the window... e.g. CreateWindow() returns HWND handle so all you need is to save&retrieve it...

提交回复
热议问题