ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.h
Revision: 295
Committed: 2003-09-11T21:26:54-07:00 (21 years, 9 months ago) by douglas
Content type: text/x-c
File size: 2679 byte(s)
Log Message:
Using strsafe.h! Fancy!

File Contents

# User Rev Content
1 douglas 255 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 295 // $Id: VTBFileUtil2.h,v 1.18 2003/09/12 04:26:54 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 douglas 292 #include <fstream>
18 douglas 255 #include <cctype>
19     #include <vector>
20 douglas 265 #include <set>
21     #include <map>
22 douglas 259 #include <cstdlib>
23 douglas 255
24 douglas 285 #define _WIN32_IE 0x0500
25    
26 douglas 255 #include <windows.h>
27 douglas 277 #include <windowsx.h>
28 douglas 257 #include <commctrl.h>
29 douglas 264 #include <objbase.h>
30     #include <shlobj.h>
31 douglas 271 #include <shlwapi.h>
32 douglas 286 #include <richedit.h>
33 douglas 255
34 douglas 295 #define STRSAFE_LIB
35     #define STRSAFE_NO_CB_FUNCTIONS
36    
37     #include <strsafe.h>
38    
39 douglas 262 #include "resource.h"
40    
41 douglas 255 using namespace std;
42    
43 douglas 262 enum Mode { none, disc, scan };
44     struct Gui
45     {
46     HINSTANCE instance;
47     HICON icon;
48 douglas 277 int show;
49 douglas 262 };
50    
51 douglas 255 extern bool debug;
52     extern string program;
53     extern string programName;
54 douglas 256 extern string programVersion;
55 douglas 262 extern Gui gui;
56 douglas 255
57 douglas 259 void usage(HWND parent = NULL);
58     void version(HWND parent = NULL);
59 douglas 278
60 douglas 285 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 douglas 264 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 douglas 278
82 douglas 264 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 douglas 278
92 douglas 256 inline void center(HWND window)
93     {
94     RECT rect, dialog, desktop;
95 douglas 255
96 douglas 256 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 douglas 278
108 douglas 291 inline void error(HWND parent = NULL, LONG code = ERROR_SUCCESS)
109 douglas 269 {
110     LPVOID message;
111 douglas 256
112 douglas 291 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
113     NULL, code == ERROR_SUCCESS ? GetLastError() : code, 0,
114 douglas 269 LPTSTR(&message), 0, NULL);
115 douglas 278 MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR);
116 douglas 269 LocalFree(message);
117     }
118    
119 douglas 278 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 douglas 255 #endif // _VTBFileUtil_h_