https://docs.microsoft.com/zh-cn/windows/desktop/api/commdlg/ns-commdlg-tagofna
lpstrFilter
Type: LPCTSTR
https://blog.csdn.net/weixin_38472903/article/details/78204366
filter格式 "Excel 03文件(*.xls)\0*.xls\0Excel 07文件(*.xlsx)\0*.xlsx\0all files\0*.*\0\0"
nMaxFile
Type: DWORD
The size, in characters, of the buffer pointed to by lpstrFile. The buffer must be large enough to store the path and file name string or strings, including the terminating NULL character. The GetOpenFileName and GetSaveFileName functions return FALSE if the buffer is too small to contain the file information. The buffer should be at least 256 characters long.
文件名长度必须,不然对话框不弹出
OpenDialogFile odf = new OpenDialogFile();odf.structSize = Marshal.SizeOf(odf);
odf.file = new string(new char[256]);
odf.maxFile = odf.file.Length;
odf.fileTitle = new string(new char[64]);
odf.maxFileTitle = odf.fileTitle.Length;
odf.filter = "Excel 03文件(*.xls)\0*.xls\0Excel 07文件(*.xlsx)\0*.xlsx\0all files\0*.*\0\0";
odf.title = "Excel文件选择";
odf.initialDir = "D:\\";
odf.defExt = "xls";
odf.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;