digitalmars.D.learn - Win32 Api: How create Open/"Save as" Dialog?
- Marcone (3/3) Jan 10 2020 How create "Open" and "Save as" Dialog using "Win32 Api" and
- Adam D. Ruppe (4/7) Jan 10 2020 You just call GetOpenFileName or GetSaveFileName.
- Marcone (2/9) Jan 10 2020 Very complicated. Can you send me the simple clear code?
- Mike Parker (2/3) Jan 10 2020 https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialo...
- Marcone (2/6) Jan 11 2020 Not compile in Dlang.
- =?UTF-8?B?UmVuw6k=?= Heldmaier (8/11) Jan 10 2020 Have a look at this website:
- Marcone (5/16) Jan 11 2020 Tha examples in this site don't compile in Dlang. I want Win32
- Marcone (23/26) Jan 11 2020 This code works, but I can't get file Path. Someone can help me?
- John Chapman (10/32) Jan 11 2020 You need to supply a buffer, not a pointer:
- Marcone (25/28) Jan 11 2020 Solution:
- Adam D. Ruppe (4/7) Jan 11 2020 and this should be the length of the array. It may require a case
- Marcone (26/34) Jan 12 2020 Changed! New code with changes working very well:
How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.
Jan 10 2020
On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.You just call GetOpenFileName or GetSaveFileName. here it is in my minigui.d https://github.com/adamdruppe/arsd/blob/master/minigui.d#L6634
Jan 10 2020
On Friday, 10 January 2020 at 14:52:36 UTC, Adam D. Ruppe wrote:On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:Very complicated. Can you send me the simple clear code?How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.You just call GetOpenFileName or GetSaveFileName. here it is in my minigui.d https://github.com/adamdruppe/arsd/blob/master/minigui.d#L6634
Jan 10 2020
On Friday, 10 January 2020 at 15:06:07 UTC, Marcone wrote:Very complicated. Can you send me the simple clear code?https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes
Jan 10 2020
On Friday, 10 January 2020 at 15:44:53 UTC, Mike Parker wrote:On Friday, 10 January 2020 at 15:06:07 UTC, Marcone wrote:Not compile in Dlang.Very complicated. Can you send me the simple clear code?https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes
Jan 11 2020
On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.Have a look at this website: http://www.winprog.org/tutorial/app_two.html It helped me a lot when i once made a simple gui in C. The tutorial is in C, but Win32 Api is C anyway... Most of the examples will probably just compile in D. Win32 Api is really ugly, i think it's a better investment to learn something like GtkD ;)
Jan 10 2020
On Saturday, 11 January 2020 at 00:12:03 UTC, René Heldmaier wrote:On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:Tha examples in this site don't compile in Dlang. I want Win32 Api becouse I want create very smal window gui for simple programs.How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.Have a look at this website: http://www.winprog.org/tutorial/app_two.html It helped me a lot when i once made a simple gui in C. The tutorial is in C, but Win32 Api is C anyway... Most of the examples will probably just compile in D. Win32 Api is really ugly, i think it's a better investment to learn something like GtkD ;)
Jan 11 2020
On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.This code works, but I can't get file Path. Someone can help me? import std; import core.sys.windows.windows; pragma(lib, "comdlg32"); void main(){ OPENFILENAME ofn; wchar* szFileName; (cast(byte*)& ofn)[0 .. ofn.sizeof] = 0; ofn.lStructSize = ofn.sizeof; ofn.hwndOwner = null; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileNameW(&ofn)){ writeln(szFileName); // Print null writeln(ofn.lpstrFile); // Print null } }
Jan 11 2020
On Saturday, 11 January 2020 at 10:34:34 UTC, Marcone wrote:This code works, but I can't get file Path. Someone can help me? import std; import core.sys.windows.windows; pragma(lib, "comdlg32"); void main(){ OPENFILENAME ofn; wchar* szFileName;You need to supply a buffer, not a pointer: wchar[MAX_PATH] szFileName;(cast(byte*)& ofn)[0 .. ofn.sizeof] = 0; ofn.lStructSize = ofn.sizeof; ofn.hwndOwner = null;The above lines are unnecessary as D structs are automatically initialized and lStructSize is already filled in.ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName;It wants a pointer to your buffer: ofn.lpstrFile = szFileName.ptr;ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileNameW(&ofn)){ writeln(szFileName); // Print null writeln(ofn.lpstrFile); // Print nullYou'll need to slice the buffer to the right length: import core.stdc.wchar_ : wcslen; writeln(ofn.lpstrFile[0 .. wcslen(ofn.lpstrFile.ptr)]);} }
Jan 11 2020
On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:How create "Open" and "Save as" Dialog using "Win32 Api" and Dlang? Please send me a simple example code in Dlang. Thank you very much.Solution: import std; import core.sys.windows.windows; pragma(lib, "comdlg32"); // Function askopenfilename() string askopenfilename(const(wchar)* filter = ""){ OPENFILENAME ofn; wchar[1024] szFileName = 0; ofn.lpstrFile = cast(LPWSTR) szFileName; ofn.lpstrFilter = filter; ofn.nMaxFile = MAX_PATH; 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. }
Jan 11 2020
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;
Jan 11 2020
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: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. }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;
Jan 12 2020