Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


MFC, window handle

Posted on 2002-03-14
Medium Priority
Last Modified: 2010-05-18
When using MFC, I do not explicitly call 'CreateWindow.' So how do I get the handle of the window created?
Question by:j4months
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 86

Accepted Solution

jkr earned 200 total points
ID: 6865208
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;

Author Comment

ID: 6865281
what about CDialog?
LVL 86

Expert Comment

ID: 6865291
CDialog is derived from CWnd, so it's the same - each instance has a member "m_hWnd"...

Author Comment

ID: 6865318
Yes, it compiles.
Can you tell me in what file is 'm_hWnd' declared? It shows nothing when I do 'find in files.'
LVL 86

Expert Comment

ID: 6865340
It's declared in "afxwin.h":

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

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

// ...


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question