小白求助,VS2005获取文件地址,怎么弄? 就是通常点开“浏览”按钮,选择文件,选择完文件,我想把这个文件的地址返回到文本框里面,用什么类?怎么用来的?打开文件选择框是用 openFileDialog 类,后面就不知道了。求助,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是要显示文件啊,显示文件所在的地址比如说 c:\\Documents and Settings\\xxk\\Desktop\\123.txt 我没用MFC,有没有 不用MFC的 类? 我用的是 win32 application OPENFILENAME ofn; // common dialog box structurechar szFile[260]; // buffer for file nameHWND hwnd; // owner windowHANDLE hf; // file handle// Initialize OPENFILENAMEZeroMemory(&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); openFileDialog 类是什么类?win32 application有这个类吗?GetOpenFileName可以实现你要的功能 这个是我的代码: 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这个里面 7楼:不好意思,我的意思是 创建项目的时候选择的 是Visual C++ CLR Windows Forms Application我试试你说的GetOpenFileName 9楼:是Visual studio 2005的 VC++啊 确实就是这样写的 指针符号是有点奇怪 MSDN上都是这么写的 请有打印心得的高手指教:如何实现A4(210*297)纸的全纸打印,也就是处理掉打印机的物理边距,请看问题的详细描述。 set_LastError这个是什麽意思 怎样通过Button控件的HWND判断Button类型??把按钮和Radio和Group box区分开。 在标签中没有显示图标,如何解决? 如何模仿鼠标对其他的进程进行操作 怎么把数组转换成整数? 请问如何得到bitmap某一点像素的RGB值? 已知字符串指针和它的长度,如何把这个字符串截取出来? 求atl电子书 在其他进程中SetWindowLong,导致界面不能显示? 请教如何获取系统消息的问题 在不同电脑上的程序运行问题
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);
{
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这个里面
不好意思,我的意思是 创建项目的时候选择的 是
Visual C++ CLR Windows Forms Application
我试试你说的GetOpenFileName
9楼:
是Visual studio 2005的 VC++啊 确实就是这样写的 指针符号是有点奇怪 MSDN上都是这么写的