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 to new a doc/view in program with parameters

how to new a doc/view in program with parameters

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
12 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.
  • R Offline
    R Offline
    rgbalpha
    wrote on last edited by
    #1

    Hello, My MFC is MDI program. I have two doctemplate in CMyApp, that is, m_pDocTemplate1 and m_pDocTemplate2. In CMyDoc1, I process some variables m_var, and then send to CMyDoc2 for processing. I handle a command to create a doc of doctemplate2 type. I do as follows: void CMyDoc1::OnCmd() { static_cast(AfxGetApp())->m_pDocTemplate2->OpenDocumentFile(NULL, TRUE); } This can only create a new empty doc/view. But what I need is to create a doc and at the same time, the CMyDoc1::m_var can be sent to CMyDoc2. How can it implement? Does anyone give me some light? Thanks in advance. Best Regards, Haifeng

    S 2 Replies Last reply
    0
    • R rgbalpha

      Hello, My MFC is MDI program. I have two doctemplate in CMyApp, that is, m_pDocTemplate1 and m_pDocTemplate2. In CMyDoc1, I process some variables m_var, and then send to CMyDoc2 for processing. I handle a command to create a doc of doctemplate2 type. I do as follows: void CMyDoc1::OnCmd() { static_cast(AfxGetApp())->m_pDocTemplate2->OpenDocumentFile(NULL, TRUE); } This can only create a new empty doc/view. But what I need is to create a doc and at the same time, the CMyDoc1::m_var can be sent to CMyDoc2. How can it implement? Does anyone give me some light? Thanks in advance. Best Regards, Haifeng

      S Offline
      S Offline
      Sam Hobbs
      wrote on last edited by
      #2

      Can you explain what you need to do from the point of view of a non-programmer? In other words, can you explain the fundamental problem you need to solve without your solution? It might be possible to do what you need to do in a much simpler manner.

      R 1 Reply Last reply
      0
      • S Sam Hobbs

        Can you explain what you need to do from the point of view of a non-programmer? In other words, can you explain the fundamental problem you need to solve without your solution? It might be possible to do what you need to do in a much simpler manner.

        R Offline
        R Offline
        rgbalpha
        wrote on last edited by
        #3

        My project actually is an image search program, as follows: First, user must input the search key words or image, that is, the program gets the m_imagefilename for it. The search image is displayed in a doc. This is CMyDoc1. Then where to search the image, that is, the m_imagedatabase. It is a directory in hard disk. When clicking the search button, the search begins. In the end, the seearch results return. The return value is a list of image name, that is, m_imagelist. The m_imagelist is sent as a parameter to the CMyDoc2 for thumbnail display. When double clicking the thumbnails, the original image is displayed in CMyDoc1. In implementation, I create a MDI project with CMyApp, CMainFrame, CChildFrame, CMyDoc/CMyView, CMyDoc2/CMyView2. In CMyApp, two members are added for doc templates. m_pDocTemplate1, m_pDocTemplate2. The two pointers are for selecting different doc types. CMyDoc/CMyView are mainly for displaying images in original size for query and result. CMyDoc2/CMyView2 are mainly for displaying search results. The results are thumbnails. I use CImageList and the CMyView2 is inherited from CListView. When clicking thumbnails, in the message handler, it should call a function to create a new doc with image name as parameter to create CMyDoc/CMyView for display. That's why I ask the question.

        S 2 Replies Last reply
        0
        • R rgbalpha

          My project actually is an image search program, as follows: First, user must input the search key words or image, that is, the program gets the m_imagefilename for it. The search image is displayed in a doc. This is CMyDoc1. Then where to search the image, that is, the m_imagedatabase. It is a directory in hard disk. When clicking the search button, the search begins. In the end, the seearch results return. The return value is a list of image name, that is, m_imagelist. The m_imagelist is sent as a parameter to the CMyDoc2 for thumbnail display. When double clicking the thumbnails, the original image is displayed in CMyDoc1. In implementation, I create a MDI project with CMyApp, CMainFrame, CChildFrame, CMyDoc/CMyView, CMyDoc2/CMyView2. In CMyApp, two members are added for doc templates. m_pDocTemplate1, m_pDocTemplate2. The two pointers are for selecting different doc types. CMyDoc/CMyView are mainly for displaying images in original size for query and result. CMyDoc2/CMyView2 are mainly for displaying search results. The results are thumbnails. I use CImageList and the CMyView2 is inherited from CListView. When clicking thumbnails, in the message handler, it should call a function to create a new doc with image name as parameter to create CMyDoc/CMyView for display. That's why I ask the question.

          S Offline
          S Offline
          Sam Hobbs
          wrote on last edited by
          #4

          I don't know if I ca help much more but I think your clarification will help others to help you better. I can't spend a lot of time studying this and thinking about it now but if I understand what you are saying then you actually have just one document and view. The first document and view I think is actually for determining what images are to be shown and/or used. For example, for files, the file open dialog is used to determine what file is or files are to be opened. Is that relevant? If not, then I hope someone else can help.

          R 1 Reply Last reply
          0
          • R rgbalpha

            My project actually is an image search program, as follows: First, user must input the search key words or image, that is, the program gets the m_imagefilename for it. The search image is displayed in a doc. This is CMyDoc1. Then where to search the image, that is, the m_imagedatabase. It is a directory in hard disk. When clicking the search button, the search begins. In the end, the seearch results return. The return value is a list of image name, that is, m_imagelist. The m_imagelist is sent as a parameter to the CMyDoc2 for thumbnail display. When double clicking the thumbnails, the original image is displayed in CMyDoc1. In implementation, I create a MDI project with CMyApp, CMainFrame, CChildFrame, CMyDoc/CMyView, CMyDoc2/CMyView2. In CMyApp, two members are added for doc templates. m_pDocTemplate1, m_pDocTemplate2. The two pointers are for selecting different doc types. CMyDoc/CMyView are mainly for displaying images in original size for query and result. CMyDoc2/CMyView2 are mainly for displaying search results. The results are thumbnails. I use CImageList and the CMyView2 is inherited from CListView. When clicking thumbnails, in the message handler, it should call a function to create a new doc with image name as parameter to create CMyDoc/CMyView for display. That's why I ask the question.

            S Offline
            S Offline
            Sam Hobbs
            wrote on last edited by
            #5

            If you were to use the two documents, then I think the first document could call the application and the application could store the necessary data. Then the application could create the second document and view and then it should exit to allow the first document and view to delete themselves.

            1 Reply Last reply
            0
            • R rgbalpha

              Hello, My MFC is MDI program. I have two doctemplate in CMyApp, that is, m_pDocTemplate1 and m_pDocTemplate2. In CMyDoc1, I process some variables m_var, and then send to CMyDoc2 for processing. I handle a command to create a doc of doctemplate2 type. I do as follows: void CMyDoc1::OnCmd() { static_cast(AfxGetApp())->m_pDocTemplate2->OpenDocumentFile(NULL, TRUE); } This can only create a new empty doc/view. But what I need is to create a doc and at the same time, the CMyDoc1::m_var can be sent to CMyDoc2. How can it implement? Does anyone give me some light? Thanks in advance. Best Regards, Haifeng

              S Offline
              S Offline
              Sam Hobbs
              wrote on last edited by
              #6

              I am nearly certain that the MFC documentation explains how to create a new document and view. Have you tried to get answers from the documentation? I know I have found answers to questions such as this by reading the documentation and if necessary I look at the MFC source code.

              R 1 Reply Last reply
              0
              • S Sam Hobbs

                I don't know if I ca help much more but I think your clarification will help others to help you better. I can't spend a lot of time studying this and thinking about it now but if I understand what you are saying then you actually have just one document and view. The first document and view I think is actually for determining what images are to be shown and/or used. For example, for files, the file open dialog is used to determine what file is or files are to be opened. Is that relevant? If not, then I hope someone else can help.

                R Offline
                R Offline
                rgbalpha
                wrote on last edited by
                #7

                Hi, thank you for your help. The file open dialog is actually implemented in ID_FILE_OPEN command. I override this in CMyDoc::OnOpenDocument(). Here I open the image and send to view for display. The problem is that I want to display results. They are a list of images just like std::vector m_imagelist. The CMyDoc can only display images in original size, and it can't display a list of images in only a document. In other words, what I want to do is like the Windows Explorer. It can display images in thumnail.(mine is CMyDoc2/CMyView2), When clicking thumbnails, it open the image in an image viewer.(mine is CMyDoc2/CMyView). The question is how to communicate between them.

                S 1 Reply Last reply
                0
                • R rgbalpha

                  Hi, thank you for your help. The file open dialog is actually implemented in ID_FILE_OPEN command. I override this in CMyDoc::OnOpenDocument(). Here I open the image and send to view for display. The problem is that I want to display results. They are a list of images just like std::vector m_imagelist. The CMyDoc can only display images in original size, and it can't display a list of images in only a document. In other words, what I want to do is like the Windows Explorer. It can display images in thumnail.(mine is CMyDoc2/CMyView2), When clicking thumbnails, it open the image in an image viewer.(mine is CMyDoc2/CMyView). The question is how to communicate between them.

                  S Offline
                  S Offline
                  Sam Hobbs
                  wrote on last edited by
                  #8

                  I was using the file open dialog as an example. I don't think I was refering to yours. So are you saying that you need a treeview on the left and a listview (listcontrol) on the right, like the Windows Explorer, but you need a third window to show the image?

                  R 1 Reply Last reply
                  0
                  • S Sam Hobbs

                    I was using the file open dialog as an example. I don't think I was refering to yours. So are you saying that you need a treeview on the left and a listview (listcontrol) on the right, like the Windows Explorer, but you need a third window to show the image?

                    R Offline
                    R Offline
                    rgbalpha
                    wrote on last edited by
                    #9

                    Yes, it is. I didn't think how to add a tree view. But if possible, the treeview is better. That is I need. Hope suggestion.:)

                    S 1 Reply Last reply
                    0
                    • S Sam Hobbs

                      I am nearly certain that the MFC documentation explains how to create a new document and view. Have you tried to get answers from the documentation? I know I have found answers to questions such as this by reading the documentation and if necessary I look at the MFC source code.

                      R Offline
                      R Offline
                      rgbalpha
                      wrote on last edited by
                      #10

                      MFC documentation has the creation of a new document and views. It is in CDocTemplate::OpenDocumentFile(). There a new document ojbect is created. But there are NOT an easy interface to use. Or you must overrride this function. That is, you have to inherit your own doctemplate class. Then use this class to create the new document/view.

                      1 Reply Last reply
                      0
                      • R rgbalpha

                        Yes, it is. I didn't think how to add a tree view. But if possible, the treeview is better. That is I need. Hope suggestion.:)

                        S Offline
                        S Offline
                        Sam Hobbs
                        wrote on last edited by
                        #11

                        Note that the Windows Explorer (which actually explores files, not windows) uses split windows, which is the most common way to support two views at once. Also note that there is a project type for generating Windows Explorer style applications. At least there is for VC 6 and I assume it is still in later versions.

                        R 1 Reply Last reply
                        0
                        • S Sam Hobbs

                          Note that the Windows Explorer (which actually explores files, not windows) uses split windows, which is the most common way to support two views at once. Also note that there is a project type for generating Windows Explorer style applications. At least there is for VC 6 and I assume it is still in later versions.

                          R Offline
                          R Offline
                          rgbalpha
                          wrote on last edited by
                          #12

                          I got it in VS.Net, and I'll have a try this method. Thank you. Best Regards, Haifeng

                          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