January 11, 2020 Re: Win32 Api: How create Open/"Save as" Dialog? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcone | On Saturday, 11 January 2020 at 12:22:25 UTC, Marcone wrote: > wchar[1024] szFileName = 0; > ofn.lpstrFile = cast(LPWSTR) szFileName; You shouldn't cast there, just use `szFileName.ptr` instead. > ofn.nMaxFile = MAX_PATH; and this should be the length of the array. It may require a case nMaxFile = cast(DWORD) szFileName.length; |
January 12, 2020 Re: Win32 Api: How create Open/"Save as" Dialog? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Saturday, 11 January 2020 at 14:21:25 UTC, Adam D. Ruppe wrote: > On Saturday, 11 January 2020 at 12:22:25 UTC, Marcone wrote: >> wchar[1024] szFileName = 0; >> ofn.lpstrFile = cast(LPWSTR) szFileName; > > You shouldn't cast there, just use `szFileName.ptr` instead. > >> ofn.nMaxFile = MAX_PATH; > > and this should be the length of the array. It may require a case > > nMaxFile = cast(DWORD) szFileName.length; Changed! New code with changes working very well: import std; import core.sys.windows.windows; pragma(lib, "comdlg32"); // Function askopenfilename() string askopenfilename(const(wchar)* filter = "All Files (*.*)\0*.*\0"){ OPENFILENAME ofn; wchar[1024] szFileName = 0; ofn.lpstrFile = szFileName.ptr; ofn.lpstrFilter = filter; ofn.nMaxFile = cast(DWORD) szFileName.length; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if (GetOpenFileNameW(&ofn)){ return to!string(szFileName[0..szFileName.indexOf('\0')]); } else { return ""; } } void main(){ writeln(askopenfilename()); // Call without filter. writeln(askopenfilename("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0")); // Cal using filter. } |
Copyright © 1999-2021 by the D Language Foundation