1 | #include "dirSelector.h"
|
---|
2 |
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <shlobj.h>
|
---|
5 |
|
---|
6 | extern HINSTANCE app_instance;
|
---|
7 |
|
---|
8 | int 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 |
|
---|
31 | dirSelector::dirSelector(char *_prompt, char *_title) : configurable(_prompt)
|
---|
32 | { this->path = NULL;
|
---|
33 | this->title = _title;
|
---|
34 | }
|
---|
35 |
|
---|
36 | dirSelector::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 |
|
---|
43 | dirSelector::dirSelector(HGLOBAL dlgBlk)
|
---|
44 | { this->path = NULL;
|
---|
45 | this->dlgBlock = dlgBlk;
|
---|
46 | }
|
---|
47 |
|
---|
48 | UINT 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 |
|
---|
72 | void 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 |
|
---|
80 | void 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 |
|
---|
93 | void dirSelector::requestPath(HWND parent, LPSTR message)
|
---|
94 | { OPENFILENAME openStr;
|
---|
95 | char fileName[256] = "dir.dir\0";
|
---|
96 | DWORD error;
|
---|
97 | BROWSEINFO bInfo;
|
---|
98 | int image;
|
---|
99 |
|
---|
100 | bInfo.hwndOwner = parent;
|
---|
101 | bInfo.pidlRoot = NULL;
|
---|
102 | bInfo.pszDisplayName = fileName;
|
---|
103 | bInfo.lpszTitle = message;
|
---|
104 | bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
|
---|
105 | bInfo.lpfn = initSelect;
|
---|
106 | bInfo.lParam = (LONG) this;
|
---|
107 | bInfo.iImage = image = 0;
|
---|
108 | LPITEMIDLIST itemList = SHBrowseForFolder(&bInfo);
|
---|
109 | if (itemList != NULL)
|
---|
110 | { SHGetPathFromIDList(itemList, fileName);
|
---|
111 | this->setPath(fileName);
|
---|
112 | }
|
---|
113 | return;
|
---|
114 |
|
---|
115 | openStr.lStructSize = sizeof(OPENFILENAME);
|
---|
116 | openStr.hwndOwner = parent;
|
---|
117 | openStr.hInstance = 0;// app_instance; //this->dlgBlock;
|
---|
118 | openStr.lpstrFilter = NULL;
|
---|
119 | openStr.lpstrCustomFilter = NULL;
|
---|
120 | openStr.nMaxCustFilter = NULL;
|
---|
121 | openStr.nFilterIndex = 0;
|
---|
122 | openStr.lpstrFile = fileName;
|
---|
123 | openStr.nMaxFile = 255;
|
---|
124 | openStr.lpstrFileTitle = NULL;
|
---|
125 | openStr.lpstrInitialDir = NULL;
|
---|
126 | openStr.lpstrTitle = message;
|
---|
127 | openStr.Flags = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; // || OFN_ENABLETEMPLATE | OFN_EXPLORER;
|
---|
128 | openStr.nFileOffset = 0;
|
---|
129 | openStr.nFileExtension = 4;
|
---|
130 | openStr.lpstrDefExt = NULL;
|
---|
131 | openStr.lCustData = NULL;
|
---|
132 | openStr.lpfnHook = hookProc;
|
---|
133 | openStr.lpTemplateName = 0; // "MySaveAsDlg";
|
---|
134 | if (GetSaveFileName(&openStr) == 0)
|
---|
135 | { error = CommDlgExtendedError();
|
---|
136 | }
|
---|
137 | else
|
---|
138 | { if (this->path != NULL)
|
---|
139 | { free(this->path);
|
---|
140 | }
|
---|
141 | this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1);
|
---|
142 | strcpy(this->path, openStr.lpstrFile);
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | char *dirSelector::selectedPath()
|
---|
147 | { return this->path;
|
---|
148 | } |
---|