Blame view

legacy/rts_winFileDialog.cpp 2.45 KB
f1402849   dmayerich   renewed commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  /*Make sure to not use Unicode characters.  Using the Unicode character set does some

  strange stuff unless you change the character pointers to LPWSTR and LPWCHAR

  */

  

  #include <iostream>

  using namespace std;

  

  

  #pragma comment( lib, "comctl32" )

  

  #include <windows.h>

  #include <commctrl.h>

  #include <commdlg.h>

  #include <rts_winFileDialog.h>

  

  bool rtsOpenFileDialog( char *filename, int filenameSize, const char *filetypes="All Files (*.*)\0*.*;")

  {

  	OPENFILENAME *ofn = (OPENFILENAME*)GlobalAlloc(GMEM_FIXED,sizeof(OPENFILENAME));

  	ZeroMemory(ofn, sizeof(OPENFILENAME));

  	ofn->lStructSize = sizeof(OPENFILENAME);

  	ofn->hwndOwner = NULL;

  	ofn->lpstrFile = filename;

  	cout<<ofn->lpstrFile<<endl;

  	ofn->nMaxFile = filenameSize;

  	ofn->lpstrFilter = filetypes ? filetypes : "All Files (*.*)\0*.*;";

  	ofn->nFilterIndex = 0;

  	ofn->lpstrFileTitle = NULL;

  	ofn->nMaxFileTitle = 0;

  	ofn->lpstrInitialDir = NULL;

  	ofn->Flags = OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST

  |OFN_EXPLORER | OFN_HIDEREADONLY;

  

  	//allow multiple files to be loaded if the user says so

  	//if(multi) ofn->Flags = ofn->Flags | OFN_ALLOWMULTISELECT;

  

  	BOOL success = GetOpenFileNameA(ofn);

  	//DWORD myfoo = CommDlgExtendedError();

  	GlobalFree(ofn);

  	return success;

  }

  

  bool rtsSaveFileDialog( char *filename, int filenameSize, const char *filetypes="All Files (*.*)\0*.*;" )

  {

  	OPENFILENAME *ofn = (OPENFILENAME*)GlobalAlloc(GMEM_FIXED,sizeof(OPENFILENAME));

  	ZeroMemory(ofn, sizeof(OPENFILENAME));

  	ofn->lStructSize = sizeof(OPENFILENAME);

  	ofn->hwndOwner = NULL;

  	ofn->lpstrFile = filename;

  	ofn->nMaxFile = filenameSize;

  	ofn->lpstrFilter = filetypes ? filetypes : "All Files (*.*)\0*.*;";

  	ofn->nFilterIndex = 0;

  	ofn->lpstrFileTitle = NULL;

  	ofn->nMaxFileTitle = 0;

  	ofn->lpstrInitialDir = NULL;

  	ofn->Flags = OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST

  |OFN_EXPLORER | OFN_HIDEREADONLY;

  	BOOL success = GetSaveFileNameA(ofn);

  	//DWORD myfoo = CommDlgExtendedError();

  	GlobalFree(ofn);

  	return success;

  }

  

  bool rts_winBrowseFolderDialog(char* title, char* foldername)

  {

  	BROWSEINFO* bi = (BROWSEINFO*)GlobalAlloc(GMEM_FIXED,sizeof(BROWSEINFO));

  	ZeroMemory(bi, sizeof(BROWSEINFO));

  	char directory[MAX_PATH] = "";

  

  	bi->pszDisplayName = directory;

  	bi->lpszTitle = title;

  	bi->pidlRoot = NULL;

  	bi->lpfn = NULL;

  	bi->ulFlags = 0;

  	PIDLIST_ABSOLUTE pID = SHBrowseForFolder(bi);

  

  	SHGetPathFromIDList(pID, foldername);

  

  	return true;

  

  }