// Vance Thrift and Biller File Utility 2 // // Douglas Thrift // // $Id: VTBFileUtil2.h,v 1.18 2003/09/12 04:26:54 douglas Exp $ #ifndef _VTBFileUtil_h_ #define _VTBFileUtil_h_ #ifdef _DEBUG #pragma warning(disable:4786) #endif // _DEBUG #include #include #include #include #include #include #include #include #include #define _WIN32_IE 0x0500 #include #include #include #include #include #include #include #define STRSAFE_LIB #define STRSAFE_NO_CB_FUNCTIONS #include #include "resource.h" using namespace std; enum Mode { none, disc, scan }; struct Gui { HINSTANCE instance; HICON icon; int show; }; extern bool debug; extern string program; extern string programName; extern string programVersion; extern Gui gui; void usage(HWND parent = NULL); void version(HWND parent = NULL); inline string toLower(const string& mixed) { string lower; for (unsigned index = 0; index < mixed.length(); index++) { lower += tolower(mixed[index]); } return lower; } inline string toAnsi(const wstring& wide) { LPSTR buffer = new CHAR[wide.length() + 1]; WideCharToMultiByte(CP_ACP, 0, wide.c_str(), wide.length() + 1, buffer, wide.length() + 1, NULL, NULL); return buffer; } inline wstring toWide(const string& ansi) { LPWSTR buffer = new WCHAR[ansi.length() + 1]; MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), ansi.length() + 1, buffer, ansi.length() + 1); return buffer; } inline void center(HWND window) { RECT rect, dialog, desktop; GetWindowRect(GetDesktopWindow(), &desktop); GetWindowRect(window, &dialog); CopyRect(&rect, &desktop); OffsetRect(&dialog, -dialog.left, -dialog.top); OffsetRect(&rect, -rect.left, -rect.top); OffsetRect(&rect, -dialog.right, -dialog.bottom); SetWindowPos(window, HWND_TOP, desktop.left + (rect.right / 2), desktop.top + (rect.bottom / 2), 0, 0, SWP_NOSIZE); } inline void error(HWND parent = NULL, LONG code = ERROR_SUCCESS) { LPVOID message; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, code == ERROR_SUCCESS ? GetLastError() : code, 0, LPTSTR(&message), 0, NULL); MessageBox(parent, LPCTSTR(message), programName.c_str(), MB_ICONERROR); LocalFree(message); } inline string format(DWORD value) { ostringstream buffer; buffer << value; string format = buffer.str(); for (int index = format.length(), number = 0; index > 0; index -= 3, number += 3) { if (index - 3 > 0) { format.insert(index - 3, 1, ','); } } return format; } #endif // _VTBFileUtil_h_