求打开文件对话框的Window api

DDrddr 2003-10-15 03:22:46
不用 MFC的
...全文
248 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2003-10-15
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
// <打开旧文件>对话框的结构设置函数
bool ShowOpenDialog(HWND HWndOwner, char *FileName, char *Title,
char *InitialDir, char *Filter)
{
//声明OPENFILENAME结构
OPENFILENAME ofn;
//先整理结构位置内容
ZeroMemory(&ofn, sizeof(OPENFILENAME));
char szFile[MAX_PATH];
ZeroMemory(szFile, MAX_PATH);
//开始设置OPENFILENAME结构成员
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = HWndOwner;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = Filter;
ofn.nFilterIndex = 0;
ofn.lpstrTitle = Title;
ofn.lpstrInitialDir = InitialDir;
//此对话框具有新窗口风格、多重选取文件与自定义信息内容
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK;
//自定义信息内容
ofn.lpfnHook = OFNHookProc;
//填完结构成员后,指派给"打开"对话框,并显示对话框
if (::GetOpenFileName(&ofn))
{
//若有选取到文件,则返回文件名称与真值
strcpy(FileName, ofn.lpstrFile);
return true;
}
//否则返回伪值
return false;
}
//---------------------------------------------------------------------------
DDrddr 2003-10-15
  • 打赏
  • 举报
回复
example??
domustdo 2003-10-15
  • 打赏
  • 举报
回复
The GetOpenFileName function creates an Open common dialog box that lets the user specify the drive, directory, and the name of a file or set of files to open.

BOOL GetOpenFileName(
LPOPENFILENAME lpofn // address of structure with initialization data
);


Parameters

lpofn

Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user's file selection.



Return Values

If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.
If the user cancels or closes the Open dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

CDERR_FINDRESFAILURE CDERR_NOHINSTANCE
CDERR_INITIALIZATION CDERR_NOHOOK
CDERR_LOCKRESFAILURE CDERR_NOTEMPLATE
CDERR_LOADRESFAILURE CDERR_STRUCTSIZE
CDERR_LOADSTRFAILURE FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAILURE FNERR_INVALIDFILENAME
CDERR_MEMLOCKFAILURE FNERR_SUBCLASSFAILURE

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧