做了一个COM,需要FileDialog对话框让用户选择路径,但是ATL中没有,怎么办? ATL只提供了CDialogImpl, 难到要我自己写FileDialog? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Use windows function GetOpenFileName/GetSaveFileNameOPENFILENAME 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);// Initialize the OPENFILENAME members. szFile[0] = '\0'; Ofn.lStructSize = sizeof(OPENFILENAME); Ofn.hwndOwner = hWnd; Ofn.lpstrFilter = szFilter; Ofn.lpstrFile= szFile; Ofn.nMaxFile = sizeof(szFile)/ sizeof(*szFile); Ofn.lpstrFileTitle = szFileTitle; Ofn.nMaxFileTitle = sizeof(szFileTitle); Ofn.lpstrInitialDir = (LPSTR)NULL; Ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT; Ofn.lpstrTitle = szTitle; // Display the Filename common dialog box. The // filename specified by the user is passed // to the CreateEnhMetaFile function and used to // store the metafile on disk. GetSaveFileName(&Ofn); 谢谢,问题已经解决. 感觉GetSaveFileName没有用SHBrowseForFolder , 后面这个函数可以直接获得路径,就是不会用,我还是用的GetSaveFileName. 呵呵 串口数据写不进数据库是什么原因?? 请教大家个关于头文件路径的问题。 clistctl怎样更改网格线的颜色? 窗口右上角的还原图标如何变成最大化图标??? 钩子函数咋才能钩到中文咧? 小弟初学MFC,这个问题哪个大虾可以解决啊? 小小师妹又遇难题,希望各位师哥师姐给予帮助! 用vc6.0自动建立数据源? [高手看进来]控制条问题 PC机向打印机(Epson兼容)发送的信息码是哪种格式的?? m_pMainWnd = new CMainWindow;的语意问题 请问如何旋转一个窗口?? 牛X的人请进!!!
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);// Initialize the OPENFILENAME members.
szFile[0] = '\0';
Ofn.lStructSize = sizeof(OPENFILENAME);
Ofn.hwndOwner = hWnd;
Ofn.lpstrFilter = szFilter;
Ofn.lpstrFile= szFile;
Ofn.nMaxFile = sizeof(szFile)/ sizeof(*szFile);
Ofn.lpstrFileTitle = szFileTitle;
Ofn.nMaxFileTitle = sizeof(szFileTitle);
Ofn.lpstrInitialDir = (LPSTR)NULL;
Ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
Ofn.lpstrTitle = szTitle;
// Display the Filename common dialog box. The
// filename specified by the user is passed
// to the CreateEnhMetaFile function and used to
// store the metafile on disk.
GetSaveFileName(&Ofn);