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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Where to place handler? CView/CDoc/Mainfrm?

Where to place handler? CView/CDoc/Mainfrm?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • O Offline
    O Offline
    oRion
    wrote on last edited by
    #1

    It seems that I could create handlers in these files, that I could used. They are quite similiar in nature, seems to me most of functions are visible to all CView/CDoc/Mainfrm? Anyone care to share what's the different between these files?

    J J 2 Replies Last reply
    0
    • O oRion

      It seems that I could create handlers in these files, that I could used. They are quite similiar in nature, seems to me most of functions are visible to all CView/CDoc/Mainfrm? Anyone care to share what's the different between these files?

      J Offline
      J Offline
      James Pullicino
      wrote on last edited by
      #2

      Document hold document data Main Frame is the main applications window Views are windows which display the documents data and are children of the Main Frame. I am assuming that by 'handlers' you are reffering to message handlers. You have two options: either put your handlers in your Main Frame, or put your handlers in your View. Very rarely will you need to add handlers to your Document since it does not make too much sense. In reality you will be putting handlers in both your mainframe and your views. Do you want your handler to work in every view or in only one type of view (this is only applicable when you have multiple views, i.e. MDI application). If you want a 'global' handler then add it to your main frame, if you want a 'local' handler (local to a view type), then add the handler to your view. Also consider the type of access you need in your handler. If you need access to the Document data for example, it will be easier to put your handler inside your view since access to the document from a view is easier than from the main frame. This applies mostly to MDI applications. (SDI applications are much simpler since you can assume only one document, thus making it easier to locate from the mainframe) In summery, treat every handler differently. Think about what the handler will be used for (logically) so that you can decide whether it should be a 'global' or 'local' handler. Think about the access requirements (do you need access to the document? Do you need access to the MainFrame?). One final tip: Observe and learn the code which ClassWizard generates so that you can modify it and move it around if neccessary. James Pullicino Drinking In The Sun Forgot Password?

      1 Reply Last reply
      0
      • O oRion

        It seems that I could create handlers in these files, that I could used. They are quite similiar in nature, seems to me most of functions are visible to all CView/CDoc/Mainfrm? Anyone care to share what's the different between these files?

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        If you talk about ON_COMMAND handlers and such, as I guess, you are free to place them where they are the most "natural". CDoc is great if you need access to the Data your application is working on, in CView you handle a button like "Redraw", which is only interesting for the View. Generally, if you need ugly casts, you should look for a better site of the handler (but sometimes you just HAVE TO cast).

        O 1 Reply Last reply
        0
        • J jhwurmbach

          If you talk about ON_COMMAND handlers and such, as I guess, you are free to place them where they are the most "natural". CDoc is great if you need access to the Data your application is working on, in CView you handle a button like "Redraw", which is only interesting for the View. Generally, if you need ugly casts, you should look for a better site of the handler (but sometimes you just HAVE TO cast).

          O Offline
          O Offline
          oRion
          wrote on last edited by
          #4

          Thanks for your replies guys! Just want to make sure we are talking the same thing here. Basically I am confused about where to place my menuitem handler, ie, OnMyMenuItem. They could exist in all the DOC/VIEW/MainFrm, and the functions are accessible in all of them also. Just don't know the different between them. I am working in with a SDI program. So probably, I will be working either with CView/CDoc or Mainfrm/CDoc , right? There isn't much different with CView and Mainfrm since they are the same? ;)

          J 1 Reply Last reply
          0
          • O oRion

            Thanks for your replies guys! Just want to make sure we are talking the same thing here. Basically I am confused about where to place my menuitem handler, ie, OnMyMenuItem. They could exist in all the DOC/VIEW/MainFrm, and the functions are accessible in all of them also. Just don't know the different between them. I am working in with a SDI program. So probably, I will be working either with CView/CDoc or Mainfrm/CDoc , right? There isn't much different with CView and Mainfrm since they are the same? ;)

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            For me, the CMainFrame(-derived) class is something technical, which tends to be almost empty. It is not concerned with the data of my application, rather with window-drawing issues. My application data is stored in the CDoc, and most manipulation routines are there. My CView get the data (or rather references to it) and put it on the screen in a ordered fashion (like vector of numbers to line plot). So - my menu handlers are almost always in CView/CDoc, and CMainFrame is empty and boring.

            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