?
Solved

How Do I Process Multiple MDI Windows Simultaneously?

Posted on 2003-02-18
3
Medium Priority
?
194 Views
Last Modified: 2010-04-01
Hello, I am a beginner here so pardon my ignorance.  

I have a program in visual basic that is opens 4 MDI child windows.  Each of these windows is able to run its own "process" simultaneously without multithreading.  For example, they are all counting from 1 to 10 simultaneously.  I need to do the same thing in visual c++.  Thus, my question is : firstly, is it possible to run 4 MDI child windows simultaneously each running its own process without resorting to multithreading?  Secondly, how do i do this?

Please advise me. Thanks.
0
Comment
Question by:xyrus
[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
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 7979962
It is impossible, and VB application doesn't work by such way. I guess each VB child window has it's own timer and makes some processing by timer. VB even doesn't have support for multithreading.
The same behaviour can be easily reproduced also in VC++.
0
 
LVL 12

Accepted Solution

by:
Salte earned 400 total points
ID: 7980987
It is possible,

each process do some processing when the window it owns is sent a mesage. So if you send a message M to window handle H then the class that instantiates that window will process this message and if that message includes incrementing a value that is what it does.

You just have to send the same message to each of the windows and have each of the windows being able to process that message.

You don't need real multi-threading to do this, don't even need a separate timer for each window. One shared timer is enough.

You can then either send the message to each window at each timer tick or you can have the timer go 4 times as fast and at tick k let it send to window (k & 3) which will give you a value 0..3 which can be used to index the windows. If you have the handles to the windows in an array then indexing that array with handle[k++ & 3] can be used to send the message to each window at a tick so that at first tick the first window get the message, next tick the second window get the message etc etc...

No real multi-threading is needed to do this. What you need is a timer and an array of all the handles and you either do: SendMessage() and give the handle as handle[k++ & 3] on each tick or you can at each tick send the message to each window:

for (int k = 0; k < 4; ++k)
   ::SendMessage(handle[k],....);

or you can use the class method SendMessage if you use a pointer to the class object instead of the handles in that handle array, the principle is the same:

Window * windows[4]; // initialize with a pointer to each window.

windows[k++ & 3] -> SendMessage(...);

or for (int k = 0; k < 4; ++k) windows[k] -> SendMessage(...);

For the two ways to do it.

The two ways differ in that Method one with windows[k++ & 3] will have each incrment its counter at a slightly different time than the other windows (you will notice it better if you let the timer go slow) while using method 2 will cause them to increment at approximately the same time even if the timer is slow.

Each window receive that message, increment the counter and invalidates the display so that it will paint itself with the new value. Fairly standard windows stuff.

Alf
0
 

Author Comment

by:xyrus
ID: 7990983
Thanks for the help, Salte!
0

Featured Post

Industry Leaders: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

764 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