最近写win32程序, 经常要用打开和保存对话框,每次都要查msdn看参数,太麻烦了,干脆贴在这里,以后copy和paste一下就ok了:
打开文件对话框
TCHAR szFile[MAX_PATH] = {0};
OPENFILENAME Ofn;
ZeroMemory(&Ofn, sizeof(Ofn));
Ofn.lStructSize = sizeof(OPENFILENAME);
Ofn.hwndOwner = m_hWnd;
Ofn.lpstrFilter = TEXT("Text File (*.txt)\0*.txt\0\0");
Ofn.lpstrDefExt = TEXT(".txt");
Ofn.lpstrFile= szFile;
Ofn.nMaxFile = sizeof(szFile);
Ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if ( GetOpenFileName(&Ofn) )
{
::SetDlgItemText(m_hWnd, IDC_EDIT_SRCFILE, Ofn. lpstrFile);
}
|
保存文件对话框:
TCHAR szFile[MAX_PATH] = {0};
OPENFILENAME Ofn;
ZeroMemory(&Ofn, sizeof(Ofn));
Ofn.lStructSize = sizeof(OPENFILENAME);
Ofn.hwndOwner = m_hWnd;
Ofn.lpstrFilter = TEXT("Text File (*.txt)\0*.txt\0\0");
Ofn.lpstrDefExt = TEXT(".txt");
Ofn.lpstrFile= szFile;
Ofn.nMaxFile = sizeof(szFile);
Ofn.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
if ( GetSaveFileName(&Ofn) )
{
::SetDlgItemText(m_hWnd, IDC_EDIT_DSTFILE, Ofn. lpstrFile);
}
|
author: thinkere-mail:
cnhnyugmail.comqq: 94483026
阅读(721) | 评论(0) | 转发(0) |