Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1314
  • 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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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