ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.h
Revision: 278
Committed: 2003-08-25T00:29:00-07:00 (21 years, 9 months ago) by douglas
Content type: text/x-c
File size: 2319 byte(s)
Log Message:
Almost finished with Scan Utility.

File Contents

# Content
1 // Vance Thrift and Biller File Utility 2
2 //
3 // Douglas Thrift
4 //
5 // $Id: VTBFileUtil2.h,v 1.12 2003/08/25 07:29:00 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 <locale>
16 #include <string>
17 #include <sstream>
18 #include <cctype>
19 #include <vector>
20 #include <set>
21 #include <map>
22 #include <cstdlib>
23
24 #include <windows.h>
25 #include <windowsx.h>
26 #include <commctrl.h>
27 #include <objbase.h>
28 #include <shlobj.h>
29 #include <shlwapi.h>
30
31 #include "resource.h"
32
33 using namespace std;
34
35 enum Mode { none, disc, scan };
36 struct Gui
37 {
38 HINSTANCE instance;
39 HICON icon;
40 int show;
41 };
42
43 extern bool debug;
44 extern string program;
45 extern string programName;
46 extern string programVersion;
47 extern Gui gui;
48
49 void usage(HWND parent = NULL);
50 void version(HWND parent = NULL);
51
52 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
62 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
72 inline void center(HWND window)
73 {
74 RECT rect, dialog, desktop;
75
76 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
88 inline void error(HWND parent = NULL)
89 {
90 LPVOID message;
91
92 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
93 FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
94 LPTSTR(&message), 0, NULL);
95 MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR);
96 LocalFree(message);
97 }
98
99 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 #endif // _VTBFileUtil_h_