Solved

problem with CWnd and FindWindow

Posted on 1998-07-26
10
723 Views
Last Modified: 2008-02-26
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??
0
Comment
Question by:benjaam
  • 6
  • 4
10 Comments
 

Author Comment

by:benjaam
ID: 1168673
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1168674
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168675
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168676
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
 

Author Comment

by:benjaam
ID: 1168677
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 22

Expert Comment

by:nietod
ID: 1168678
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
 

Author Comment

by:benjaam
ID: 1168679
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168680
>>  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
 
LVL 22

Expert Comment

by:nietod
ID: 1168681
>> 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
 

Author Comment

by:benjaam
ID: 1168682
ok...thanks for your help!

I think you really earned your points...:)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

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 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…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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

16 Experts available now in Live!

Get 1:1 Help Now