title: C++ Open file dialog in window
body: <p>I have C++ code to show dialog chooser file. I want to the user can only chooser type file specified. My dialog can show type file specified but the user can input other type file in File name like my picture</p>
  
  <p><a href="https://i.stack.imgur.com/sWRNx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sWRNx.png" alt="enter image description here"></a></p>
  
  <p>So, how can I make the user only input File name and search type file specified in <code>lpstrFilter</code>? OR Can i disable File name box?</p>
  
  <p><strong>This is my code</strong>:</p>
  
  <pre><code>const wchar_t* ChooserFile(const char* typeFile)
  {
      try
      {
          ZeroMemory( &amp;sfn , sizeof( sfn));
          sfn.lStructSize = sizeof ( sfn );
          sfn.hwndOwner = NULL ;
          wchar_t w_syFile[MAX_PATH];
          //mbstowcs(w_syFile, syFile, strlen(syFile)+1);//Plus null
          size_t convertedChars = 0;
          mbstowcs_s(&amp;convertedChars, w_syFile, MAX_PATH, syFile, _TRUNCATE);
          sfn.lpstrFile = w_syFile ;
          sfn.lpstrFile[0] = _T('\0');
          sfn.nMaxFile = sizeof( syFile );
  
          //TypeFile
          sfn.lpstrFilter = TEXT("Microsoft Office Word Documents (*.xlsx)\0*.XLSX\0");
  
          sfn.nFilterIndex =1;
          sfn.lpstrFileTitle = NULL ;
          sfn.nMaxFileTitle = 0 ;
          sfn.lpstrInitialDir=NULL;
  
          //sfn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT|OFN_EXPLORER | OFN_ENABLEHOOK ;
          sfn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_NOVALIDATE|OFN_HIDEREADONLY  ;
          if (GetOpenFileName( &amp;sfn ) != TRUE)
          {
              wstrPathFile = TEXT("");
              return wstrPathFile.c_str();
          }
  
          DWORD  retval=0;
          //BOOL   success; 
          TCHAR  buffer[BUFSIZE]=TEXT(""); 
          TCHAR  buf[BUFSIZE]=TEXT(""); 
          TCHAR** lppPart={NULL};
  
          wchar_t wstrPath[BUFSIZE];
          retval = GetFullPathNameW(sfn.lpstrFile,sfn.nMaxFile,wstrPath,lppPart);
          if (retval==0)
          {
              wstrPathFile = TEXT("");
              return wstrPathFile.c_str();
          }
          std::wstring s(wstrPath);
          wstrPathFile = s;
          wcout&lt;&lt;wstrPathFile&lt;&lt;endl;
          return wstrPathFile.c_str();
      }
      catch (...)
      {
          PrintToFile("ChooserFile","Error");
          wstrPathFile = TEXT("");
          return wstrPathFile.c_str();
      }
  }
  </code></pre>