source: other-projects/gs2-export-cdrom-installer/trunk/dirSelector.cpp@ 21709

Last change on this file since 21709 was 11664, checked in by mdewsnip, 18 years ago

Fixed the line endings... for real this time, I hope.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1#include "dirSelector.h"
2
3#include <stdio.h>
4#include <shlobj.h>
5
6extern HINSTANCE app_instance;
7
8int CALLBACK initSelect(HWND window, UINT message, LPARAM lParam, LONG lpData)
9{ TCHAR buffer[MAX_PATH];
10
11 switch (message)
12 { case BFFM_INITIALIZED:
13 { dirSelector *selector = (dirSelector *) lpData;
14
15 lstrcpy(buffer, selector->selectedPath());
16// GetCurrentDirectory(sizeof(buffer) / sizeof(TCHAR), buffer);
17 SendMessage(window, BFFM_SETSELECTION, TRUE, (LPARAM) buffer);
18 SendMessage(window, BFFM_SETSTATUSTEXT, 0, (LPARAM) buffer);
19 }
20 break;
21
22 case BFFM_SELCHANGED:
23 if (SHGetPathFromIDList((LPITEMIDLIST) lParam, buffer))
24 { SendMessage(window, BFFM_SETSTATUSTEXT, 0, (LPARAM) buffer);
25 }
26 break;
27 }
28 return 0;
29}
30
31dirSelector::dirSelector(char *_prompt, char *_title) : configurable(_prompt)
32{ this->path = NULL;
33 this->title = _title;
34}
35
36dirSelector::dirSelector(char *_prompt, char *_optPrompt, char *_title, FilePath *_defPath) :
37 configurable(_prompt, _optPrompt)
38{ this->path = new char[strlen(_defPath->cString())+1];
39 strcpy(this->path, _defPath->cString());
40 this->title = _title;
41}
42
43dirSelector::dirSelector(HGLOBAL dlgBlk)
44{ this->path = NULL;
45 this->dlgBlock = dlgBlk;
46}
47
48UINT APIENTRY hookProc(HWND dlg, UINT message,
49 WPARAM wParam, LPARAM lParam)
50{ switch (message)
51 { case WM_INITDIALOG:
52 CommDlg_OpenSave_HideControl(GetParent(dlg), edt1);
53 CommDlg_OpenSave_HideControl(GetParent(dlg), stc3);
54 CommDlg_OpenSave_HideControl(GetParent(dlg), cmb1);
55 CommDlg_OpenSave_HideControl(GetParent(dlg), stc2);
56 CommDlg_OpenSave_HideControl(GetParent(dlg), chx1);
57 CommDlg_OpenSave_SetControlText(GetParent(dlg), IDOK, "Select");
58 break;
59
60 case WM_NOTIFY:
61 if (((LPNMHDR) lParam)->code == CDN_INITDONE)
62 { CommDlg_OpenSave_HideControl(GetParent(dlg), edt1);
63 }
64 else if (((LPNMHDR) lParam)->code == CDN_FILEOK)
65 { return 0;
66 }
67 break;
68 }
69 return 0;
70}
71
72void dirSelector::setPath(LPSTR newpath)
73{ if (this->path)
74 { delete this->path;
75 }
76 this->path = new char[strlen(newpath) + 1];
77 strcpy(this->path, newpath);
78}
79
80void dirSelector::setPathFromEdit(HWND window)
81{ char *newpath;
82
83 newpath = new char[GetWindowTextLength(window) + 1];
84 if (newpath != NULL)
85 { GetWindowText(window, newpath, GetWindowTextLength(window) + 1);
86 if (this->path)
87 { delete this->path;
88 }
89 this->path = newpath;
90 }
91}
92
93void dirSelector::requestPath(HWND parent, LPSTR message)
94{
95 OPENFILENAME openStr;
96 char fileName[256] = "dir.dir\0";
97 DWORD error;
98 BROWSEINFO bInfo;
99 int image;
100
101 bInfo.hwndOwner = parent;
102 bInfo.pidlRoot = NULL;
103 bInfo.pszDisplayName = fileName;
104 bInfo.lpszTitle = message;
105 bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
106 bInfo.lpfn = initSelect;
107 bInfo.lParam = (LONG) this;
108 bInfo.iImage = image = 0;
109 LPITEMIDLIST itemList = SHBrowseForFolder(&bInfo);
110 if (itemList != NULL)
111 {
112 SHGetPathFromIDList(itemList, fileName);
113 this->setPath(fileName);
114 }
115 return;
116
117 openStr.lStructSize = sizeof(OPENFILENAME);
118 openStr.hwndOwner = parent;
119 openStr.hInstance = 0; // app_instance; //this->dlgBlock;
120 openStr.lpstrFilter = NULL;
121 openStr.lpstrCustomFilter = NULL;
122 // openStr.nMaxCustFilter = NULL;
123 openStr.nMaxCustFilter = 0;
124 openStr.nFilterIndex = 0;
125 openStr.lpstrFile = fileName;
126 openStr.nMaxFile = 255;
127 openStr.lpstrFileTitle = NULL;
128 openStr.lpstrInitialDir = NULL;
129 openStr.lpstrTitle = message;
130 openStr.Flags = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; // || OFN_ENABLETEMPLATE | OFN_EXPLORER;
131 openStr.nFileOffset = 0;
132 openStr.nFileExtension = 4;
133 openStr.lpstrDefExt = NULL;
134 // openStr.lCustData = NULL;
135 openStr.lCustData = 0;
136 openStr.lpfnHook = hookProc;
137 openStr.lpTemplateName = 0; // "MySaveAsDlg";
138 if (GetSaveFileName(&openStr) == 0)
139 {
140 error = CommDlgExtendedError();
141 }
142 else
143 {
144 if (this->path != NULL)
145 {
146 free(this->path);
147 }
148 this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1);
149 strcpy(this->path, openStr.lpstrFile);
150 }
151}
152
153char *dirSelector::selectedPath()
154{
155 return this->path;
156}
Note: See TracBrowser for help on using the repository browser.