Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. mfc in a thread

mfc in a thread

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++designhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krishnan V
    wrote on last edited by
    #1

    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

    Y 1 Reply Last reply
    0
    • K Krishnan V

      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

      Y Offline
      Y Offline
      YaronNir
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • Y YaronNir

        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

        K Offline
        K Offline
        Krishnan V
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups