Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

How Do I Process Multiple MDI Windows Simultaneously?

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.
1 Solution
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++.
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)

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.

xyrusAuthor Commented:
Thanks for the help, Salte!

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now