ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/Chooser.cxx
Revision: 267
Committed: 2003-08-18T15:25:29-07:00 (21 years, 10 months ago) by douglas
File size: 2893 byte(s)
Log Message:
istringstream in IndividualClient.getFile().

File Contents

# User Rev Content
1 douglas 263 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 267 // $Id: Chooser.cxx,v 1.5 2003/08/18 22:25:29 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 266 INT_PTR CALLBACK Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l)
33     {
34     map<HWND, Chooser*>::iterator itor = windows.find(dialog);
35     Chooser* data = itor->second;
36     Mode* choice = &data->choice;
37     bool* shortcut = &data->shortcut;
38    
39     switch (msg)
40     {
41     case WM_INITDIALOG:
42     center(dialog);
43     SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon));
44     SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
45     {
46     map<unsigned, Chooser*>::iterator itor = choosers.find(l);
47    
48     windows.insert(pair<HWND, Chooser*>(dialog, itor->second));
49     }
50     break;
51     case WM_COMMAND:
52     switch (LOWORD(w))
53     {
54     case IDC_CHOICE_DISC:
55     *choice = disc;
56     if (debug) cerr << "choice = disc\n";
57     EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
58     EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
59     break;
60     case IDC_CHOICE_SCAN:
61     *choice = scan;
62     if (debug) cerr << "choice = scan\n";
63     EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
64     EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
65     break;
66     case IDC_CHOICE_ALWAYS:
67     *shortcut = !*shortcut;
68     if (debug) cerr << "shortcut = " << *shortcut << "\n";
69     break;
70     case IDCANCEL:
71     *choice = none;
72     case IDOK:
73     windows.erase(dialog);
74     EndDialog(dialog, w);
75     return TRUE;
76     default:
77     break;
78     }
79     break;
80     }
81    
82     return FALSE;
83     }
84    
85     unsigned Chooser::count = 0;
86     map<unsigned, Chooser*> Chooser::choosers;
87     map<HWND, Chooser*> Chooser::windows;
88    
89 douglas 263 void Chooser::desktop(void)
90     {
91 douglas 264 if (!shortcut || choice == none) return;
92 douglas 263
93 douglas 264 IShellLink* link;
94    
95     CoInitialize(NULL);
96     CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
97     IID_IShellLink, (LPVOID*)(&link));
98    
99     string name;
100    
101     link->SetPath(program.c_str());
102     link->SetIconLocation(program.c_str(), 0);
103     link->SetDescription(programName.c_str());
104    
105     switch (choice)
106     {
107     case disc:
108     name = "Disc Browse";
109     link->SetArguments("-disc");
110     break;
111     case scan:
112     name = "Scan Utility";
113     link->SetArguments("-scan");
114     break;
115     }
116    
117     IPersistFile* file;
118    
119     link->QueryInterface(IID_IPersistFile, (LPVOID*)(&file));
120    
121     char* desktop = new char[MAX_PATH];
122    
123     SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT,
124     desktop);
125    
126     wstring path = toWide(string(desktop) + "\\" + name + ".lnk");
127    
128     if (debug) cerr << "path = " << toAnsi(path) << "\n";
129    
130     file->Save(path.c_str(), TRUE);
131     file->Release();
132     link->Release();
133    
134 douglas 267 delete [] desktop;
135    
136 douglas 264 CoUninitialize();
137 douglas 263 }