Solved

Sending messages to child windows from dialog box in another class

Posted on 1998-09-10
3
212 Views
Last Modified: 2010-08-05
Hi...

I need to know how for example to create a new child window in an mdi application from a click on a button in a modeless
dialog box with its own class
and not by..clicking the menu buttons or toolbar buttons. Do i have to post messages to my main frame/client window then
send messages to my child window again....

please please help...i'm stuck
p.s i'm using visualc++, mdi class wizard to create my program
0
Comment
Question by:ramesh_mirpuri
  • 2
3 Comments
 
LVL 2

Expert Comment

by:duneram
ID: 1172449
Windows is event driven.

If the user presses a button, you should create the window at that point in time.  If you choose to send messages, its better to use the PostMessage api to do it.  Why?  its asynchronous when you do it that way

In your MainFrm.cpp file take a look in classwizard for
ID_FILE_OPEN
use it to create a function.  You basically want this functionality to execute whenever this event is suppsoed to happen.


0
 
LVL 1

Accepted Solution

by:
softev earned 50 total points
ID: 1172450
The most common way is to PostMessage and add a message
handler for the specific message sent into the object you
want to open the window.  

If this is or will become common functionality in your application, consider setting up your "own" notification system.
Base it on Posting user defined messages ( WM_USER+ some number for each distinct message ) and catch them in areas of the application that will deal directly with that message.

You can easily acheive this by placing a message manager in
your main application and registering every object ( or window )
that you would have process a given message.  For example, use a
pMainApp->RegisterMe( this ) type of call to register the window.
All you will need is a Object pointer array in the main app
to store registered objects. All notification messages get sent like this from other objects pMainApp->SendNotify( WM_USER + 123 ).  When MainApp gets the notification it can send it down directly to objects that are interested
in receiving it ( in the array ).



0
 
LVL 2

Expert Comment

by:duneram
ID: 1172451
I would say you would in general be better off using RegisterWindowsMessage for your unique message ID's.  if you use that API you are guaranteed uniqueness....   If you use the WM_USER+... there is a chance you may walk on something else or vice versa..  If a different app uses the same one you pick and happens to use HWND_BROADCAST you would then respond to his message thinking its your message.  RegisterWindowsMessage is a better way to go.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 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

19 Experts available now in Live!

Get 1:1 Help Now