• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1317
  • Last Modified:

MFC, window handle

When using MFC, I do not explicitly call 'CreateWindow.' So how do I get the handle of the window created?
0
j4months
Asked:
j4months
  • 3
  • 2
1 Solution
 
jkrCommented:
As all "windowing" classes are derived from CWnd, the window handle is available as "m_hWnd", e.g.

CMyWnd* pWnd = ...;

HWND hWnd = pWnd->m_hWnd;
0
 
j4monthsAuthor Commented:
what about CDialog?
0
 
jkrCommented:
CDialog is derived from CWnd, so it's the same - each instance has a member "m_hWnd"...
0
 
j4monthsAuthor Commented:
Yes, it compiles.
Can you tell me in what file is 'm_hWnd' declared? It shows nothing when I do 'find in files.'
Thanks.
0
 
jkrCommented:
It's declared in "afxwin.h":

class CWnd : public CCmdTarget
{
    DECLARE_DYNCREATE(CWnd)
protected:
    static const MSG* PASCAL GetCurrentMessage();

// Attributes
public:
    HWND m_hWnd;            // must be first data member
    operator HWND() const;

// ...

};
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now