Here is the problem: how come you don't have a pointer to the instance of MFC
CWnd
(or whatever you use)?
Certainly, as
CWnd
installs it's Window procedure for handling raw Windows messages, it should keep "this" pointer in raw Windows API data, which is usually done by UI libraries build on Windows API. This is the way to keep mapping between the class instance with OOP-library and raw Window data.
But — if this is
your application,
you already have this pointer; if not — getting this pointer is not helpful, because you cannot safely cast it to the MFC class you might assume, as
nothing can guarantee that the window was build using MFC; and MFC of the same version as you use.
Also, do understand that Windows API registered Window class of the class derived from any MFC class are two absolutely different things.
Now, if you need just the window text, you can use
GetWindowText
, see
http://msdn.microsoft.com/en-us/library/ms633520%28v=vs.85%29.aspx[
^].
[EDIT]
To extract other information from the raw Window handle, use the function
GetWindowLong
, see
http://msdn.microsoft.com/en-us/library/ms633584(v=vs.85).aspx[
^]. Potentially the pointer to the instance of the UI library class can be stored at the index
GWL_USERDATA
, but nothing can guarantee you any certain interpretation of this pointer or valid type cast you can use if this is not your application.
—SA