2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: VTBFileUtil2.h,v 1.10 2003/08/20 05:49:34 douglas Exp $ |
5 |
> |
// $Id: VTBFileUtil2.h,v 1.17 2003/09/09 01:43:28 douglas Exp $ |
6 |
|
|
7 |
|
#ifndef _VTBFileUtil_h_ |
8 |
|
#define _VTBFileUtil_h_ |
14 |
|
#include <iostream> |
15 |
|
#include <string> |
16 |
|
#include <sstream> |
17 |
+ |
#include <fstream> |
18 |
|
#include <cctype> |
19 |
|
#include <vector> |
20 |
|
#include <set> |
21 |
|
#include <map> |
22 |
|
#include <cstdlib> |
23 |
|
|
24 |
+ |
#define _WIN32_IE 0x0500 |
25 |
+ |
|
26 |
|
#include <windows.h> |
27 |
+ |
#include <windowsx.h> |
28 |
|
#include <commctrl.h> |
29 |
|
#include <objbase.h> |
30 |
|
#include <shlobj.h> |
31 |
|
#include <shlwapi.h> |
32 |
+ |
#include <richedit.h> |
33 |
|
|
34 |
|
#include "resource.h" |
35 |
|
|
40 |
|
{ |
41 |
|
HINSTANCE instance; |
42 |
|
HICON icon; |
43 |
+ |
int show; |
44 |
|
}; |
45 |
|
|
46 |
|
extern bool debug; |
51 |
|
|
52 |
|
void usage(HWND parent = NULL); |
53 |
|
void version(HWND parent = NULL); |
54 |
+ |
|
55 |
+ |
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 |
|
inline string toAnsi(const wstring& wide) |
68 |
|
{ |
69 |
|
LPSTR buffer = new CHAR[wide.length() + 1]; |
73 |
|
|
74 |
|
return buffer; |
75 |
|
} |
76 |
+ |
|
77 |
|
inline wstring toWide(const string& ansi) |
78 |
|
{ |
79 |
|
LPWSTR buffer = new WCHAR[ansi.length() + 1]; |
83 |
|
|
84 |
|
return buffer; |
85 |
|
} |
86 |
+ |
|
87 |
|
inline void center(HWND window) |
88 |
|
{ |
89 |
|
RECT rect, dialog, desktop; |
99 |
|
SetWindowPos(window, HWND_TOP, desktop.left + (rect.right / 2), desktop.top |
100 |
|
+ (rect.bottom / 2), 0, 0, SWP_NOSIZE); |
101 |
|
} |
102 |
< |
inline void error(void) |
102 |
> |
|
103 |
> |
inline void error(HWND parent = NULL, LONG code = ERROR_SUCCESS) |
104 |
|
{ |
105 |
|
LPVOID message; |
106 |
|
|
107 |
< |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
108 |
< |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
107 |
> |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
108 |
> |
NULL, code == ERROR_SUCCESS ? GetLastError() : code, 0, |
109 |
|
LPTSTR(&message), 0, NULL); |
110 |
< |
MessageBox(NULL, LPCTSTR(message), programName.c_str(), MB_ICONERROR); |
110 |
> |
MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR); |
111 |
|
LocalFree(message); |
112 |
|
} |
113 |
|
|
114 |
+ |
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 |
|
#endif // _VTBFileUtil_h_ |