Solved

MFC, window handle

Posted on 2002-03-14
5
1,286 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

770 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