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 265 by douglas, 2003-08-16T20:55:39-07:00 vs.
Revision 291 by douglas, 2003-09-05T01:57:00-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: Chooser.cxx,v 1.3 2003/08/17 03:55:39 douglas Exp $
5 > // $Id: Chooser.cxx,v 1.11 2003/09/05 08:57:00 douglas Exp $
6  
7   #include "Chooser.h"
8  
9 < INT_PTR CALLBACK smersh(HWND dialog, UINT msg, WPARAM w, LPARAM l);
9 > Chooser::Chooser()
10 > {
11 >        shortcut = false;
12 >        choice = none;
13 >        number = count++;
14 >
15 >        choosers.insert(pair<unsigned, Chooser*>(number, this));
16 > }
17  
18 < struct
18 > Chooser::~Chooser()
19   {
20 <        bool* shortcut;
14 <        Mode* choice;
20 >        choosers.erase(number);
21   }
16 cheese;
22  
23   Mode Chooser::choose(HWND parent)
24   {
25 <        cheese.shortcut = &shortcut;
26 <        cheese.choice = &choice;
22 <
23 <        DialogBox(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, smersh);
25 >        DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, window,
26 >                number);
27  
28          desktop();
29  
30          return choice;
31   }
32  
33 + unsigned Chooser::count = 0;
34 + map<unsigned, Chooser*> Chooser::choosers;
35 + map<HWND, Chooser*> Chooser::windows;
36 +
37 + INT_PTR Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l)
38 + {
39 +        map<HWND, Chooser*>::iterator itor = windows.find(dialog);
40 +        Chooser* data = itor->second;
41 +
42 +        switch (msg)
43 +        {
44 +        case WM_INITDIALOG:
45 +                center(dialog);
46 +                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon));
47 +                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
48 +
49 +                {
50 +                        map<unsigned, Chooser*>::iterator itor = choosers.find(l);
51 +                        
52 +                        windows.insert(pair<HWND, Chooser*>(dialog, itor->second));
53 +
54 +                        data = itor->second;
55 +                }
56 +
57 +                {
58 +                        HMENU menu = GetSystemMenu(dialog, FALSE);
59 +                        MENUITEMINFO separator, usage, version, license;
60 +                        int count = GetMenuItemCount(menu);
61 +
62 +                        separator.cbSize = sizeof(separator);
63 +                        separator.fMask = MIIM_TYPE;
64 +                        separator.fType = MFT_SEPARATOR;
65 +                        usage.cbSize = sizeof(usage);
66 +                        usage.fMask = MIIM_ID | MIIM_TYPE;
67 +                        usage.fType = MFT_STRING;
68 +                        usage.wID = 1;
69 +                        usage.dwTypeData = "&Usage...";
70 +                        usage.cch = 9;
71 +                        version.cbSize = sizeof(version);
72 +                        version.fMask = MIIM_ID | MIIM_TYPE;
73 +                        version.fType = MFT_STRING;
74 +                        version.wID = 2;
75 +                        version.dwTypeData = "&Version...";
76 +                        version.cch = 11;
77 +                        license.cbSize = sizeof(license);
78 +                        license.fMask = MIIM_ID | MIIM_TYPE;
79 +                        license.fType = MFT_STRING;
80 +                        license.wID = 3;
81 +                        license.dwTypeData = "&License...";
82 +                        license.cch = 11;
83 +
84 +                        InsertMenuItem(menu, count++, TRUE, &separator);
85 +                        InsertMenuItem(menu, count++, TRUE, &usage);
86 +                        InsertMenuItem(menu, count++, TRUE, &version);
87 +                        InsertMenuItem(menu, count++, TRUE, &license);
88 +                }
89 +                break;
90 +        case WM_SYSCOMMAND:
91 +                switch (w)
92 +                {
93 +                case 1:
94 +                        usage(dialog);
95 +                        break;
96 +                case 2:
97 +                        version(dialog);
98 +                        break;
99 +                case 3:
100 +                        {
101 +                                License license;
102 +
103 +                                license.display(dialog);
104 +                        }
105 +                        break;
106 +                }
107 +                break;
108 +        case WM_COMMAND:
109 +                switch (LOWORD(w))
110 +                {
111 +                case IDC_CHOICE_DISC:
112 +                        data->choice = disc;
113 +
114 +                        if (debug) cerr << "choice = disc\n";
115 +
116 +                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
117 +                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
118 +                        break;
119 +                case IDC_CHOICE_SCAN:
120 +                        data->choice = scan;
121 +
122 +                        if (debug) cerr << "choice = scan\n";
123 +
124 +                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
125 +                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
126 +                        break;
127 +                case IDC_CHOICE_ALWAYS:
128 +                        data->shortcut = !data->shortcut;
129 +
130 +                        if (debug) cerr << "shortcut = " << data->shortcut << "\n";
131 +                        break;
132 +                case IDCANCEL:
133 +                        data->choice = none;
134 +                case IDOK:
135 +                        EndDialog(dialog, w);
136 +                        return TRUE;
137 +                        break;
138 +                }
139 +                break;
140 +        }
141 +
142 +        return FALSE;
143 + }
144 +
145   void Chooser::desktop(void)
146   {
147          if (!shortcut || choice == none) return;
148  
149          IShellLink* link;
150  
36        CoInitialize(NULL);
151          CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
152                  IID_IShellLink, (LPVOID*)(&link));
153  
# Line 61 | Line 175 | void Chooser::desktop(void)
175  
176          char* desktop = new char[MAX_PATH];
177  
178 <        SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT,
179 <                desktop);
178 >        SHGetFolderPath(NULL, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL,
179 >                SHGFP_TYPE_CURRENT, desktop);
180  
181          wstring path = toWide(string(desktop) + "\\" + name + ".lnk");
182  
# Line 72 | Line 186 | void Chooser::desktop(void)
186          file->Release();
187          link->Release();
188  
189 <        CoUninitialize();
76 < }
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;
189 >        delete [] desktop;
190   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines