2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: VTBFileUtil2.h,v 1.11 2003/08/24 07:31:45 douglas Exp $ |
5 |
> |
// $Id: VTBFileUtil2.h,v 1.13 2003/08/25 08:08:18 douglas Exp $ |
6 |
|
|
7 |
|
#ifndef _VTBFileUtil_h_ |
8 |
|
#define _VTBFileUtil_h_ |
47 |
|
|
48 |
|
void usage(HWND parent = NULL); |
49 |
|
void version(HWND parent = NULL); |
50 |
+ |
|
51 |
|
inline string toAnsi(const wstring& wide) |
52 |
|
{ |
53 |
|
LPSTR buffer = new CHAR[wide.length() + 1]; |
57 |
|
|
58 |
|
return buffer; |
59 |
|
} |
60 |
+ |
|
61 |
|
inline wstring toWide(const string& ansi) |
62 |
|
{ |
63 |
|
LPWSTR buffer = new WCHAR[ansi.length() + 1]; |
67 |
|
|
68 |
|
return buffer; |
69 |
|
} |
70 |
+ |
|
71 |
|
inline void center(HWND window) |
72 |
|
{ |
73 |
|
RECT rect, dialog, desktop; |
83 |
|
SetWindowPos(window, HWND_TOP, desktop.left + (rect.right / 2), desktop.top |
84 |
|
+ (rect.bottom / 2), 0, 0, SWP_NOSIZE); |
85 |
|
} |
86 |
< |
inline void error(void) |
86 |
> |
|
87 |
> |
inline void error(HWND parent = NULL) |
88 |
|
{ |
89 |
|
LPVOID message; |
90 |
|
|
91 |
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
92 |
|
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
93 |
|
LPTSTR(&message), 0, NULL); |
94 |
< |
MessageBox(NULL, LPCTSTR(message), programName.c_str(), MB_ICONERROR); |
94 |
> |
MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR); |
95 |
|
LocalFree(message); |
96 |
|
} |
97 |
|
|
98 |
+ |
inline string format(DWORD value) |
99 |
+ |
{ |
100 |
+ |
ostringstream buffer; |
101 |
+ |
|
102 |
+ |
buffer << value; |
103 |
+ |
|
104 |
+ |
string format = buffer.str(); |
105 |
+ |
|
106 |
+ |
for (int index = format.length(), number = 0; index > 0; index -= 3, |
107 |
+ |
number += 3) |
108 |
+ |
{ |
109 |
+ |
if (index - 3 > 0) |
110 |
+ |
{ |
111 |
+ |
format.insert(index - 3, 1, ','); |
112 |
+ |
} |
113 |
+ |
} |
114 |
+ |
|
115 |
+ |
return format; |
116 |
+ |
} |
117 |
+ |
|
118 |
|
#endif // _VTBFileUtil_h_ |