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. Updating View from WinThread

Updating View from WinThread

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++announcementworkspace
3 Posts 3 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.
  • J Offline
    J Offline
    J Guds
    wrote on last edited by
    #1

    I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University

    D C 2 Replies Last reply
    0
    • J J Guds

      I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      The UI is "owned" by the primary thread and should only be updated by it. All other threads should post (not send) a message to the primary thread indicating an update needs to be done. Check out this article.


      A rich person is not the one who has the most, but the one that needs the least.

      1 Reply Last reply
      0
      • J J Guds

        I'm developing a VC++ SDI program that needs to have a couple threads running. The main thread starts by pressing a button in the toolbar which is processed in the Document. This thread reads from a data file once a second, this data is stored as variables in the Document, after this data is read and stored I need to update the View, however I have not been successful at having the View update with out crashing the program. I have the program setup as a SDI and have added a CWinThread Class. I have been successfull at reading the data with the class but just not updating the View. Any help with this problem would be great. J Guds Masters Student Kansas University

        C Offline
        C Offline
        chifor
        wrote on last edited by
        #3

        I suggest you to take a luck at example from “msdn” documentation “MTMDI” that demonstrates an MFC User Interface Thread. For avoiding potential problems when programming multithreaded applications you need to respect some rolls or programming tips that is also described in “mfc” documentation. Ex: - You can't have two threads manipulating the same object.., if you need this you need to protect such access with appropriate Win32 synchronization mechanisms... - A thread can access only MFC objects that it created, a worker thread cannot perform a calculation and then call a document’s “UpdateAllViews” member function to have the windows that contain views on the new data modified, because the map from CWnd objects to HWNDs is local to the primary thread. There are several ways around this problem: you can pass individual handles (such as an HWND) rather than C++ objects to the worker thread, or you can create new user-defined messages corresponding to the different tasks your worker threads will be performing and post these messages to the application’s main window using PostMessage. If this little help is not enough for your problem send me a sample of your code and I will help you. CC.

        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