1.读注册表
static const int MaxBufferSize = 256;
UFUNCTION(BlueprintPure)
static FString ReadRegistryValue(const FString& PathDir, const FString& KeyName, bool& bIsFind);
FString AMyActor::ReadRegistryValue(const FString& PathDir, const FString& KeyName, bool& bIsFind)
{
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, *PathDir, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
TCHAR Buffer[MaxBufferSize];
DWORD BufferSize = sizeof(Buffer);
HRESULT hResult = RegQueryValueEx(hKey, *KeyName, 0, nullptr, reinterpret_cast<LPBYTE>(Buffer), &BufferSize);
if (hResult != 0)
{
// Handle error
return "no key";
}
bIsFind = true;
return FString(Buffer);
}
return "no Rout";
}
2.写注册表
UFUNCTION(BlueprintCallable)
static bool WriteRegistryValue(const FString &PathDir, const FString &KeyName, const FString &ValueName);
bool AMyActor::WriteRegistryValue(const FString &PathDir, const FString &KeyName, const FString &ValueName)
{
bool bRes = false;
HKEY hRootKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, *PathDir, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hRootKey, NULL) == ERROR_SUCCESS)
{
LRESULT SetResult = RegSetValueEx(hRootKey, *KeyName, 0, REG_SZ, (const BYTE*)*ValueName, (ValueName.Len() + 1) * sizeof(TCHAR));
RegCloseKey(hRootKey);
if (SetResult == ERROR_SUCCESS)
{
bRes = true;
}
}
return bRes;
}
3.复制到剪切板
bool URegisteLibrary::SetCopyString(const FString content)
{
HWND hWnd = NULL;
OpenClipboard(hWnd);//打开剪切板
EmptyClipboard();//清空剪切板
HANDLE hHandle = GlobalAlloc(GMEM_FIXED, 1000);//分配内存
char* pData = (char*)GlobalLock(hHandle);//锁定内存,返回申请内存的首地址
//pData = TCHAR_TO_UTF8(*content);
strcpy(pData, TCHAR_TO_UTF8(*content));
SetClipboardData(CF_TEXT, hHandle);//设置剪切板数据
GlobalUnlock(hHandle);//解除锁定
CloseClipboard();//关闭剪切板
if (IsClipboardFormatAvailable(CF_TEXT))
{
return true;
}
else
{
return false;
}
}
4.读取剪切板
FString URegisteLibrary::GetCopyString()
{
HWND hWnd = NULL;
OpenClipboard(hWnd);
//EmptyClipboard();
if (IsClipboardFormatAvailable(CF_TEXT))
{
HANDLE h = GetClipboardData(CF_TEXT);//获取剪切板数据
char* p = (char*)GlobalLock(h);
GlobalUnlock(h);
CloseClipboard();
return UTF8_TO_TCHAR(p);
}
else
{
return "noCopyString";
}
}
读写剪切板2
// 读取剪贴板
FPlatformApplicationMisc::ClipboardPaste(MyString);
// 拷贝剪贴板
FPlatformApplicationMisc::ClipboardCopy(MyString);