[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

problem with CWnd and FindWindow

Posted on 1998-07-26
10
Medium Priority
?
803 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 

Author Comment

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

Accepted Solution

by:
nietod earned 150 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

656 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