ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.h
Revision: 279
Committed: 2003-08-25T01:08:18-07:00 (21 years, 9 months ago) by douglas
Content type: text/x-c
File size: 2301 byte(s)
Log Message:
I guess I don't need to include <locale>.

File Contents

# User Rev Content
1 douglas 255 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 279 // $Id: VTBFileUtil2.h,v 1.13 2003/08/25 08:08:18 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     #include <windows.h>
24 douglas 277 #include <windowsx.h>
25 douglas 257 #include <commctrl.h>
26 douglas 264 #include <objbase.h>
27     #include <shlobj.h>
28 douglas 271 #include <shlwapi.h>
29 douglas 255
30 douglas 262 #include "resource.h"
31    
32 douglas 255 using namespace std;
33    
34 douglas 262 enum Mode { none, disc, scan };
35     struct Gui
36     {
37     HINSTANCE instance;
38     HICON icon;
39 douglas 277 int show;
40 douglas 262 };
41    
42 douglas 255 extern bool debug;
43     extern string program;
44     extern string programName;
45 douglas 256 extern string programVersion;
46 douglas 262 extern Gui gui;
47 douglas 255
48 douglas 259 void usage(HWND parent = NULL);
49     void version(HWND parent = NULL);
50 douglas 278
51 douglas 264 inline string toAnsi(const wstring& wide)
52     {
53     LPSTR buffer = new CHAR[wide.length() + 1];
54    
55     WideCharToMultiByte(CP_ACP, 0, wide.c_str(), wide.length() + 1, buffer,
56     wide.length() + 1, NULL, NULL);
57    
58     return buffer;
59     }
60 douglas 278
61 douglas 264 inline wstring toWide(const string& ansi)
62     {
63     LPWSTR buffer = new WCHAR[ansi.length() + 1];
64    
65     MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), ansi.length() + 1, buffer,
66     ansi.length() + 1);
67    
68     return buffer;
69     }
70 douglas 278
71 douglas 256 inline void center(HWND window)
72     {
73     RECT rect, dialog, desktop;
74 douglas 255
75 douglas 256 GetWindowRect(GetDesktopWindow(), &desktop);
76     GetWindowRect(window, &dialog);
77     CopyRect(&rect, &desktop);
78    
79     OffsetRect(&dialog, -dialog.left, -dialog.top);
80     OffsetRect(&rect, -rect.left, -rect.top);
81     OffsetRect(&rect, -dialog.right, -dialog.bottom);
82    
83     SetWindowPos(window, HWND_TOP, desktop.left + (rect.right / 2), desktop.top
84     + (rect.bottom / 2), 0, 0, SWP_NOSIZE);
85     }
86 douglas 278
87     inline void error(HWND parent = NULL)
88 douglas 269 {
89     LPVOID message;
90 douglas 256
91 douglas 269 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
92     FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
93     LPTSTR(&message), 0, NULL);
94 douglas 278 MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR);
95 douglas 269 LocalFree(message);
96     }
97    
98 douglas 278 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 douglas 255 #endif // _VTBFileUtil_h_