ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/Chooser.cxx
(Generate patch)

Comparing trunk/VTBFileUtil2/Chooser.cxx (file contents):
Revision 263 by douglas, 2003-08-16T16:09:44-07:00 vs.
Revision 266 by douglas, 2003-08-17T16:39:32-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: Chooser.cxx,v 1.1 2003/08/16 23:09:44 douglas Exp $
5 > // $Id: Chooser.cxx,v 1.4 2003/08/17 23:39:32 douglas Exp $
6  
7   #include "Chooser.h"
8  
9 < struct
9 > Chooser::Chooser()
10   {
11 <        bool* shortcut;
12 <        Mode* choice;
11 >        shortcut = false;
12 >        choice = none;
13 >        number = count++;
14 >        choosers.insert(pair<unsigned, Chooser*>(number, this));
15   }
14 cheese;
16  
17 < Mode Chooser::choose(HWND parent)
17 > Chooser::~Chooser()
18   {
19 <        cheese.shortcut = &shortcut;
20 <        cheese.choice = &choice;
19 >        choosers.erase(number);
20 > }
21  
22 <        DialogBox(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, smersh);
22 > Mode Chooser::choose(HWND parent)
23 > {
24 >        DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent,
25 >                Chooser::window, number);
26  
27          desktop();
28  
29          return choice;
30   }
31  
32 < void Chooser::desktop(void)
32 > INT_PTR CALLBACK Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l)
33   {
34 <        if (!shortcut) return;
35 <
36 <        MessageBox(NULL, "Desktop Shortcut", programName.c_str(),
37 <                MB_ICONINFORMATION);
34 < }
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  
36 INT_PTR CALLBACK smersh(HWND dialog, UINT msg, WPARAM w, LPARAM l)
37 {
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 <                        *cheese.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 <                        *cheese.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 <                        *cheese.shortcut = !*cheese.shortcut;
68 <                        if (debug) cerr << "shortcut = " << *cheese.shortcut << "\n";
67 >                        *shortcut = !*shortcut;
68 >                        if (debug) cerr << "shortcut = " << *shortcut << "\n";
69                          break;
70                  case IDCANCEL:
71 <                        *cheese.choice = none;
71 >                        *choice = none;
72                  case IDOK:
73 +                        windows.erase(dialog);
74                          EndDialog(dialog, w);
75                          return TRUE;
76                  default:
# Line 74 | Line 81 | INT_PTR CALLBACK smersh(HWND dialog, UIN
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 + void Chooser::desktop(void)
90 + {
91 +        if (!shortcut || choice == none) return;
92 +
93 +        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 +        CoUninitialize();
135 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines