Solved

MFC, window handle

Posted on 2002-03-14
5
1,295 Views
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?
0
Comment
Question by:j4months
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 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;
0
 

Author Comment

by:j4months
ID: 6865281
what about CDialog?
0
 
LVL 86

Expert Comment

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

Author Comment

by:j4months
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.'
Thanks.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6865340
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

679 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