C++ USES the openfilename openfile dialog usage example

  • 2020-04-02 02:52:25
  • OfStack

This article illustrates the use of C++ using openfilename to open the file dialog box. Specific methods are as follows:

Note that sometimes the dialog box never appears because nMaxFile is not set.

The specific function code is as follows:

char szFileName[MAX_PATH]={0};  
OPENFILENAME openFileName = {0}; 
openFileName.lStructSize = sizeof(OPENFILENAME); 
openFileName.nMaxFile = MAX_PATH;  //This must be set, otherwise the open file dialog will not appear. < br / > openFileName.lpstrFilter = " Text file (*.txt)0*.txt0 All the files (*.*)0*.*00"; 
openFileName.lpstrFile = szFileName; 
openFileName.nFilterIndex = 1; 
openFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 
 
if (::GetOpenFileName(&openFileName)) 

    ::MessageBoxA(hwndDlg, openFileName.lpstrFile, "", MB_OK); 
}

Hope that the article described in the C++ programming to help you.


Related articles: