📄 eccmisc.cpp
字号:
/* ==========================================================================
Ecc - Erik's Code Collection
Copyright (C) 2003 - Erik Dienske
This file is part of Ecc.
Ecc is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Ecc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ecc; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
===========================================================================*/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "EccMisc.h"
#include "Registry.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
//===========================================================================
namespace ecc {
//===========================================================================
String GetSystemFolder(const TEccSystemFolder sf)
{
String key_name;
switch (sf)
{
case sfDesktop:
key_name = "Desktop";
break;
case sfFavorites:
key_name = "Favorites";
break;
case sfPersonal:
key_name = "Personal";
break;
case sfPrograms:
key_name = "Programs";
break;
case sfQuickLaunch:
key_name = "Quick Launch";
break;
case sfRecent:
key_name = "Recent";
break;
case sfStartMenu:
key_name = "Start Menu";
break;
case sfStartup:
key_name = "Startup";
break;
default:
return "";
}
String key_str = "\\Software\\Microsoft\\Windows\\CurrentVersion\\";
if (sf == sfQuickLaunch)
key_str += "GrpConv\\MapGroups";
else
key_str += "Explorer\\Shell Folders";
const String c_key_str = key_str;
String folder;
TRegistry *reg = new TRegistry();
try
{
if (reg->OpenKey(c_key_str, false))
{
folder = reg->ReadString(key_name);
reg->CloseKey();
}
}
__finally
{ delete reg; }
return folder;
}
//---------------------------------------------------------------------------
//===========================================================================
static int EccHourGlassCount;
/* Increases with every HourGlass(true);
Decreases with every HourGlass(false);
When EccHourGlassCount is not 0 the Screen->Cursor displays an hourglass. */
//---------------------------------------------------------------------------
int GetHourGlassCount()
{
return EccHourGlassCount;
}
//---------------------------------------------------------------------------
void ResetHourGlass()
{
EccHourGlassCount = 0;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void HourGlass(const bool state)
{
if (state) ++EccHourGlassCount;
else --EccHourGlassCount;
Screen->Cursor = (EccHourGlassCount) ? crHourGlass : crDefault;
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
//===========================================================================
bool ConfirmBox(const String msg, const String caption)
{
return (
Application->MessageBox( msg.c_str(), caption.c_str(), MB_YESNO )
== IDYES );
}
//---------------------------------------------------------------------------
String GetSystemUserName()
{
#define USERNAME_BUFSIZE 1024
LPTSTR lpszSystemInfo; // pointer to system information string
DWORD cchBuff = USERNAME_BUFSIZE - 1; // size of computer or user name
TCHAR tchBuffer[USERNAME_BUFSIZE]; // buffer for string
lpszSystemInfo = tchBuffer;
// Get the user name:
String uname = "unknown_user";
if( GetUserName(lpszSystemInfo, &cchBuff) )
uname = String(lpszSystemInfo);
return uname;
}
//---------------------------------------------------------------------------
void InitRandomizer()
{
Word Hour, Min, Sec, MSec;
DecodeTime(Now(), Hour, Min, Sec, MSec);
srand((MSec+Hour)*(Sec+Min));
}
//---------------------------------------------------------------------------
//===========================================================================
} // namespace ecc;
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -