Solved

Sending messages to child windows from dialog box in another class

Posted on 1998-09-10
3
218 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
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

734 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