mfc in a thread
-
Hi, I have an existing Win32 console app. I want to now add user interface (MDI) to it, which obviously I would like to be run in a separate thread. I used AfxBeginThread to create a new MFC thread which creates my interface, etc. But, the problem is that in this implementation I do not have any CWinApp object at all, and therefore I cannot use some MFC functions. What is the correct way to create a user interface using MFC in a thread other than the main thread of my app? Thanks, Krishnan
-
Hi, I have an existing Win32 console app. I want to now add user interface (MDI) to it, which obviously I would like to be run in a separate thread. I used AfxBeginThread to create a new MFC thread which creates my interface, etc. But, the problem is that in this implementation I do not have any CWinApp object at all, and therefore I cannot use some MFC functions. What is the correct way to create a user interface using MFC in a thread other than the main thread of my app? Thanks, Krishnan
Hi, there are 2 types of threads in win32/mfc... applications: 1) worker thread. 2) UI thread. your case is the second one, UI thread. all UI threads in MFC application must inherite CWinThread class..... then when you call AfxBeginThread(..) method, you pass your dervied-CWinThread object as the parameter. the CWinThread class, has the method : "InitInstance()" there you must create the proper MDI objects you want to display..... read about UI thread in the MSDN or here... hope this helps ya regards, Yaron Ask not what your application can do for you, Ask what you can do for your application
-
Hi, there are 2 types of threads in win32/mfc... applications: 1) worker thread. 2) UI thread. your case is the second one, UI thread. all UI threads in MFC application must inherite CWinThread class..... then when you call AfxBeginThread(..) method, you pass your dervied-CWinThread object as the parameter. the CWinThread class, has the method : "InitInstance()" there you must create the proper MDI objects you want to display..... read about UI thread in the MSDN or here... hope this helps ya regards, Yaron Ask not what your application can do for you, Ask what you can do for your application
YaronNir wrote: your case is the second one, UI thread. all UI threads in MFC application must inherite CWinThread class..... then when you call AfxBeginThread(..) method, you pass your dervied-CWinThread object as the parameter. the CWinThread class, has the method : "InitInstance()" there you must create the proper MDI objects you want to display..... I have already done that. But, the problem is how do I create a CWinApp object. Since, my app is a console app, I cannot declare a global variable for the CWinApp object. Also that object would be instantiated in the main thread, whereas my UI is in different thread.