UE4 C++ windows操作

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);

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值