是的,可以从 VC++ 控制台应用程序打开 OpenDialog。
步骤:
创建一个新项目。 -> 选择 Win32 控制台应用程序。
在下一个对话框中,选择“支持 MFC 的应用程序”。
您将获得以下代码:
#include "stdafx.h"
#include "test.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
静态字符 THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////// //////////////////////////
// 唯一的应用程序对象
CWinApp theApp;
使用命名空间标准;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
return nRetCode;
}
在“else”部分开头添加如下代码
CFileDialog dlgOpen(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"文本文件 (.txt)|.txt||");
dlgOpen.DoModal();
运行应用程序。将自动打开一个打开的对话框。谷歌“CFileDialog”以获得更多帮助。