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. How do I post a message to a CDocument?

How do I post a message to a CDocument?

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
5 Posts 4 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.
  • C Offline
    C Offline
    clintsinger
    wrote on last edited by
    #1

    Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint

    M S 2 Replies Last reply
    0
    • C clintsinger

      Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      A document is not a window, so you cannot post arbitrary messages to it. You can send WM_COMMAND messages to it, but only because MFC handles the message routing itself. CDocument is derived from CCmdTarget, which means "can be the target of a WM_COMMAND message" --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber My IntarWeb Homepgae!!!11

      C 1 Reply Last reply
      0
      • C clintsinger

        Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint

        S Offline
        S Offline
        Steve Mayfield
        wrote on last edited by
        #3

        Why don't you just post a message to the MainFrame and then use GetActiveDocument()->UpdateAllViews(...)? Also use (CDocumentClassName *)GetActiveDocument()->SpecialProcessingFunctions(..) in the MainFrame to do any document manipulations which can also be message or timer driven. Steve

        B 1 Reply Last reply
        0
        • S Steve Mayfield

          Why don't you just post a message to the MainFrame and then use GetActiveDocument()->UpdateAllViews(...)? Also use (CDocumentClassName *)GetActiveDocument()->SpecialProcessingFunctions(..) in the MainFrame to do any document manipulations which can also be message or timer driven. Steve

          B Offline
          B Offline
          Bartosz Bien
          wrote on last edited by
          #4

          This way it goes more Frame/Doc/View architecture than the pure Doc/View. ;) I would personally avoid coding logic in the frame window unless it's absolutely needed (which is not the case). The message map in CDocument class can be nicely utilized to handle menu/toolbar/accelerator messages that are related to the document. Try to create message handlers in the classes that own the variables you use in these handlers, so there is nothing like ((CDocumentClassName *)CFrameWnd::GetActiveDocument())->SpecialProcessingFunctions(..), but rather CDocumentClassName::OnSpecial(). :rolleyes: Regards, BB

          1 Reply Last reply
          0
          • M Michael Dunn

            A document is not a window, so you cannot post arbitrary messages to it. You can send WM_COMMAND messages to it, but only because MFC handles the message routing itself. CDocument is derived from CCmdTarget, which means "can be the target of a WM_COMMAND message" --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber My IntarWeb Homepgae!!!11

            C Offline
            C Offline
            clintsinger
            wrote on last edited by
            #5

            Thank you for the clarification. Perhaps you could answer another question. I have a thread that is owned by the CDocument derived class. The threads sole purpose is to wait on some incomming data then update a structure in the document. The problem I was running into is that when I called UpdateAllViews I would ASSERT() because of some issues with multithreaded programs and c++ objects. I thought then that I could just update the data, then post a message to the document which in turn calls UpdateAllViews. That way there wouldn't be a problem. Any suggestions? Cheers, Clint

            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