problem with CWnd and FindWindow

I have a problem with VC++6. I'm a real newbie to C++
and my problem is the following:
If I write something like this

CWnd Window;

Cwnd* hAOL = Window.FindWindow (NULL, "AOL");

I think it should place into Window the handle of
AOL's window. But it just puts the handle into hAOL
and if I try to make something like this

Window.m_hWnd = hAOL;

after the code above I got the problem that
C++ cannot convert from class CWnd* into struct
HWND__*

Who can help me??
benjaamAsked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
answer coming.
0
 
benjaamAuthor Commented:
Edited text of question
0
 
nietodCommented:
strange but true:   The code

   Cwnd* hAOL = Window.FindWindow (NULL, "AOL");

doesn't use the object Window.  FindWindow() is a static member function of CWnd.  Static member functions do not operate on objects, that is they do not need to be called for a paraticular object, like you appear to be doing there.  Now since they are part if a class, you do need to indicate the class to the compiler, this is because other classes could have functions called FindWindow() so you need to tell the compiler which class's FindWindow()  you are wanting to use.  This is usually done as

   Cwnd* hAOL = CWnd::FindWindow (NULL, "AOL");

That says use the FindWindow() that is part of CWnd.  Note that it is not providing a CWnd for the function to work with.  It doesn't need one.  Now what you had does the same thing, but is missleading to the reader (it certainly was to you)

   Cwnd* hAOL = Window.FindWindow (NULL, "AOL");

That says to the compiler, that you want to use the FindWindow() that is part of the same class as the class that Window belongs to.  It doesn't use Window in any way at run-time.  It just uses it at compile time to figure out what class is involved.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
nietodCommented:
Thus the code

CWnd Window;

   Cwnd* hAOL = Window.FindWindow (NULL, "AOL");

will not change Window in any way.

********************

next problem:  the code

Window.m_hWnd = hAOL;

is not goign to work.  First you should nto change m_hWnd() directly.  (it won't let you anyways).  It must be changed using the Attach() and Dettach() procedures.   like

Window.Attach(SomeHandle);

However, these attach and detach window handles.  You don't have window handles.  You have CWnds

You are given a pointer to a CWnd, why don't you just use that pointer?

0
 
benjaamAuthor Commented:
In the example I gave you (with AOL) it would be possible to use
this pointer. But if I, for example want to change the shape of a window I need

Window.SetWindowRgn(...);

So I need a handle to a window in Window because I want to change this specific window's region.
And is there basically a possibility to give Window a handle with the FindWindow() function?
0
 
nietodCommented:
In MFC you will never have to use a window handle.  (unless maybe you are doing somthing really weird)  You will use window objects instead.

to do

Window.SetWindowRgn(...);

you don't have to worry about the window handle, as long as you obtained "Window" through some sort of MFC mechanism that gives you window objects that are attached to window (that have their window handles set).  

If for some reason you had a window handle and don't have a window object for it you can attach a window object to the handle using Attach().  However, if you are find yourself using attach it probably means that you are making a mistake and are circumventign MFC rather than using it.  There may be exceptions where you really do have to use Attach(), but they should be rare.
0
 
benjaamAuthor Commented:
So please tell me how to obtain Window through a MFC mechanism.
Let's say I want to get AOL's main window (class "AOL Frame25")
into Window.
How do I get it so that I can go on and work with Window to find child windows, change shapes, modify menus or so on?
(C++ is a bit confusing to me because I first made programs using VB and in VB the programs are completely different.)
0
 
nietodCommented:
>>  tell me how to obtain Window through a MFC mechanism
that depends on the circumstances.  ussuallly it is just passed as a parameter to a message handler.
>> Let's say I want to get AOL's main window (class "AOL Frame25")  into Window.
use FindWindow to get a pointer to the CWnd.

>> How do I get it so that I can go on and work with Window to find child windows
use the GetWindow() member function.  You call it once to get the first child using the parent CWnd pointer and GW_CHILD.  Then to get the other children you call it repeatidly using the last child found and GW_HWNDNEXT.  something like

CWnd* Par = CWnd::FindWindow (NULL, "AOL");
CWnd* Child = Par->GetWndow(GW_CHILD);
while (Child)
{
   // Do something with Child.
   Child = Child->GetWindow(GW_HWNDNEXT);
}
0
 
nietodCommented:
>> change shapes, modify menus or so on
on AOL's windows?  you can use the standard MFC commands to do this.  However should you?  If you add new options to AOL's menus will it be able to handle them?  If you resize AOL's windows will it handle it okay?  In general you don't want to muck around in someone else's program unless you absolutely have to.
0
 
benjaamAuthor Commented:
ok...thanks for your help!

I think you really earned your points...:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.