1 |
douglas |
255 |
// Vance Thrift and Biller File Utility 2 |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
douglas |
292 |
// $Id: VTBFileUtil2.h,v 1.17 2003/09/09 01:43:28 douglas Exp $ |
6 |
douglas |
255 |
|
7 |
|
|
#ifndef _VTBFileUtil_h_ |
8 |
|
|
#define _VTBFileUtil_h_ |
9 |
|
|
|
10 |
|
|
#ifdef _DEBUG |
11 |
|
|
#pragma warning(disable:4786) |
12 |
|
|
#endif // _DEBUG |
13 |
|
|
|
14 |
|
|
#include <iostream> |
15 |
|
|
#include <string> |
16 |
|
|
#include <sstream> |
17 |
douglas |
292 |
#include <fstream> |
18 |
douglas |
255 |
#include <cctype> |
19 |
|
|
#include <vector> |
20 |
douglas |
265 |
#include <set> |
21 |
|
|
#include <map> |
22 |
douglas |
259 |
#include <cstdlib> |
23 |
douglas |
255 |
|
24 |
douglas |
285 |
#define _WIN32_IE 0x0500 |
25 |
|
|
|
26 |
douglas |
255 |
#include <windows.h> |
27 |
douglas |
277 |
#include <windowsx.h> |
28 |
douglas |
257 |
#include <commctrl.h> |
29 |
douglas |
264 |
#include <objbase.h> |
30 |
|
|
#include <shlobj.h> |
31 |
douglas |
271 |
#include <shlwapi.h> |
32 |
douglas |
286 |
#include <richedit.h> |
33 |
douglas |
255 |
|
34 |
douglas |
262 |
#include "resource.h" |
35 |
|
|
|
36 |
douglas |
255 |
using namespace std; |
37 |
|
|
|
38 |
douglas |
262 |
enum Mode { none, disc, scan }; |
39 |
|
|
struct Gui |
40 |
|
|
{ |
41 |
|
|
HINSTANCE instance; |
42 |
|
|
HICON icon; |
43 |
douglas |
277 |
int show; |
44 |
douglas |
262 |
}; |
45 |
|
|
|
46 |
douglas |
255 |
extern bool debug; |
47 |
|
|
extern string program; |
48 |
|
|
extern string programName; |
49 |
douglas |
256 |
extern string programVersion; |
50 |
douglas |
262 |
extern Gui gui; |
51 |
douglas |
255 |
|
52 |
douglas |
259 |
void usage(HWND parent = NULL); |
53 |
|
|
void version(HWND parent = NULL); |
54 |
douglas |
278 |
|
55 |
douglas |
285 |
inline string toLower(const string& mixed) |
56 |
|
|
{ |
57 |
|
|
string lower; |
58 |
|
|
|
59 |
|
|
for (unsigned index = 0; index < mixed.length(); index++) |
60 |
|
|
{ |
61 |
|
|
lower += tolower(mixed[index]); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
return lower; |
65 |
|
|
} |
66 |
|
|
|
67 |
douglas |
264 |
inline string toAnsi(const wstring& wide) |
68 |
|
|
{ |
69 |
|
|
LPSTR buffer = new CHAR[wide.length() + 1]; |
70 |
|
|
|
71 |
|
|
WideCharToMultiByte(CP_ACP, 0, wide.c_str(), wide.length() + 1, buffer, |
72 |
|
|
wide.length() + 1, NULL, NULL); |
73 |
|
|
|
74 |
|
|
return buffer; |
75 |
|
|
} |
76 |
douglas |
278 |
|
77 |
douglas |
264 |
inline wstring toWide(const string& ansi) |
78 |
|
|
{ |
79 |
|
|
LPWSTR buffer = new WCHAR[ansi.length() + 1]; |
80 |
|
|
|
81 |
|
|
MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), ansi.length() + 1, buffer, |
82 |
|
|
ansi.length() + 1); |
83 |
|
|
|
84 |
|
|
return buffer; |
85 |
|
|
} |
86 |
douglas |
278 |
|
87 |
douglas |
256 |
inline void center(HWND window) |
88 |
|
|
{ |
89 |
|
|
RECT rect, dialog, desktop; |
90 |
douglas |
255 |
|
91 |
douglas |
256 |
GetWindowRect(GetDesktopWindow(), &desktop); |
92 |
|
|
GetWindowRect(window, &dialog); |
93 |
|
|
CopyRect(&rect, &desktop); |
94 |
|
|
|
95 |
|
|
OffsetRect(&dialog, -dialog.left, -dialog.top); |
96 |
|
|
OffsetRect(&rect, -rect.left, -rect.top); |
97 |
|
|
OffsetRect(&rect, -dialog.right, -dialog.bottom); |
98 |
|
|
|
99 |
|
|
SetWindowPos(window, HWND_TOP, desktop.left + (rect.right / 2), desktop.top |
100 |
|
|
+ (rect.bottom / 2), 0, 0, SWP_NOSIZE); |
101 |
|
|
} |
102 |
douglas |
278 |
|
103 |
douglas |
291 |
inline void error(HWND parent = NULL, LONG code = ERROR_SUCCESS) |
104 |
douglas |
269 |
{ |
105 |
|
|
LPVOID message; |
106 |
douglas |
256 |
|
107 |
douglas |
291 |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
108 |
|
|
NULL, code == ERROR_SUCCESS ? GetLastError() : code, 0, |
109 |
douglas |
269 |
LPTSTR(&message), 0, NULL); |
110 |
douglas |
278 |
MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR); |
111 |
douglas |
269 |
LocalFree(message); |
112 |
|
|
} |
113 |
|
|
|
114 |
douglas |
278 |
inline string format(DWORD value) |
115 |
|
|
{ |
116 |
|
|
ostringstream buffer; |
117 |
|
|
|
118 |
|
|
buffer << value; |
119 |
|
|
|
120 |
|
|
string format = buffer.str(); |
121 |
|
|
|
122 |
|
|
for (int index = format.length(), number = 0; index > 0; index -= 3, |
123 |
|
|
number += 3) |
124 |
|
|
{ |
125 |
|
|
if (index - 3 > 0) |
126 |
|
|
{ |
127 |
|
|
format.insert(index - 3, 1, ','); |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
return format; |
132 |
|
|
} |
133 |
|
|
|
134 |
douglas |
255 |
#endif // _VTBFileUtil_h_ |