Home > other >  C # to get GetOpenFileName multiple-choice file name
C # to get GetOpenFileName multiple-choice file name

Time:09-21

Use GetOpenFileName access to the file name, how to choose more filename preserved,

CodePudding user response:

#include

Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
OPENFILENAME ofn;
TCHAR szOpenFileNames [80 * MAX_PATH];
TCHAR szPath [MAX_PATH];
TCHAR szFileName [80 * MAX_PATH];
TCHAR * p;
Int nLen=0;

ZeroMemory (& amp; Ofn, sizeof (ofn));
Ofn. Flags=OFN_EXPLORER | OFN_ALLOWMULTISELECT;
Ofn. LStructSize=sizeof (ofn);
Ofn. LpstrFile=szOpenFileNames;
Ofn. NMaxFile=sizeof (szOpenFileNames);
Ofn. LpstrFile [0]='/0;
Ofn. LpstrFilter=TEXT (" All Files (*. *)/0 *. */0 ");

If (GetOpenFileName (& amp; Ofn))
{
//copy before the first name of the file to the szPath, namely:
//if only one file, then copy to the last '/'
//if choose multiple files, then copy to the first NULL character
Lstrcpyn (szPath, szOpenFileNames ofn. NFileOffset);
//when choose a document, the following NULL character is required.
//there is no distinction between chose a and multiple files
SzPath [ofn nFileOffset]='/0;
NLen=lstrlen (szPath);

If (szPath [nLen - 1].='//')//if the multiple files, you must add "//"
{
Lstrcat (szPath, TEXT ("//"));
}

P=szOpenFileNames + ofn. NFileOffset;//move the pointer to the first file

ZeroMemory (szFileName, sizeof (szFileName));
While (* p)
{
Lstrcat (szFileName, szPath);//to the file name and path
Lstrcat (szFileName, p);//plus the file name
Lstrcat (szFileName, TEXT ("/n "));//line breaks
P +=lstrlen (p) + 1;//move to the next file
}
MessageBox (NULL, szFileName, TEXT (" MultiSelect "), MB_OK);
}
}


This is a c + + code, not quite understand

CodePudding user response:

Public void onclick ()
{
OpenFileDialog ofd=new OpenFileDialog (); One way to//new
Ofd. InitialDirectory="file://" + UnityEngine. Application. DataPath; Open//define the default folder open//define the default folder location
Ofd. Multiselect=true;

If (ofd. ShowDialog ()==DialogResult. OK)
{
//show the window of the open file
Foreach (string file in ofd. FileNames)
{
The Debug Log (file);
}
}
}

Unity is used in the

Out of the window is not win32
  • Related