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