ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/VTBFileUtil2/Chooser.cxx
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (13 years, 11 months ago) by douglas
File size: 4028 byte(s)
Log Message:
Rearranged everything else.

File Contents

# Content
1 // Vance Thrift and Biller File Utility 2
2 //
3 // Douglas Thrift
4 //
5 // $Id: Chooser.cxx,v 1.11 2003/09/05 08:57:00 douglas Exp $
6
7 #include "Chooser.h"
8
9 Chooser::Chooser()
10 {
11 shortcut = false;
12 choice = none;
13 number = count++;
14
15 choosers.insert(pair<unsigned, Chooser*>(number, this));
16 }
17
18 Chooser::~Chooser()
19 {
20 choosers.erase(number);
21 }
22
23 Mode Chooser::choose(HWND parent)
24 {
25 DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, window,
26 number);
27
28 desktop();
29
30 return choice;
31 }
32
33 unsigned Chooser::count = 0;
34 map<unsigned, Chooser*> Chooser::choosers;
35 map<HWND, Chooser*> Chooser::windows;
36
37 INT_PTR Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l)
38 {
39 map<HWND, Chooser*>::iterator itor = windows.find(dialog);
40 Chooser* data = itor->second;
41
42 switch (msg)
43 {
44 case WM_INITDIALOG:
45 center(dialog);
46 SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon));
47 SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
48
49 {
50 map<unsigned, Chooser*>::iterator itor = choosers.find(l);
51
52 windows.insert(pair<HWND, Chooser*>(dialog, itor->second));
53
54 data = itor->second;
55 }
56
57 {
58 HMENU menu = GetSystemMenu(dialog, FALSE);
59 MENUITEMINFO separator, usage, version, license;
60 int count = GetMenuItemCount(menu);
61
62 separator.cbSize = sizeof(separator);
63 separator.fMask = MIIM_TYPE;
64 separator.fType = MFT_SEPARATOR;
65 usage.cbSize = sizeof(usage);
66 usage.fMask = MIIM_ID | MIIM_TYPE;
67 usage.fType = MFT_STRING;
68 usage.wID = 1;
69 usage.dwTypeData = "&Usage...";
70 usage.cch = 9;
71 version.cbSize = sizeof(version);
72 version.fMask = MIIM_ID | MIIM_TYPE;
73 version.fType = MFT_STRING;
74 version.wID = 2;
75 version.dwTypeData = "&Version...";
76 version.cch = 11;
77 license.cbSize = sizeof(license);
78 license.fMask = MIIM_ID | MIIM_TYPE;
79 license.fType = MFT_STRING;
80 license.wID = 3;
81 license.dwTypeData = "&License...";
82 license.cch = 11;
83
84 InsertMenuItem(menu, count++, TRUE, &separator);
85 InsertMenuItem(menu, count++, TRUE, &usage);
86 InsertMenuItem(menu, count++, TRUE, &version);
87 InsertMenuItem(menu, count++, TRUE, &license);
88 }
89 break;
90 case WM_SYSCOMMAND:
91 switch (w)
92 {
93 case 1:
94 usage(dialog);
95 break;
96 case 2:
97 version(dialog);
98 break;
99 case 3:
100 {
101 License license;
102
103 license.display(dialog);
104 }
105 break;
106 }
107 break;
108 case WM_COMMAND:
109 switch (LOWORD(w))
110 {
111 case IDC_CHOICE_DISC:
112 data->choice = disc;
113
114 if (debug) cerr << "choice = disc\n";
115
116 EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
117 EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
118 break;
119 case IDC_CHOICE_SCAN:
120 data->choice = scan;
121
122 if (debug) cerr << "choice = scan\n";
123
124 EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
125 EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
126 break;
127 case IDC_CHOICE_ALWAYS:
128 data->shortcut = !data->shortcut;
129
130 if (debug) cerr << "shortcut = " << data->shortcut << "\n";
131 break;
132 case IDCANCEL:
133 data->choice = none;
134 case IDOK:
135 EndDialog(dialog, w);
136 return TRUE;
137 break;
138 }
139 break;
140 }
141
142 return FALSE;
143 }
144
145 void Chooser::desktop(void)
146 {
147 if (!shortcut || choice == none) return;
148
149 IShellLink* link;
150
151 CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
152 IID_IShellLink, (LPVOID*)(&link));
153
154 string name;
155
156 link->SetPath(program.c_str());
157 link->SetIconLocation(program.c_str(), 0);
158 link->SetDescription(programName.c_str());
159
160 switch (choice)
161 {
162 case disc:
163 name = "Disc Browse";
164 link->SetArguments("-disc");
165 break;
166 case scan:
167 name = "Scan Utility";
168 link->SetArguments("-scan");
169 break;
170 }
171
172 IPersistFile* file;
173
174 link->QueryInterface(IID_IPersistFile, (LPVOID*)(&file));
175
176 char* desktop = new char[MAX_PATH];
177
178 SHGetFolderPath(NULL, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL,
179 SHGFP_TYPE_CURRENT, desktop);
180
181 wstring path = toWide(string(desktop) + "\\" + name + ".lnk");
182
183 if (debug) cerr << "path = " << toAnsi(path) << "\n";
184
185 file->Save(path.c_str(), TRUE);
186 file->Release();
187 link->Release();
188
189 delete [] desktop;
190 }