1 |
douglas |
263 |
// Vance Thrift and Biller File Utility 2 |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
douglas |
290 |
// $Id: Chooser.cxx,v 1.10 2003/09/05 01:57:00 douglas Exp $ |
6 |
douglas |
263 |
|
7 |
|
|
#include "Chooser.h" |
8 |
|
|
|
9 |
douglas |
266 |
Chooser::Chooser() |
10 |
|
|
{ |
11 |
|
|
shortcut = false; |
12 |
|
|
choice = none; |
13 |
|
|
number = count++; |
14 |
|
|
choosers.insert(pair<unsigned, Chooser*>(number, this)); |
15 |
|
|
} |
16 |
douglas |
265 |
|
17 |
douglas |
266 |
Chooser::~Chooser() |
18 |
douglas |
263 |
{ |
19 |
douglas |
266 |
choosers.erase(number); |
20 |
douglas |
263 |
} |
21 |
|
|
|
22 |
|
|
Mode Chooser::choose(HWND parent) |
23 |
|
|
{ |
24 |
douglas |
266 |
DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, |
25 |
|
|
Chooser::window, number); |
26 |
douglas |
263 |
|
27 |
|
|
desktop(); |
28 |
|
|
|
29 |
|
|
return choice; |
30 |
|
|
} |
31 |
|
|
|
32 |
douglas |
268 |
unsigned Chooser::count = 0; |
33 |
|
|
map<unsigned, Chooser*> Chooser::choosers; |
34 |
|
|
map<HWND, Chooser*> Chooser::windows; |
35 |
|
|
|
36 |
douglas |
273 |
INT_PTR Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
37 |
douglas |
266 |
{ |
38 |
|
|
map<HWND, Chooser*>::iterator itor = windows.find(dialog); |
39 |
|
|
Chooser* data = itor->second; |
40 |
|
|
|
41 |
|
|
switch (msg) |
42 |
|
|
{ |
43 |
|
|
case WM_INITDIALOG: |
44 |
|
|
center(dialog); |
45 |
|
|
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
46 |
|
|
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
47 |
|
|
{ |
48 |
|
|
map<unsigned, Chooser*>::iterator itor = choosers.find(l); |
49 |
|
|
|
50 |
|
|
windows.insert(pair<HWND, Chooser*>(dialog, itor->second)); |
51 |
|
|
} |
52 |
|
|
break; |
53 |
|
|
case WM_COMMAND: |
54 |
|
|
switch (LOWORD(w)) |
55 |
|
|
{ |
56 |
|
|
case IDC_CHOICE_DISC: |
57 |
douglas |
268 |
data->choice = disc; |
58 |
douglas |
266 |
if (debug) cerr << "choice = disc\n"; |
59 |
|
|
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
60 |
|
|
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
61 |
|
|
break; |
62 |
|
|
case IDC_CHOICE_SCAN: |
63 |
douglas |
268 |
data->choice = scan; |
64 |
douglas |
266 |
if (debug) cerr << "choice = scan\n"; |
65 |
|
|
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
66 |
|
|
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
67 |
|
|
break; |
68 |
|
|
case IDC_CHOICE_ALWAYS: |
69 |
douglas |
268 |
data->shortcut = !data->shortcut; |
70 |
|
|
if (debug) cerr << "shortcut = " << data->shortcut << "\n"; |
71 |
douglas |
266 |
break; |
72 |
|
|
case IDCANCEL: |
73 |
douglas |
268 |
data->choice = none; |
74 |
douglas |
266 |
case IDOK: |
75 |
|
|
EndDialog(dialog, w); |
76 |
|
|
return TRUE; |
77 |
|
|
default: |
78 |
|
|
break; |
79 |
|
|
} |
80 |
|
|
break; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
return FALSE; |
84 |
|
|
} |
85 |
|
|
|
86 |
douglas |
263 |
void Chooser::desktop(void) |
87 |
|
|
{ |
88 |
douglas |
264 |
if (!shortcut || choice == none) return; |
89 |
douglas |
263 |
|
90 |
douglas |
264 |
IShellLink* link; |
91 |
|
|
|
92 |
|
|
CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, |
93 |
|
|
IID_IShellLink, (LPVOID*)(&link)); |
94 |
|
|
|
95 |
|
|
string name; |
96 |
|
|
|
97 |
|
|
link->SetPath(program.c_str()); |
98 |
|
|
link->SetIconLocation(program.c_str(), 0); |
99 |
|
|
link->SetDescription(programName.c_str()); |
100 |
|
|
|
101 |
|
|
switch (choice) |
102 |
|
|
{ |
103 |
|
|
case disc: |
104 |
|
|
name = "Disc Browse"; |
105 |
|
|
link->SetArguments("-disc"); |
106 |
|
|
break; |
107 |
|
|
case scan: |
108 |
|
|
name = "Scan Utility"; |
109 |
|
|
link->SetArguments("-scan"); |
110 |
|
|
break; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
IPersistFile* file; |
114 |
|
|
|
115 |
|
|
link->QueryInterface(IID_IPersistFile, (LPVOID*)(&file)); |
116 |
|
|
|
117 |
|
|
char* desktop = new char[MAX_PATH]; |
118 |
|
|
|
119 |
douglas |
290 |
SHGetFolderPath(NULL, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL, |
120 |
|
|
SHGFP_TYPE_CURRENT, desktop); |
121 |
douglas |
264 |
|
122 |
|
|
wstring path = toWide(string(desktop) + "\\" + name + ".lnk"); |
123 |
|
|
|
124 |
|
|
if (debug) cerr << "path = " << toAnsi(path) << "\n"; |
125 |
|
|
|
126 |
|
|
file->Save(path.c_str(), TRUE); |
127 |
|
|
file->Release(); |
128 |
|
|
link->Release(); |
129 |
|
|
|
130 |
douglas |
267 |
delete [] desktop; |
131 |
douglas |
263 |
} |