?? common.cpp
字號:
//+-----------------------------------------------------------------------------
//| Included files
//+-----------------------------------------------------------------------------
#include "Common.h"
//+-----------------------------------------------------------------------------
//| Global objects
//+-----------------------------------------------------------------------------
COMMON Common;
//+-----------------------------------------------------------------------------
//| Constructor
//+-----------------------------------------------------------------------------
COMMON::COMMON()
{
//Empty
}
//+-----------------------------------------------------------------------------
//| Destructor
//+-----------------------------------------------------------------------------
COMMON::~COMMON()
{
//Empty
}
//+-----------------------------------------------------------------------------
//| Copies a string into the clipboard
//+-----------------------------------------------------------------------------
BOOL COMMON::SetClipboardData(CONST std::string& String)
{
HGLOBAL GlobalString;
CHAR* GlobalStringPointer;
if(!::OpenClipboard(NULL))
{
Error.SetMessage("Unable to open the clipboard!");
return FALSE;
}
GlobalString = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, static_cast<INT>(String.size()) + 1);
if(GlobalString == NULL)
{
::CloseClipboard();
Error.SetMessage("Unable to allocate memory for the clipboard data!");
return FALSE;
}
EmptyClipboard();
GlobalStringPointer = reinterpret_cast<CHAR*>(::GlobalLock(GlobalString));
if(GlobalStringPointer == NULL)
{
::CloseClipboard();
Error.SetMessage("Unable to lock the global memory!");
return FALSE;
}
std::memcpy(GlobalStringPointer, String.c_str(), static_cast<INT>(String.size()) + 1);
::GlobalUnlock(GlobalString);
::SetClipboardData(CF_TEXT, GlobalString);
::CloseClipboard();
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Retrieves a string from the clipboard
//+-----------------------------------------------------------------------------
std::string COMMON::GetClipboardData()
{
INT Size;
HGLOBAL GlobalString;
CHAR* GlobalStringPointer;
std::vector<CHAR> Buffer;
if(!::OpenClipboard(NULL)) return "";
GlobalString = ::GetClipboardData(CF_TEXT);
if(GlobalString == NULL)
{
::CloseClipboard();
return "";
}
GlobalStringPointer = reinterpret_cast<CHAR*>(::GlobalLock(GlobalString));
if(GlobalStringPointer == NULL)
{
::CloseClipboard();
return "";
}
Size = static_cast<INT>(std::strlen(GlobalStringPointer));
Buffer.resize(Size + 1);
std::memcpy(&Buffer[0], GlobalStringPointer, Size);
Buffer[Size] = '\0';
::GlobalUnlock(GlobalString);
::CloseClipboard();
return &Buffer[0];
}
//+-----------------------------------------------------------------------------
//| Checks if a point is inside a rect
//+-----------------------------------------------------------------------------
BOOL COMMON::PointInsideRect(CONST POINT& Point, CONST RECT& Rect) CONST
{
if(Point.x < Rect.left) return FALSE;
if(Point.y < Rect.top) return FALSE;
if(Point.x >= Rect.right) return FALSE;
if(Point.y >= Rect.bottom) return FALSE;
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Turns the string into all lowercase characters
//+-----------------------------------------------------------------------------
std::string COMMON::LowerCase(CONST std::string& String) CONST
{
INT i;
std::string Result = String;
for(i = 0; i < static_cast<INT>(Result.size()); i++)
{
Result[i] = std::tolower(Result[i]);
}
return Result;
}
//+-----------------------------------------------------------------------------
//| Turns the string into all uppercase characters
//+-----------------------------------------------------------------------------
std::string COMMON::UpperCase(CONST std::string& String) CONST
{
INT i;
std::string Result = String;
for(i = 0; i < static_cast<INT>(Result.size()); i++)
{
Result[i] = std::toupper(Result[i]);
}
return Result;
}
//+-----------------------------------------------------------------------------
//| Returns the path of a filename
//+-----------------------------------------------------------------------------
std::string COMMON::GetPath(CONST std::string& FileName) CONST
{
INT i;
i = static_cast<INT>(FileName.rfind("\\"));
if(i == std::string::npos)
{
i = static_cast<INT>(FileName.rfind("/"));
if(i == std::string::npos)
{
return "";
}
}
return FileName.substr(0, i + 1);
}
//+-----------------------------------------------------------------------------
//| Returns the name of a filename
//+-----------------------------------------------------------------------------
std::string COMMON::GetName(CONST std::string& FileName) CONST
{
INT i;
INT j;
i = static_cast<INT>(FileName.rfind("\\"));
if(i == std::string::npos)
{
i = static_cast<INT>(FileName.rfind("/"));
if(i == std::string::npos)
{
i = -1;
}
}
j = static_cast<INT>(FileName.rfind("."));
if(j == std::string::npos) j = static_cast<INT>(FileName.size());
return FileName.substr(i + 1, j - i - 1);
}
//+-----------------------------------------------------------------------------
//| Returns the filename of a filename (excluding the path)
//+-----------------------------------------------------------------------------
std::string COMMON::GetFileName(CONST std::string& FileName) CONST
{
INT i;
i = static_cast<INT>(FileName.rfind("\\"));
if(i == std::string::npos)
{
i = static_cast<INT>(FileName.rfind("/"));
if(i == std::string::npos)
{
return FileName;
}
}
return FileName.substr(i + 1, FileName.size() - i - 1);
}
//+-----------------------------------------------------------------------------
//| Returns the extention of a filename
//+-----------------------------------------------------------------------------
std::string COMMON::GetExtention(CONST std::string& FileName) CONST
{
INT i;
i = static_cast<INT>(FileName.rfind("."));
if(i == std::string::npos) return "";
return FileName.substr(i + 1, FileName.size() - i - 1);
}
//+-----------------------------------------------------------------------------
//| Splits a filename into path, name and extention
//+-----------------------------------------------------------------------------
VOID COMMON::SplitFileName(std::string& FullFileName, std::string& Path, std::string& Name, std::string& FileName,std::string& Extention) CONST
{
INT i;
INT j;
i = static_cast<INT>(FullFileName.rfind("\\"));
if(i == std::string::npos)
{
i = static_cast<INT>(FullFileName.rfind("/"));
if(i == std::string::npos)
{
i = -1;
}
}
j = static_cast<INT>(FullFileName.rfind("."));
if(j == std::string::npos) j = static_cast<INT>(FullFileName.size());
Path = (i >= 0) ? FullFileName.substr(0, i + 1) : "";
Name = FullFileName.substr(i + 1, j - i - 1);
FileName = FullFileName.substr(i + 1, FullFileName.size() - i - 1);
Extention = (j < static_cast<INT>(FullFileName.size())) ? FullFileName.substr(i + 1, FullFileName.size() - i - 1) : "";
}
//+-----------------------------------------------------------------------------
//| Returns the program filename
//+-----------------------------------------------------------------------------
std::string COMMON::GetProgramFileName() CONST
{
INT i;
std::string FileName;
CHAR Buffer[BUFFER_SIZE];
::GetModuleFileName(NULL, Buffer, BUFFER_SIZE - 1);
FileName = Buffer;
i = static_cast<INT>(FileName.rfind("\\"));
if(i != std::string::npos)
{
FileName = FileName.substr((i + 1), (static_cast<INT>(FileName.size()) - (i + 1)));
}
return FileName;
}
//+-----------------------------------------------------------------------------
//| Returns the program directory
//+-----------------------------------------------------------------------------
std::string COMMON::GetProgramDirectory() CONST
{
INT i;
std::string Directory;
CHAR Buffer[BUFFER_SIZE];
::GetModuleFileName(NULL, Buffer, BUFFER_SIZE - 1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -