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