Feature: Add menu to set screen strategy for remote control

This commit is contained in:
yuanyuanxiang
2026-01-08 22:10:38 +01:00
parent e0239dce8d
commit 808371ed6e
31 changed files with 541 additions and 425 deletions

View File

@@ -51,24 +51,24 @@ static inline std::string GetRegistryName() {
return name;
}
// 鑾峰彇褰撳墠浼氳瘽鐢ㄦ埛鐨勬敞鍐岃〃鏍归敭
// SYSTEM 杩涚▼鏃犳硶浣跨敤 HKEY_CURRENT_USER锛岄渶瑕侀€氳繃 HKEY_USERS\<SID> 璁块棶
// 杩斿洖鐨?HKEY 闇€瑕佽皟鐢ㄨ€呭湪浣跨敤瀹屾瘯鍚庤皟鐢?RegCloseKey 鍏抽棴
// 获取当前会话用户的注册表根键
// SYSTEM 进程无法使用 HKEY_CURRENT_USER,需要通过 HKEY_USERS\<SID> 访问
// 返回的 HKEY 需要调用者在使用完毕后调用 RegCloseKey 关闭
inline HKEY GetCurrentUserRegistryKey()
{
HKEY hUserKey = NULL;
// 鑾峰彇褰撳墠杩涚▼鐨勪細璇?ID
// 获取当前进程的会话 ID
DWORD sessionId = 0;
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
// 鑾峰彇璇ヤ細璇濈殑鐢ㄦ埛浠ょ墝
// 获取该会话的用户令牌
HANDLE hUserToken = NULL;
if (!WTSQueryUserToken(sessionId, &hUserToken)) {
// 濡傛灉澶辫触锛堝彲鑳戒笉鏄湇鍔¤繘绋嬶級锛屽洖閫€鍒?HKEY_CURRENT_USER
// 如果失败(可能不是服务进程),回退到 HKEY_CURRENT_USER
return HKEY_CURRENT_USER;
}
// 鑾峰彇浠ょ墝涓殑鐢ㄦ埛淇℃伅澶у皬
// 获取令牌中的用户信息大小
DWORD dwSize = 0;
GetTokenInformation(hUserToken, TokenUser, NULL, 0, &dwSize);
if (dwSize == 0) {
@@ -76,7 +76,7 @@ inline HKEY GetCurrentUserRegistryKey()
return HKEY_CURRENT_USER;
}
// 鍒嗛厤鍐呭瓨骞惰幏鍙栫敤鎴蜂俊鎭?
// 分配内存并获取用户信息
TOKEN_USER* pTokenUser = (TOKEN_USER*)malloc(dwSize);
if (!pTokenUser) {
SAFE_CLOSE_HANDLE(hUserToken);
@@ -89,7 +89,7 @@ inline HKEY GetCurrentUserRegistryKey()
return HKEY_CURRENT_USER;
}
// 灏?SID 杞崲涓哄瓧绗︿覆
// SID 转换为字符串
LPSTR szSid = NULL;
if (!ConvertSidToStringSidA(pTokenUser->User.Sid, &szSid)) {
free(pTokenUser);
@@ -97,9 +97,9 @@ inline HKEY GetCurrentUserRegistryKey()
return HKEY_CURRENT_USER;
}
// 鎵撳紑 HKEY_USERS\<SID>
// 打开 HKEY_USERS\<SID>
if (RegOpenKeyExA(HKEY_USERS, szSid, 0, KEY_READ | KEY_WRITE, &hUserKey) != ERROR_SUCCESS) {
// 灏濊瘯鍙鏂瑰紡
// 尝试只读方式
if (RegOpenKeyExA(HKEY_USERS, szSid, 0, KEY_READ, &hUserKey) != ERROR_SUCCESS) {
hUserKey = NULL;
}
@@ -112,7 +112,7 @@ inline HKEY GetCurrentUserRegistryKey()
return hUserKey ? hUserKey : HKEY_CURRENT_USER;
}
// 妫€鏌ユ槸鍚﹂渶瑕佸叧闂敞鍐岃〃鏍归敭锛堥潪棰勫畾涔夐敭闇€瑕佸叧闂級
// 检查是否需要关闭注册表根键(非预定义键需要关闭)
inline void CloseUserRegistryKeyIfNeeded(HKEY hKey)
{
if (hKey != HKEY_CURRENT_USER &&
@@ -130,7 +130,7 @@ inline void CloseUserRegistryKeyIfNeeded(HKEY hKey)
#endif
// 閰嶇疆璇诲彇绫? 鏂囦欢閰嶇疆.
// 配置读取类: 文件配置.
class config
{
private:
@@ -154,7 +154,7 @@ public:
return ::GetPrivateProfileIntA(MainKey.c_str(), SubKey.c_str(), nDef, m_IniFilePath);
}
// 鑾峰彇閰嶇疆椤逛腑鐨勭涓€涓暣鏁?
// 获取配置项中的第一个整数
virtual int Get1Int(const std::string& MainKey, const std::string& SubKey, char ch=';', int nDef=0)
{
std::string s = GetStr(MainKey, SubKey, "");
@@ -181,7 +181,7 @@ public:
}
};
// 閰嶇疆璇诲彇绫? 娉ㄥ唽琛ㄩ厤缃?
// 配置读取类: 注册表配置.
class iniFile : public config
{
private:
@@ -204,13 +204,13 @@ public:
}
}
// 鍐欏叆鏁存暟锛屽疄闄呭啓涓哄瓧绗︿覆
// 写入整数,实际写为字符串
bool SetInt(const std::string& MainKey, const std::string& SubKey, int Data) override
{
return SetStr(MainKey, SubKey, std::to_string(Data));
}
// 鍐欏叆瀛楃涓?
// 写入字符串
bool SetStr(const std::string& MainKey, const std::string& SubKey, const std::string& Data) override
{
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
@@ -225,7 +225,7 @@ public:
return bRet;
}
// 璇诲彇瀛楃涓?
// 读取字符串
std::string GetStr(const std::string& MainKey, const std::string& SubKey, const std::string& def = "") override
{
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
@@ -245,7 +245,7 @@ public:
return result;
}
// 璇诲彇鏁存暟锛屽厛浠庡瓧绗︿覆涓浆鎹?
// 读取整数,先从字符串中转换
int GetInt(const std::string& MainKey, const std::string& SubKey, int defVal = 0) override
{
std::string val = GetStr(MainKey, SubKey);
@@ -282,19 +282,19 @@ public:
}
}
// 鍐欏叆鏁存暟锛堝啓涓轰簩杩涘埗锛?
// 写入整数(写为二进制)
bool SetInt(const std::string& MainKey, const std::string& SubKey, int Data) override
{
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(&Data), sizeof(int));
}
// 鍐欏叆瀛楃涓诧紙浠ヤ簩杩涘埗鏂瑰紡锛?
// 写入字符串(以二进制方式)
bool SetStr(const std::string& MainKey, const std::string& SubKey, const std::string& Data) override
{
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(Data.data()), static_cast<DWORD>(Data.size()));
}
// 璇诲彇瀛楃涓诧紙浠庝簩杩涘埗鏁版嵁杞崲锛?
// 读取字符串(从二进制数据转换)
std::string GetStr(const std::string& MainKey, const std::string& SubKey, const std::string& def = "") override
{
std::vector<BYTE> buffer;
@@ -304,7 +304,7 @@ public:
return std::string(buffer.begin(), buffer.end());
}
// 璇诲彇鏁存暟锛堜粠浜岃繘鍒惰В鏋愶級
// 读取整数(从二进制解析)
int GetInt(const std::string& MainKey, const std::string& SubKey, int defVal = 0) override
{
std::vector<BYTE> buffer;
@@ -348,4 +348,4 @@ private:
RegCloseKey(hKey);
return bRet;
}
};
};