Solved

MFC, window handle

Posted on 2002-03-14
5
1,277 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
Comment Utility
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
Comment Utility
what about CDialog?
0
 
LVL 86

Expert Comment

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

Author Comment

by:j4months
Comment Utility
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
Comment Utility
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 improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now