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. Problem about opening file

Problem about opening file

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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.
  • C Offline
    C Offline
    Chen XuNuo
    wrote on last edited by
    #1

    LPCTSTR lpszPathName; CFileDialog fileDlg(TRUE); fileDlg.m_ofn.lpstrTitle="Open"; fileDlg.m_ofn.lpstrFilter="BMP Files(*.bmp)\0*.bmp\0\0"; if(fileDlg.DoModal()==IDOK) lpszPathName=fileDlg.GetPathName(); else return; CFile file; if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite)) { AfxMessageBox("File open failed"); return; } Is there something wrong in the codes up? Thankks~

    C 1 Reply Last reply
    0
    • C Chen XuNuo

      LPCTSTR lpszPathName; CFileDialog fileDlg(TRUE); fileDlg.m_ofn.lpstrTitle="Open"; fileDlg.m_ofn.lpstrFilter="BMP Files(*.bmp)\0*.bmp\0\0"; if(fileDlg.DoModal()==IDOK) lpszPathName=fileDlg.GetPathName(); else return; CFile file; if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite)) { AfxMessageBox("File open failed"); return; } Is there something wrong in the codes up? Thankks~

      C Offline
      C Offline
      Chen XuNuo
      wrote on last edited by
      #2

      :confused:The messagebox appears~

      H 1 Reply Last reply
      0
      • C Chen XuNuo

        :confused:The messagebox appears~

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Did you use of debugger for see value of lpszPathName is it correct and valid?


        WhiteSky


        C 1 Reply Last reply
        0
        • H Hamid Taebi

          Did you use of debugger for see value of lpszPathName is it correct and valid?


          WhiteSky


          C Offline
          C Offline
          Chen XuNuo
          wrote on last edited by
          #4

          I want to open a file named "aa" in path C:\Documents and Settings\示例图片\aa I saw the debugger and the content is "C:\Documents and Settings\示例图片\葺葺葺葺葺葺葺葺葺葺葺葺?" Why~?

          D 1 Reply Last reply
          0
          • C Chen XuNuo

            I want to open a file named "aa" in path C:\Documents and Settings\示例图片\aa I saw the debugger and the content is "C:\Documents and Settings\示例图片\葺葺葺葺葺葺葺葺葺葺葺葺?" Why~?

            D Offline
            D Offline
            Dosin
            wrote on last edited by
            #5

            Here is an example of opening a file open dialog box - hope this helps void CFileProc1Dlg::OnOpenBtn() { // TODO: Add your control notification handler code here this->UpdateData(); CFile f; char strFilter[] = { "Files (*.dat)|*.dat|All Files (*.*)|*.*||" }; CFileDialog FileDlg(TRUE, ".dat", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE ) return; CArchive ar(&f, CArchive::load); ar >> m_sample; ar.Close(); } else return; f.Close(); this->UpdateData(FALSE); } -- modified at 0:58 Saturday 14th April, 2007

            C 1 Reply Last reply
            0
            • D Dosin

              Here is an example of opening a file open dialog box - hope this helps void CFileProc1Dlg::OnOpenBtn() { // TODO: Add your control notification handler code here this->UpdateData(); CFile f; char strFilter[] = { "Files (*.dat)|*.dat|All Files (*.*)|*.*||" }; CFileDialog FileDlg(TRUE, ".dat", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE ) return; CArchive ar(&f, CArchive::load); ar >> m_sample; ar.Close(); } else return; f.Close(); this->UpdateData(FALSE); } -- modified at 0:58 Saturday 14th April, 2007

              C Offline
              C Offline
              Chen XuNuo
              wrote on last edited by
              #6

              The problem has been settled.Thanks a lot!

              H 1 Reply Last reply
              0
              • C Chen XuNuo

                The problem has been settled.Thanks a lot!

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                It seems your problem solved.


                WhiteSky


                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