ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/VTBFileUtil2/License.cxx
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (14 years, 1 month ago) by douglas
File size: 4611 byte(s)
Log Message:
Rearranged everything else.

File Contents

# User Rev Content
1 douglas 291 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 295 // $Id: License.cxx,v 1.3 2003/09/12 04:26:54 douglas Exp $
6 douglas 291
7     #include "License.h"
8    
9     License::License()
10     {
11     number = count++;
12    
13 douglas 292 if (number == 0) library = LoadLibrary("riched20.dll");
14    
15 douglas 291 licenses.insert(pair<unsigned, License*>(number, this));
16     }
17    
18     License::~License()
19     {
20     licenses.erase(number);
21 douglas 292
22     if (licenses.empty()) FreeLibrary(library);
23 douglas 291 }
24    
25     void License::display(HWND parent)
26     {
27 douglas 292 if (license.str() == "")
28     {
29     HRSRC license = FindResource(gui.instance, LPCTSTR(IDR_LICENSE),
30     LPCTSTR(256));
31     int length = SizeofResource(gui.instance, license);
32     HANDLE handle = LoadResource(gui.instance, license);
33    
34     if (handle != NULL)
35     {
36     const char* license = (char*)(LockResource(handle));
37    
38     this->license.write(license, length);
39     }
40     else
41     {
42     error(parent);
43     }
44     }
45    
46 douglas 291 DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_LICENSE), parent, window,
47     number);
48     }
49    
50     void License::check(HWND parent)
51     {
52     HKEY key;
53    
54     if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER,
55     "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
56     REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
57     NULL) == ERROR_SUCCESS)
58     {
59     DWORD type, data, size = sizeof(data);
60    
61     if (RegQueryValueEx(key, "LastLicenseDate", NULL, &type, LPBYTE(&data),
62     &size) == ERROR_SUCCESS)
63     {
64     if (type != REG_DWORD)
65     {
66     data = 0;
67     }
68     }
69     else
70     {
71     data = 0;
72     }
73    
74     if (debug) cerr << "data = {\n"
75     << " month = " << LOWORD(data) << "\n"
76     << " year = " << HIWORD(data) << "\n"
77     << "}\n";
78    
79     SYSTEMTIME time;
80    
81     GetLocalTime(&time);
82    
83     if (debug) cerr << "time = {\n"
84     << " month = " << time.wMonth << "\n"
85     << " year = " << time.wYear << "\n"
86     << "}\n";
87    
88     if (LOWORD(data) != time.wMonth || HIWORD(data) != time.wYear)
89     {
90     display(parent);
91    
92     data = MAKELONG(time.wMonth, time.wYear);
93    
94     if (code = RegSetValueEx(key, "LastLicenseDate", 0, REG_DWORD,
95     LPBYTE(&data), sizeof(data)) != ERROR_SUCCESS)
96     {
97     error(parent, code);
98     }
99     }
100    
101     RegCloseKey(key);
102     }
103     else
104     {
105     error(parent, code);
106     }
107     }
108    
109     unsigned License::count = 0;
110 douglas 292 HMODULE License::library = NULL;
111 douglas 291 map<unsigned, License*> License::licenses;
112     map<HWND, License*> License::windows;
113    
114     INT_PTR License::window(HWND dialog, UINT msg, WPARAM w, LPARAM l)
115     {
116     map<HWND, License*>::iterator itor = windows.find(dialog);
117     License* data = itor->second;
118    
119     switch (msg)
120     {
121     case WM_INITDIALOG:
122     center(dialog);
123     SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon));
124     SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
125    
126     {
127     map<unsigned, License*>::iterator itor = licenses.find(l);
128    
129     windows.insert(pair<HWND, License*>(dialog, itor->second));
130    
131     data = itor->second;
132     }
133    
134 douglas 292 {
135     HMENU menu = GetSystemMenu(dialog, FALSE);
136     MENUITEMINFO separator, save;
137     int count = GetMenuItemCount(menu);
138    
139     separator.cbSize = sizeof(separator);
140     separator.fMask = MIIM_TYPE;
141     separator.fType = MFT_SEPARATOR;
142     save.cbSize = sizeof(save);
143     save.fMask = MIIM_ID | MIIM_TYPE;
144     save.fType = MFT_STRING;
145     save.wID = 1;
146     save.dwTypeData = "&Save...";
147     save.cch = 8;
148    
149     InsertMenuItem(menu, count++, TRUE, &separator);
150     InsertMenuItem(menu, count++, TRUE, &save);
151     }
152    
153     if (library != NULL)
154     {
155     HWND license = CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS,
156     "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |
157     ES_DISABLENOSCROLL | ES_READONLY | ES_WANTRETURN, 30, 33, 460,
158     242, dialog, NULL, gui.instance, 0);
159     SETTEXTEX text;
160    
161     text.flags = ST_DEFAULT;
162     text.codepage = CP_ACP;
163    
164     SendMessage(license, EM_SETTEXTEX, WPARAM(&text),
165     LPARAM(data->license.str().c_str()));
166     }
167 douglas 291 break;
168 douglas 292 case WM_SYSCOMMAND:
169     switch (w)
170     {
171     case 1:
172     {
173     OPENFILENAME save;
174     char file[MAX_PATH];
175    
176 douglas 295 StringCchPrintf(file, MAX_PATH, "License.rtf");
177 douglas 292
178     save.lStructSize = sizeof(save);
179     save.hwndOwner = dialog;
180     save.lpstrFilter = "Rich Text Format (RTF)\0*.rtf\0";
181     save.lpstrCustomFilter = NULL;
182     save.nFilterIndex = 1;
183     save.lpstrFile = file;
184     save.nMaxFile = MAX_PATH;
185     save.lpstrFileTitle = NULL;
186     save.lpstrInitialDir = NULL;
187     save.lpstrTitle = NULL;
188     save.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
189     save.lpstrDefExt = "rtf";
190    
191     if (GetSaveFileName(&save))
192     {
193     if (debug) cerr << "file = " << file << "\n";
194    
195     ofstream fout(file);
196    
197     fout << data->license.str();
198    
199     fout.close();
200     }
201     }
202     break;
203     }
204     break;
205 douglas 291 case WM_COMMAND:
206     switch (LOWORD(w))
207     {
208     case IDCANCEL:
209     case IDOK:
210     EndDialog(dialog, w);
211     return TRUE;
212     break;
213     }
214     break;
215     }
216    
217     return FALSE;
218     }