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