UI thread for MDI application in MFC
Hi, I'm working on a program that can have many MDI windows all with OpenGL animation in them. I'm using timers to trigger OnDraw() render updates on frames when they are running sequences every 30th of a second or there abouts depending on frame rate set. Anyway, its ok provided i don't have too many windows open. After several window, all with independent timers if i try to open a new window the user interface stops responding or sometimes a window opens after a while. But the timers seem to be taking over the message queue so things other messages don't get a chance to respond. At least thats what I'm assuming is going on.
Therefore, I think I need to take the plung and make each window a UI thread, I'm appy enough with worker threads, but I'm a little confussed how to set up and MDI UI thread given that it uses Document templates with associated document and view classes, so its not a single class i can use like CWinApp, or maybe somewhere it is derived from it. But the architecture is too complicated for me to know how to hook the document/views as CWinThread derived classes and I am not sure where to start the threads? is it within the InitInstance where the document templates are set up? I've read you are supposed to override InitInstance methods of the threads themselves as well somewhere, but the documentation seems vague and I can't find any example source that implements this.
Also, I know that i will probably need to provide semaphores or mutexes for shared data, but i would have thought if they all have their own document classes I may not need to. Although sometimes a Dialog may need to access data from one or more of the documents which will now be running as seperate threads. Sorry about all this rambling, but if anyone has any idea of what i'm talking about and can point me in the right direction I would be very greatful,
Thanks a lot, Dan
Re: UI thread for MDI application in MFC
The problem with your implementation is you Main Message Loop is getting blocked and the best way to be doing is just in the Timer Post a Message of Paint and return immediately and see if that improves the scenario.
Also I am not sure you need to be triggering the OnDraw but windows will but if your requirements is to draw then you need to be working on DC to eliminate the un-visible part of the windows as well.
|All times are GMT +5.5. The time now is 02:45.|