要求实现一个保存文件的对话框,但无保存文件类型的选项。
4 个解决方案
#1
up
#2
GetSaveFileName
函数功能:该函数创建一个Save公共对话框,以便用户指定驱动器、目录和文件名。
函数原型:BOOL GetSaveFileName(LPOPENFILENAME Ipofn);
参数:
Ipofn:指向一个包含初始化对话框信息的OPENFILENAME结构。当GetsaveFileName函数返回时,此结构含有关于用户文件选择的信息。
返回值:如果用户指定了一个文件名且点击OK按钮,返回值为非零值。由OPENFILENAME结构中的IpstrFile成员指向的缓冲区含有全路径和用户指定的文件名。如果用户取消或关闭Save对话框或错误出现,返回值为零。若想获得有关更多的错误信息,请调用CommDlgExtendError函数,其返回值同GetOpenFileName返回值。
函数功能:该函数创建一个Save公共对话框,以便用户指定驱动器、目录和文件名。
函数原型:BOOL GetSaveFileName(LPOPENFILENAME Ipofn);
参数:
Ipofn:指向一个包含初始化对话框信息的OPENFILENAME结构。当GetsaveFileName函数返回时,此结构含有关于用户文件选择的信息。
返回值:如果用户指定了一个文件名且点击OK按钮,返回值为非零值。由OPENFILENAME结构中的IpstrFile成员指向的缓冲区含有全路径和用户指定的文件名。如果用户取消或关闭Save对话框或错误出现,返回值为零。若想获得有关更多的错误信息,请调用CommDlgExtendError函数,其返回值同GetOpenFileName返回值。
#3
char c_filename[256];
memset(c_filename,0,256);
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = Form1->Handle;
ofn.hInstance = Application->Handle;
ofn.lpstrFilter = "Database file(*.jdb)|*.jdb\0";
ofn.lpstrFileTitle = c_filename;
ofn.nMaxFileTitle = 256;
ofn.lpstrFile = c_filename;
ofn.nMaxFile = 256;
ofn.lpstrTitle = "Select a file to open...";
ofn.Flags = OFN_FILEMUSTEXIST|OFN_EXPLORER;
GetSaveFileName(&ofn);
memset(c_filename,0,256);
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = Form1->Handle;
ofn.hInstance = Application->Handle;
ofn.lpstrFilter = "Database file(*.jdb)|*.jdb\0";
ofn.lpstrFileTitle = c_filename;
ofn.nMaxFileTitle = 256;
ofn.lpstrFile = c_filename;
ofn.nMaxFile = 256;
ofn.lpstrTitle = "Select a file to open...";
ofn.Flags = OFN_FILEMUSTEXIST|OFN_EXPLORER;
GetSaveFileName(&ofn);
#4
INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, INT nShowCmd)
{
TCHAR szFilename[MAX_PATH] = TEXT("");
BOOL bResult = FALSE;
DWORD dwError = NOERROR;
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrFilter = TEXT("All Files\0*.*\0\0");
ofn.lpstrFile = szFilename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER |
OFN_ENABLEHOOK |
OFN_HIDEREADONLY |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST;
ofn.lpfnHook = (LPOFNHOOKPROC) SaveAsHookProc;
bResult = GetSaveFileName (&ofn);
if (bResult == FALSE)
{
dwError = CommDlgExtendedError ();
return dwError;
}
MessageBox (NULL, szFilename, TEXT("SaveAs returned..."), MB_OK);
return 0;
}
LPSTR lpCmdLine, INT nShowCmd)
{
TCHAR szFilename[MAX_PATH] = TEXT("");
BOOL bResult = FALSE;
DWORD dwError = NOERROR;
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrFilter = TEXT("All Files\0*.*\0\0");
ofn.lpstrFile = szFilename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER |
OFN_ENABLEHOOK |
OFN_HIDEREADONLY |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST;
ofn.lpfnHook = (LPOFNHOOKPROC) SaveAsHookProc;
bResult = GetSaveFileName (&ofn);
if (bResult == FALSE)
{
dwError = CommDlgExtendedError ();
return dwError;
}
MessageBox (NULL, szFilename, TEXT("SaveAs returned..."), MB_OK);
return 0;
}
#1
up
#2
GetSaveFileName
函数功能:该函数创建一个Save公共对话框,以便用户指定驱动器、目录和文件名。
函数原型:BOOL GetSaveFileName(LPOPENFILENAME Ipofn);
参数:
Ipofn:指向一个包含初始化对话框信息的OPENFILENAME结构。当GetsaveFileName函数返回时,此结构含有关于用户文件选择的信息。
返回值:如果用户指定了一个文件名且点击OK按钮,返回值为非零值。由OPENFILENAME结构中的IpstrFile成员指向的缓冲区含有全路径和用户指定的文件名。如果用户取消或关闭Save对话框或错误出现,返回值为零。若想获得有关更多的错误信息,请调用CommDlgExtendError函数,其返回值同GetOpenFileName返回值。
函数功能:该函数创建一个Save公共对话框,以便用户指定驱动器、目录和文件名。
函数原型:BOOL GetSaveFileName(LPOPENFILENAME Ipofn);
参数:
Ipofn:指向一个包含初始化对话框信息的OPENFILENAME结构。当GetsaveFileName函数返回时,此结构含有关于用户文件选择的信息。
返回值:如果用户指定了一个文件名且点击OK按钮,返回值为非零值。由OPENFILENAME结构中的IpstrFile成员指向的缓冲区含有全路径和用户指定的文件名。如果用户取消或关闭Save对话框或错误出现,返回值为零。若想获得有关更多的错误信息,请调用CommDlgExtendError函数,其返回值同GetOpenFileName返回值。
#3
char c_filename[256];
memset(c_filename,0,256);
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = Form1->Handle;
ofn.hInstance = Application->Handle;
ofn.lpstrFilter = "Database file(*.jdb)|*.jdb\0";
ofn.lpstrFileTitle = c_filename;
ofn.nMaxFileTitle = 256;
ofn.lpstrFile = c_filename;
ofn.nMaxFile = 256;
ofn.lpstrTitle = "Select a file to open...";
ofn.Flags = OFN_FILEMUSTEXIST|OFN_EXPLORER;
GetSaveFileName(&ofn);
memset(c_filename,0,256);
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = Form1->Handle;
ofn.hInstance = Application->Handle;
ofn.lpstrFilter = "Database file(*.jdb)|*.jdb\0";
ofn.lpstrFileTitle = c_filename;
ofn.nMaxFileTitle = 256;
ofn.lpstrFile = c_filename;
ofn.nMaxFile = 256;
ofn.lpstrTitle = "Select a file to open...";
ofn.Flags = OFN_FILEMUSTEXIST|OFN_EXPLORER;
GetSaveFileName(&ofn);
#4
INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, INT nShowCmd)
{
TCHAR szFilename[MAX_PATH] = TEXT("");
BOOL bResult = FALSE;
DWORD dwError = NOERROR;
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrFilter = TEXT("All Files\0*.*\0\0");
ofn.lpstrFile = szFilename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER |
OFN_ENABLEHOOK |
OFN_HIDEREADONLY |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST;
ofn.lpfnHook = (LPOFNHOOKPROC) SaveAsHookProc;
bResult = GetSaveFileName (&ofn);
if (bResult == FALSE)
{
dwError = CommDlgExtendedError ();
return dwError;
}
MessageBox (NULL, szFilename, TEXT("SaveAs returned..."), MB_OK);
return 0;
}
LPSTR lpCmdLine, INT nShowCmd)
{
TCHAR szFilename[MAX_PATH] = TEXT("");
BOOL bResult = FALSE;
DWORD dwError = NOERROR;
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrFilter = TEXT("All Files\0*.*\0\0");
ofn.lpstrFile = szFilename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER |
OFN_ENABLEHOOK |
OFN_HIDEREADONLY |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST;
ofn.lpfnHook = (LPOFNHOOKPROC) SaveAsHookProc;
bResult = GetSaveFileName (&ofn);
if (bResult == FALSE)
{
dwError = CommDlgExtendedError ();
return dwError;
}
MessageBox (NULL, szFilename, TEXT("SaveAs returned..."), MB_OK);
return 0;
}