getting the HWND for my own application in C

wonderer picture wonderer · Jul 14, 2009 · Viewed 15.2k times · Source

since I couldn't find an answer to this question I researched a bit further into the MSDN and I found isChild(). It might give me the answer to that other question.

Now, in order to use isChild() I need to pass the HWND of the parent application that I want to check, in this case my own application. How do I get the HWND of my own application?

I don't know the title since it changes constantly so I can't use FindWindow().

Thanks

Edit:

Since it's not clear, I'll add more information: I am not creating a window. I don't have access to the creation of a window. My code is a piece of code that gets compiled together with whatever application the other programmer is coding and I have no access to how the window is created, the title or any other information. So, how do I get the HWND to the "WINDOW" of the application I am running?

Answer

jalf picture jalf · Jul 14, 2009

Your application doesn't have a HWND. The window does. An application may have no windows or it may have many, so there is no general function to "Get the application's HWND".

The obvious solution is just to hold on to the handle when you get it. When you create the window, a HWND is returned. Store that.