ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.h
Revision: 285
Committed: 2003-09-02T20:40:35-07:00 (21 years, 9 months ago) by douglas
Content type: text/x-c
File size: 2506 byte(s)
Log Message:
The world turns.

File Contents

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