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