ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/Chooser.cxx
Revision: 265
Committed: 2003-08-16T20:55:39-07:00 (21 years, 10 months ago) by douglas
File size: 2441 byte(s)
Log Message:
Stuff works.

File Contents

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