Solved

MDI with a User Interface Thread

Posted on 1998-09-16
9
393 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 1000 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 379
How to know only "File created" with EventLog 3 32
no14 challenge 14 62
mapBully challenge 6 114
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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now