Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CFileDialog

When I bring up a window for file save or open, the default titles of the window are "Save As" or "Open." How can I customize those titles? Thanks in advance.
0 Kudos
Message 1 of 3
(3,236 Views)
Just set 'lpstrTitle' to your own specified string.

void CSampleDlg::OnButton1()
{
OPENFILENAME ofn = {0};
char szName[MAX_PATH];
*szName = 0;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = AfxGetApp()->m_pMainWnd->m_hWnd;
ofn.lpstrFilter = NULL;
ofn.lpstrFilter = "Text files (*.txt)\0*.txt\0All files (*.*)\0*.*\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = &szName[0];
ofn.nMaxFile = MAX_PATH;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = "This is My Title to replace the default title";
ofn.lpstrFileTitle = NULL;
ofn.lpstrDefExt = "TXT";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_EXPLORER;


if (GetOpenFileName(&ofn)){
CString SelectedFile = ofn.lpstrFile;

// Do something with file
}
}
Message 2 of 3
(3,236 Views)
THANK YOU, mps!
0 Kudos
Message 3 of 3
(3,236 Views)