ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/VTBFileUtil2/VTBFileUtil2.h
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (16 years, 9 months ago) by douglas
Content type: text/x-c
File size: 2679 byte(s)
Log Message:
Rearranged everything else.

File Contents

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