C++利用注册表添加桌面右键新建菜单

发表于:2016-1-07 10:24

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:jerrylsxu    来源:51Testing软件测试网采编

  对于程序员来说,新建一个cpp文件是再频繁不过的事情了。
  为了方便,我们习惯在桌面右键新建文件,而不是新建一个文本文档,然后修改后缀名。
  百度谷歌查询了一下,终于知道如何添加注册表。
  手痒,抽出时间用cpp写了一个程序,方便以后操作。
  客户需求是永远无法满足的,经同学测试,陆续写了三个版本。
  接下来直接贴代码~
  第一个版本,只能添加c、cpp、java三种后缀。
1 /*
2  * Author: Haipz
3  * School: HDU
4  * File Name: registry1.0.cpp
5  */
6 #include <cstdio>
7 #include <cmath>
8 #include <ctime>
9 #include <cctype>
10 #include <cstring>
11 #include <cstdlib>
12 #include <climits>
13 #include <cfloat>
14 #include <iostream>
15 #include <vector>
16 #include <stack>
17 #include <queue>
18 #include <set>
19 #include <map>
20 #include <algorithm>
21 using namespace std;
22
23 char s[1024], buffer[128], result[1024*4];
24
25 void work_1() {
26     system("reg add \"HKEY_CLASSES_ROOT\\.c\\ShellNew\" /v \"NullFile\" /t REG_SZ");
27 }
28
29 void work_2() {
30     system("reg add \"HKEY_CLASSES_ROOT\\.cpp\\ShellNew\" /v \"NullFile\" /t REG_SZ");
31 }
32
33 void work_3() {
34     system("reg add \"HKEY_CLASSES_ROOT\\.java\\ShellNew\" /v \"NullFile\" /t REG_SZ");
35 }
36
37 int main() {
38     printf("Add registry for C, C++ and Java\n");
39     printf("Author: Haipz\nSchool: HDU\n");
40     printf("1 for C;\n2 for C++;\n3 for Java.\n");
41     printf("Example: 12 to add C and C++.\n");
42     printf("Please make choice(s): ");
43     gets(s);
44     for (int i = 0; s[i] != '\0'; ++i) {
45         printf("Working...\n");
46         if (s[i] == '1') work_1();
47         else if (s[i] == '2') work_2();
48         else if (s[i] == '3') work_3();
49         else printf("%c is a wrong enter!\n", s[i]);
50     }
51     system("pause");
52     return 0;
53 }
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号