diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-18 19:01:56 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-18 19:01:56 -0400 |
| commit | cb4d28cc1cb0e29990e0081fe1245620f3aab955 (patch) | |
| tree | b92a366a823c24a38bd3bb2f0722ed627ccbc15c /redo/dialog_windows.c | |
| parent | b6bf7402abe8d0d88b9db9ccf581425dfe118b2f (diff) | |
Added OpenFile(), the first dialog to be added, and implemented it on Windows... mostly.
Diffstat (limited to 'redo/dialog_windows.c')
| -rw-r--r-- | redo/dialog_windows.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/redo/dialog_windows.c b/redo/dialog_windows.c new file mode 100644 index 0000000..d5b69f7 --- /dev/null +++ b/redo/dialog_windows.c @@ -0,0 +1,40 @@ +// 18 august 2014 + +#include "winapi_windows.h" +#include "_cgo_export.h" + +// this should be reasonable +#define NFILENAME 4096 + +WCHAR *openFile(void) +{ + OPENFILENAMEW ofn; + DWORD err; + WCHAR *filenameBuffer; + + // freed on the Go side + filenameBuffer = (WCHAR *) malloc((NFILENAME + 1) * sizeof (WCHAR)); + if (filenameBuffer == NULL) + xpanic("memory exhausted in OpenFile()", GetLastError()); + filenameBuffer[0] = L'\0'; // required by GetOpenFileName() to indicate no previous filename + ZeroMemory(&ofn, sizeof (OPENFILENAMEW)); + ofn.lStructSize = sizeof (OPENFILENAMEW); + ofn.hwndOwner = NULL; + ofn.hInstance = hInstance; + ofn.lpstrFilter = NULL; // no filters + ofn.lpstrFile = filenameBuffer; + ofn.nMaxFile = NFILENAME + 1; // TODO include + 1? + ofn.lpstrInitialDir = NULL; // let system decide + ofn.lpstrTitle = NULL; // let system decide + // TODO OFN_SHAREAWARE? + // TODO remove OFN_NODEREFERENCELINKS? or does no filters ensure that anyway? + ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_FORCESHOWHIDDEN | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOTESTFILECREATE | OFN_PATHMUSTEXIST; + if (GetOpenFileNameW(&ofn) == FALSE) { + // TODO stringify + err = CommDlgExtendedError(); + if (err == 0) // user cancelled + return NULL; + xpanic("error running open file dialog", GetLastError()); + } + return filenameBuffer; +} |
