Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending messages to child windows from dialog box in another class

Posted on 1998-09-10
3
Medium Priority
?
225 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 100 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

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…
Suggested Courses

886 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