Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
2 Star 4 Fork 4

精易科技/eapi

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
eapi
/
cppCode
/
eapi_23_AddRightMenu.cpp
eapi
/
cppCode
/
eapi_23_AddRightMenu.cpp
eapi_23_AddRightMenu.cpp 8.51 KB
Copy Edit Raw Blame History
AlongsCode authored 2023年02月09日 00:42 +08:00 . 部分重构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
#include "..\include_eapi_header.h"
#include <optional>
#include <algorithm>
using namespace std;
#undef max
namespace eapiRightMenu
{
static std::string ReplaceSubText(std::string text, const std::string& to_replace, std::optional<size_t> replace_count = std::nullopt) {
size_t search_start = 0;
size_t count = replace_count.value_or(std::numeric_limits<size_t>::max());
std::string replace = "";
size_t pos = text.find(to_replace, search_start);
while (pos != std::string::npos && count > 0) {
text.replace(pos, to_replace.length(), replace);
pos = text.find(to_replace, pos + replace.length());
--count;
}
return text;
}
static vector<string> EnumRegistryKey(HKEY root, string path)
{
REGSAM Type;
HKEY pHkey;
SYSTEM_INFO INFO;
std::vector<string> ret;
pHkey = 0;
GetNativeSystemInfo(&INFO);
if (INFO.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Type = KEY_WOW64_32KEY | KEY_ALL_ACCESS, INFO.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {
Type = KEY_WOW64_64KEY | KEY_ALL_ACCESS;
}
RegOpenKeyExA(root, path.c_str(), 1, Type, &pHkey);
char name[MAX_PATH] = {};
if (!RegEnumKeyA(pHkey, 0, name, MAX_PATH))
{
ret.push_back(name);
if (!RegEnumKeyA(pHkey, 1, name, MAX_PATH))
{
DWORD i = 2;
do {
ret.push_back(name);
} while (!RegEnumKeyA(pHkey, i++, name, MAX_PATH));
}
RegCloseKey(pHkey);
}
return ret;
}
static void DleteMore(const string& name, HKEY hkey, const string& parpath, HKEY handle, const string& livepath)
{
vector<string> data;
DWORD samDesired;
SYSTEM_INFO SystemInfo;
string needhandle;
GetNativeSystemInfo(&SystemInfo);
if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
samDesired = KEY_WOW64_64KEY;
}
do
{
data = EnumRegistryKey(hkey, livepath);
for (size_t i = 0; i < data.size(); ++i)
{
if (!EnumRegistryKey(hkey, livepath + "\\" + data[i]).empty()) {
DleteMore(name, hkey, parpath, handle, livepath + "\\" + data[i]);
}
else {
needhandle = ReplaceSubText(livepath + "\\" + data[i], parpath + "\\", 1);
RegDeleteKeyExA(handle, needhandle.c_str(), samDesired, 0);
}
}
} while (EnumRegistryKey(hkey, livepath).size() >= 1);
needhandle = ReplaceSubText(livepath, parpath + "\\");
RegDeleteKeyExA(handle, needhandle.c_str(), samDesired, 0);
}
/**
* @brief 删除带有给定标题的右键菜单。
*
* @param 要使用的范围或扩展名。
* @param Title要删除的右键菜单的标题。
*
* @return 如果成功删除右键菜单,返回 true,否则返回false。
*/
static bool DeleteRightMenu(const string& Rangeorextensiontobeused, const string& Title) {
SYSTEM_INFO SystemInfo;
GetNativeSystemInfo(&SystemInfo);
REGSAM Accessrights, samDesired;
if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {
Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;
}
if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64))
{
samDesired = KEY_WOW64_64KEY;
}
HKEY hKey;
;
if (RegOpenKeyExA(HKEY_CLASSES_ROOT, 0, 0, Accessrights, &hKey) != ERROR_SUCCESS)
{
return false;
}
if (!EnumRegistryKey(HKEY_CLASSES_ROOT, "\\" + Title).empty())
{
DleteMore(Title, HKEY_CLASSES_ROOT, "", hKey, "\\" + Title);
}
else if (RegDeleteKeyExA(hKey, Title.c_str(), samDesired, 0)) {
RegCloseKey(hKey);
return false;
};
RegCloseKey(hKey);
return true;
}
/**
* @brief 用于在 Windows 系统中添加右键菜单
*
* @param rangeOrExtensionToBeUsed:使用的范围或扩展名
* @param title:要添加的右键菜单的标题。
* @param comLine:右键菜单的命令行。
* @param shortKey:右键菜单的快捷键。
* @param icon:右键菜单的图标。
* @param shiftDisplay:右键菜单的显示位置(是否在Shift按下时显示)。
*
* @return 如果成功删除右键菜单,返回 true,否则返回false。
*/
static bool AddRightMenu(
const std::string& Rangeorextensiontobeused,
const std::string& Title,
const std::string& comline,
const std::string& shortkey,
const std::string& icon,
bool shiftdisplay) {
string Actionpath;
if (Rangeorextensiontobeused == "*")
{
Actionpath = "Directory\\Background\\shell";
}
else if (Rangeorextensiontobeused == "D")
{
Actionpath = "DesktopBackground\\Shell";
}
else if (Rangeorextensiontobeused == "URL")
{
Actionpath = "Directory\\shell";
}
else
{
Actionpath = "*\\shell";
if (Rangeorextensiontobeused != "SAVER") {
Actionpath = Rangeorextensiontobeused;
}
}
HKEY phkResult = 0;
SYSTEM_INFO SystemInfo;
GetNativeSystemInfo(&SystemInfo);
REGSAM Accessrights, samDesired;
if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {
Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;
}
if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64))
{
samDesired = KEY_WOW64_64KEY;
}
RegCreateKeyExA(HKEY_CLASSES_ROOT, Actionpath.c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);
if (!phkResult) {
return false;
}
RegSetValueExA(phkResult, "SubCommands", 0, REG_SZ, 0, 0);
RegCloseKey(phkResult);
string lpSubKey = Actionpath + "\\shell";
GetNativeSystemInfo(&SystemInfo);
RegCreateKeyExA(HKEY_CLASSES_ROOT, lpSubKey.c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);
if (!phkResult) {
return false;
}
HKEY hKey = 0;
RegOpenKeyExA(HKEY_CLASSES_ROOT, lpSubKey.c_str(), 0, Accessrights, &hKey);
string lpPstr = lpSubKey;
lpSubKey = lpSubKey + "\\" + Actionpath + "\\shell" + "\\" + Title;
if (EnumRegistryKey(HKEY_CLASSES_ROOT, lpSubKey).size() <= 0) {
RegDeleteKeyExA(hKey, (Actionpath + "\\shell" + "\\" + Title).c_str(), samDesired, 0);
}
else
{
DleteMore((Actionpath + "\\shell" + "\\" + Title), HKEY_CLASSES_ROOT, lpPstr, hKey, lpSubKey);
}
RegCloseKey(hKey);
;
RegCloseKey(phkResult);
RegCreateKeyExA(HKEY_CLASSES_ROOT, (Actionpath + "\\shell" + "\\" + Title).c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);
if (!phkResult) {
return false;
}
if (!shortkey.empty())
{
string temp = Title + "(&" + shortkey + ")";
RegSetValueExA(phkResult, "MUIVerb", 0, REG_SZ, (const BYTE*)temp.c_str(), temp.size());
}
else
{
RegSetValueExA(phkResult, "MUIVerb", 0, REG_SZ, (const BYTE*)Title.c_str(), Title.size());
}
if (!icon.empty())
{
RegSetValueExA(phkResult, "icon", 0, REG_SZ, (const BYTE*)icon.c_str(), icon.size());
}
if (shiftdisplay) {
RegSetValueExA(phkResult, "Extended", 0, REG_SZ, 0, 0);
}
RegCloseKey(phkResult);
RegCreateKeyExA(HKEY_CLASSES_ROOT, (Actionpath + "\\shell" + "\\" + Title + "\\command").c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, Accessrights, NULL, &phkResult, NULL);
if (phkResult)
{
RegSetValueExA(phkResult, 0, 0, REG_SZ, (const BYTE*)comline.c_str(), comline.size());
return 1;
}
return 0;
}
};
EAPI_EXTERN_C void eapi_AddRightMenu_23_eapi(PMDATA_INF pRetData, INT nArgCount, PMDATA_INF pArgInf)
{
std::string RangeOrExtName = "*", title, commandline, shortkey, icon;
BOOL shiftdisplay = FALSE;
if (pArgInf[0].m_dtDataType && pArgInf[0].m_pText && strlen(pArgInf[0].m_pText))
{
RangeOrExtName = pArgInf[0].m_pText;
}
if (pArgInf[1].m_dtDataType && pArgInf[1].m_pText)
{
title = pArgInf[1].m_pText;
}
if (pArgInf[2].m_dtDataType && pArgInf[2].m_pText)
{
commandline = pArgInf[2].m_pText;
}
if (pArgInf[3].m_dtDataType && pArgInf[3].m_pText)
{
shortkey = pArgInf[3].m_pText;
}
if (pArgInf[4].m_dtDataType && pArgInf[4].m_pText)
{
icon = pArgInf[4].m_pText;
}
if (pArgInf[5].m_dtDataType)
{
shiftdisplay = pArgInf[5].m_bool;
}
pRetData->m_bool = eapiRightMenu::AddRightMenu(RangeOrExtName, title, commandline, shortkey, icon, shiftdisplay);
}
EAPI_EXTERN_C void eapi_DeleteRightMenu_24_eapi(PMDATA_INF pRetData, INT nArgCount, PMDATA_INF pArgInf)
{
std::string RangeOrExtName = "*", title;
BOOL shiftdisplay = FALSE;
if (pArgInf[0].m_dtDataType && pArgInf[0].m_pText && strlen(pArgInf[0].m_pText))
{
RangeOrExtName = pArgInf[0].m_pText;
}
if (pArgInf[1].m_dtDataType && pArgInf[1].m_pText)
{
title = pArgInf[1].m_pText;
}
pRetData->m_bool = eapiRightMenu::DeleteRightMenu(title, RangeOrExtName);
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

易语言支持库 - 应用接口支持库 欢迎易友fork提交代码完成支持库重构改造。
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/JYtechnology/eapi.git
git@gitee.com:JYtechnology/eapi.git
JYtechnology
eapi
eapi
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /