Solved

Sending messages to child windows from dialog box in another class

Posted on 1998-09-10
3
209 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

17 Experts available now in Live!

Get 1:1 Help Now