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. CFileDialog implementation...

CFileDialog implementation...

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
12 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.
  • J jmkhael

    either open the File SAve as from ur dialog or make a member variable, and set it from the outside using a reference or a pointer to ur dialog Papa while (TRUE) Papa.WillLove ( Bebe ) ;

    M Offline
    M Offline
    macmac38
    wrote on last edited by
    #3

    Hmm, sounds tricky.. I make a member variable(m_filename). Do u have a code snip for that? Thanks, Mark

    J 1 Reply Last reply
    0
    • M macmac38

      Hi, i made this "File save as.." dialog window but after this i don'really know how to insert or to connect the given name to my saving function which is in another dialog window? CString szlstfile = fileDlg.GetPathName(); //MainFrm.cpp SaveStream(szlstfile); //ContrDlg.cpp Thanks, Mark

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

      What you have looks fine. Presumably SaveStream() will do something with the filename passed to it. What seems to be the problem?

      M 1 Reply Last reply
      0
      • D David Crow

        What you have looks fine. Presumably SaveStream() will do something with the filename passed to it. What seems to be the problem?

        M Offline
        M Offline
        macmac38
        wrote on last edited by
        #5

        Hi, the problem is to pass the filename from MainFrm.cpp to ControlDlg.cpp Thanks, Mark

        D 1 Reply Last reply
        0
        • M macmac38

          Hi, the problem is to pass the filename from MainFrm.cpp to ControlDlg.cpp Thanks, Mark

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

          Passing variables from one file to another is undefined. I assume you have a class defined in ControlDlg.cpp (e.g., CControlDlg) with at least one public method (e.g., SaveStream). In your CMainFrame class, you'll need an instance of the CControlDlg class, unless the method is static. Now it's just a matter of calling the CControlDlg's method, passing it the filename obtained from CFileDialog.

          M 1 Reply Last reply
          0
          • M macmac38

            Hmm, sounds tricky.. I make a member variable(m_filename). Do u have a code snip for that? Thanks, Mark

            J Offline
            J Offline
            jmkhael
            wrote on last edited by
            #7

            in ur class: class urClass { private: CString m_fileName; /*(or array of char)*/ public: void SetFileName ( CString fileName ) ; }; and from another part of the world where this compile: urClass object; ... object.SetFileName ( "whateverPathToSet" ) ; Papa while (TRUE) Papa.WillLove ( Bebe ) ;

            1 Reply Last reply
            0
            • D David Crow

              Passing variables from one file to another is undefined. I assume you have a class defined in ControlDlg.cpp (e.g., CControlDlg) with at least one public method (e.g., SaveStream). In your CMainFrame class, you'll need an instance of the CControlDlg class, unless the method is static. Now it's just a matter of calling the CControlDlg's method, passing it the filename obtained from CFileDialog.

              M Offline
              M Offline
              macmac38
              wrote on last edited by
              #8

              Yes, thats right. I like to give the filename before data arrived.(it comes from the usb-port). The SaveStream() func is called during runtime when data arrives. How i can do that? I think the filename(variable is stored in RAM).. Thanks, Mark

              D 1 Reply Last reply
              0
              • M macmac38

                Yes, thats right. I like to give the filename before data arrived.(it comes from the usb-port). The SaveStream() func is called during runtime when data arrives. How i can do that? I think the filename(variable is stored in RAM).. Thanks, Mark

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

                Now you've really got me confused. In your OP, the filename was originally coming from CFileDialog::GetPathName(). You then wanted to pass that to the SaveStream() function. Perhaps you could explain in detail what you are after rather than just offer bits and pieces that just get construed along the way.

                A 1 Reply Last reply
                0
                • D David Crow

                  Now you've really got me confused. In your OP, the filename was originally coming from CFileDialog::GetPathName(). You then wanted to pass that to the SaveStream() function. Perhaps you could explain in detail what you are after rather than just offer bits and pieces that just get construed along the way.

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #10

                  I am sorry but thanks for your time. ---------------------------------------------------------------------------- //MainFrm.cpp void CMainFrame::OnDataSaveAs() { CFileDialog dlg(FALSE); CControlDlg cd; dlg.m_ofn.lpstrInitialDir = "F:"; dlg.DoModal(); if ( dlg.DoModal() == IDOK) { CString filename = dlg.GetPathName(); cd.SaveStream(filename); //doesn't work because no data at start } } ----------------------------------------------------------------------- //ControlDlg.cpp includes the main code for scanner void CControlDlg::OndataReady(LPUNKNOWN pDobj) { STGMEDIUM s; long hint = 0L; BOOL r = FALSE; COleDataObject foo; foo.Attach((LPDATAOBJECT)pDobj); r = ReadStream(pDobj, s, foo); if(r){ SaveStream(filename); //saving } } I like the user to choose a filename when my app starts, because this is a control programm for a 3d scanner over USB. When my app starts the scanner takes some scans every few seconds. So if the user select a filename at the start there is no data for the file at the begining. When the scanner sends the datafiles i like to save them incremently. For example: filename choosen is "File", then saved as: File_1 File_2 File_3 .... ..for this the prog has to know the last filename. This all i have to handle.

                  D 1 Reply Last reply
                  0
                  • A Anonymous

                    I am sorry but thanks for your time. ---------------------------------------------------------------------------- //MainFrm.cpp void CMainFrame::OnDataSaveAs() { CFileDialog dlg(FALSE); CControlDlg cd; dlg.m_ofn.lpstrInitialDir = "F:"; dlg.DoModal(); if ( dlg.DoModal() == IDOK) { CString filename = dlg.GetPathName(); cd.SaveStream(filename); //doesn't work because no data at start } } ----------------------------------------------------------------------- //ControlDlg.cpp includes the main code for scanner void CControlDlg::OndataReady(LPUNKNOWN pDobj) { STGMEDIUM s; long hint = 0L; BOOL r = FALSE; COleDataObject foo; foo.Attach((LPDATAOBJECT)pDobj); r = ReadStream(pDobj, s, foo); if(r){ SaveStream(filename); //saving } } I like the user to choose a filename when my app starts, because this is a control programm for a 3d scanner over USB. When my app starts the scanner takes some scans every few seconds. So if the user select a filename at the start there is no data for the file at the begining. When the scanner sends the datafiles i like to save them incremently. For example: filename choosen is "File", then saved as: File_1 File_2 File_3 .... ..for this the prog has to know the last filename. This all i have to handle.

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

                    I assume that OnDataSaveAs() is called when the "Save As" button is clicked, or when the "Save As" menu option is selected. Since this is a user-defined action, it may not have happened by the time your program needs the name of an output file (i.e., when calling SaveStream() from within CControlDlg::OndataReady(). It sounds like you need to check for the existance of an output filename before saving the data. Something like:

                    CControlDlg::OndataReady()
                    {
                    ...
                    if (filename.IsEmpty() == TRUE)
                    {
                    CFileDialog dlg(FALSE);
                    dlg.DoModal();
                    filename = dlg.GetPathName();
                    }
                    ...
                    SaveStream(filename); //saving
                    }

                    You may need to remove like code from the CMainFrame::OnDataSaveAs() function.

                    A 1 Reply Last reply
                    0
                    • D David Crow

                      I assume that OnDataSaveAs() is called when the "Save As" button is clicked, or when the "Save As" menu option is selected. Since this is a user-defined action, it may not have happened by the time your program needs the name of an output file (i.e., when calling SaveStream() from within CControlDlg::OndataReady(). It sounds like you need to check for the existance of an output filename before saving the data. Something like:

                      CControlDlg::OndataReady()
                      {
                      ...
                      if (filename.IsEmpty() == TRUE)
                      {
                      CFileDialog dlg(FALSE);
                      dlg.DoModal();
                      filename = dlg.GetPathName();
                      }
                      ...
                      SaveStream(filename); //saving
                      }

                      You may need to remove like code from the CMainFrame::OnDataSaveAs() function.

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #12

                      Thanks for all. I will try it out.

                      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