Win32 Api: How create Open/"Save as" Dialog?

Marcone marcone at email.com
Sat Jan 11 10:34:34 UTC 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
     }
}


More information about the Digitalmars-d-learn mailing list