Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find CWnd* of active window?

361 views
Skip to first unread message

Terry Disbro

unread,
Aug 14, 1998, 3:00:00 AM8/14/98
to
Hello All,
This newsgroup was very helpful with my last Novice question so I
thought
I'd try another. Here it goes - many MFC functions in the windows
environment
require a CWnd pointer. This would be fine if I had created the CWnd
object
myself but since it was created by VC++ Developer Studio I have no idea
what to put
when a CWnd* parameter is required. There must be a way to determine
the CWnd*
of the currently active window. I created an SDI application and only
have the Single
default window. Any help to determine how to determine the CWnd* of the
current
active window for use in functions like:
CWindowDC( CWnd* pWnd );
would be greatly appreciated!

Thanx for listening,
T.L. Disbro


Tomas Restrepo

unread,
Aug 14, 1998, 3:00:00 AM8/14/98
to
For most of the functions you describe there's two choices:

1- The CWnd* is the windows you're using. If you're using DC (like
CWindowDC) you're probably coding in a member class of a CWnd derived class.
That means you can simply pass 'this' as parameter.

2- The function you're using requieres the main application window. For
this, you can use
AfxGetApp()->m_pMainWnd;
or
AfxGetMainWnd();

Tomas Restrepo
win...@bigfoot.com
http://www.geocities.com/SiliconValley/Heights/3401

Terry Disbro <ox...@dmrtc.net> wrote in message
35D43646...@dmrtc.net...

Brad McMillan

unread,
Aug 14, 1998, 3:00:00 AM8/14/98
to Tomas Restrepo
Tomas Restrepo wrote:

> For most of the functions you describe there's two choices:
>
> 1- The CWnd* is the windows you're using. If you're using DC (like CWindowDC)
> you're probably coding in a member class of a CWnd derived class. That means
> you can simply pass 'this' as parameter.
>
> 2- The function you're using requieres the main application window. For this,
> you can use
> AfxGetApp()->m_pMainWnd; or AfxGetMainWnd();

Tomas:

A couple of quick questions:

1. In CWindowDC( CWnd* pWnd ); is pWnd the "handle" of CWnd*?
2. Is it a pointer that points to a block of data that has all the information
associated with CWnd*?
3. Is there a way to find out what this information is and how it is structured?

Thanks in advance,
Brad McMillan


Terry Disbro

unread,
Aug 14, 1998, 3:00:00 AM8/14/98
to
Thanx again Tomas,
This was exactly what I was looking for. Maybe someday I'll figure all of
this out.
Later,
T. L. Disbro

Tomas Restrepo wrote:

> For most of the functions you describe there's two choices:
>
> 1- The CWnd* is the windows you're using. If you're using DC (like
> CWindowDC) you're probably coding in a member class of a CWnd derived class.
> That means you can simply pass 'this' as parameter.
>
> 2- The function you're using requieres the main application window. For
> this, you can use
> AfxGetApp()->m_pMainWnd;
> or
> AfxGetMainWnd();
>

Ralf Pichocki

unread,
Aug 15, 1998, 3:00:00 AM8/15/98
to
You can get a CWnd* for every Windows window with CWnd::FromHandle().

Greetings, Pi.


0 new messages