就是通常点开“浏览”按钮,选择文件,选择完文件,我想把这个文件的地址返回到文本框里面,用什么类?
怎么用来的?打开文件选择框是用 openFileDialog 类,后面就不知道了。
求助,谢谢!

解决方案 »

  1.   

    我是要显示文件啊,显示文件所在的地址比如说 c:\\Documents and Settings\\xxk\\Desktop\\123.txt
      

  2.   

    我没用MFC,有没有 不用MFC的 类? 我用的是 win32 application
      

  3.   


    OPENFILENAME ofn;       // common dialog box structure
    char szFile[260];       // buffer for file name
    HWND hwnd;              // owner window
    HANDLE hf;              // file handle// Initialize OPENFILENAME
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFile;
    //
    // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
    // use the contents of szFile to initialize itself.
    //
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = sizeof(szFile);
    ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;// Display the Open dialog box. if (GetOpenFileName(&ofn)==TRUE) 
        hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
            0, (LPSECURITY_ATTRIBUTES) NULL,
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
            (HANDLE) NULL);
      

  4.   

    openFileDialog 类是什么类?win32 application有这个类吗?GetOpenFileName可以实现你要的功能
      

  5.   

    这个是我的代码: private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
     {
     Stream^ myStream;
     OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;  openFileDialog1->InitialDirectory = "c:\\Documents and Settings\\xxk\\Desktop";
     openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
     openFileDialog1->FilterIndex = 2;
     openFileDialog1->RestoreDirectory = true;  if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
     {
     if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
     {
     // Insert code to read the stream here.
     myStream->Close();
     }
     }
    文件对话框打开了,选择一个文件,然后返回它的地址,加点什么?
    比如说要返回到textBox1->Text这个里面
      

  6.   

    7楼:
    不好意思,我的意思是 创建项目的时候选择的 是
    Visual C++     CLR    Windows Forms Application
    我试试你说的GetOpenFileName
      

  7.   


    9楼:
    是Visual studio 2005的 VC++啊 确实就是这样写的 指针符号是有点奇怪 MSDN上都是这么写的