[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MDI with a User Interface Thread

Posted on 1998-09-16
9
Medium Priority
?
406 Views
Last Modified: 2013-11-20
I have a MDI project with several Documents and Views.
I would like to add to the project a CwinThread class (User Interface Thread).
I want this class to have its own message queue (since it different thread),
But the GUI's thread frame should be and behave like regular CMDIChildwns.
How it can be done?
0
Comment
Question by:yoavm
[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
9 Comments
 
LVL 2

Expert Comment

by:milenvk
ID: 1322182
I think there is no way to do that. If you want to achieve that from your separate user interface thread you have to send WM_MDICREATE to the MDI client window, which, however, is created by the main thread and thus it just does not work, i.e. the MDI client window is created in the main thread and cannot produce new MDI windows to another thread. This simply blocks your way to do what you want. But there sure are other solutions to your problem. Can you specify why you need the separate thread? Then maybe some different solution will pop up here :-)
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1322183
You can get around the problem of sending WM_MDICREATE to the MDI client window for creation of the new MDI child window, by calling CreateMDIWindow in the child UI thread. I order to do this, you need to completly write your own code to create the frame and view.

The above is no problem, but here comes the trouble: MFC maintains a thread local map of HWND -> CWnd. If you create a new frame and view in another thread than the main, MFC will ASSERT a lot of places because HWND maps to the wrong CWnd object (a temp one).

I have found a solution to this, and it seems to work ok, but I need to tweek the creation of the child frame a little bit more before posting the solution here.
0
 

Author Comment

by:yoavm
ID: 1322184
to the  piano_boxer:

I would like very much to get this solution.

Thanks,
yoavm
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 4

Expert Comment

by:piano_boxer
ID: 1322185
Nearly done!
Works great now, I just need to insert code to correctly shutdown the child UI thread(s) when closing the mainframe, and make the UI child thread init function support a user supplied CMultiDocTemplate instead of the hardcoded values i use for testing.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1322186
Well.....
At this point I have to say that there is really no reason for creating each view in its own thread. Executing blocking function (Fx: Sleep(10000)), will block the whole MDI user interface anyway. (I suspected that).

I tried to create a toolbar in the context of the child thread, and press a button on it to start executing the blocking function. The function is executed correctly in the context of the child thread BUT still blocks the UI :-(
---
Leave your e-mail here and I'll send the source-code to you (Its really to long to post here).
0
 
LVL 1

Expert Comment

by:Bridge
ID: 1322187
Can I have the source as well;
Bridge@quantec.ltd.uk
0
 

Author Comment

by:yoavm
ID: 1322188
Hi,

My email:  yoavm@ndsoft.com

Thanks.
0
 

Author Comment

by:yoavm
ID: 1322189
Hi,

My email:  yoavm@ndsoft.com

Thanks.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 2000 total points
ID: 1322190
The architecture you suggest is a waste of time. MDI windows are child windows, and will necessarily communicate with their parent window using sent messages. Those sent messages force context switches between the sending thread and the receiving thread, with the sending thread blocking until the receiving thread handles the message.

That's inefficient--you won't get the full multithreading you expect on the thread that owns the child window.

You're _far_ better off with a solution like the MTMDI Sample presents: let the main thread of your application handle the MDI frame window--and even the view. Then, create a child window of the view on a new UI thread.  This creates an extra window, which is also a child--but that child isn't directly involved in the MDI scheme and therefore won't so frequently block on UI messages all the time.  Furhter, it doesn't require any workarounds and results in far simpler and smaller code.

B ekiM


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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

656 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