对于程序员来说,新建一个cpp文件是再频繁不过的事情了。

为了方便,我们习惯在桌面右键新建文件,而不是新建一个文本文档,然后修改后缀名。

百度谷歌查询了一下,终于知道如何添加注册表。

手痒,抽出时间用cpp写了一个程序,方便以后操作。

客户需求是永远无法满足的,经同学测试,陆续写了三个版本。

接下来直接贴代码~

第一个版本,只能添加c、cpp、java三种后缀。

 /*
* Author: Haipz
* School: HDU
* File Name: registry1.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char s[], buffer[], result[*]; void work_1() {
system("reg add \"HKEY_CLASSES_ROOT\\.c\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} void work_2() {
system("reg add \"HKEY_CLASSES_ROOT\\.cpp\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} void work_3() {
system("reg add \"HKEY_CLASSES_ROOT\\.java\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} int main() {
printf("Add registry for C, C++ and Java\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("1 for C;\n2 for C++;\n3 for Java.\n");
printf("Example: 12 to add C and C++.\n");
printf("Please make choice(s): ");
gets(s);
for (int i = ; s[i] != '\0'; ++i) {
printf("Working...\n");
if (s[i] == '') work_1();
else if (s[i] == '') work_2();
else if (s[i] == '') work_3();
else printf("%c is a wrong enter!\n", s[i]);
}
system("pause");
return ;
}

第二个版本,精简了代码,支持添加用户输入的后缀。

 /*
* Author: Haipz
* School: HDU
* File Name: registry2.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char a[];
char b[] = "reg add \"HKEY_CLASSES_ROOT\\.";
char c[] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ"; void work(char* a) {
strcat(b, a);
strcat(b, c);
system(b);
} int main() {
printf("Function: Add registry to build a new file simply!\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("Example: Enter c to add C and enter cpp to add C++.\n");
printf("Your opion: ");
gets(a);
work(a);
system("pause");
return ;
}

第三个版本,支持多次添加,并允许删除已添加的注册表。

 /*
* Author: Haipz
* School: HDU
* File Name: registry2.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char key[];
char a[]; void add(char* t) {
char b[] = "reg add \"HKEY_CLASSES_ROOT\\.";
char c[] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ";
strcat(b, t);
strcat(b, c);
system(b);
} void del(char* t) {
char d[] = "reg delete \"HKEY_CLASSES_ROOT\\.";
char e[] = "\\ShellNew\" /f";
strcat(d, t);
strcat(d, e);
system(d);
} int main() {
printf("Function: Build a new file simply!\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("Example: Enter \"c\" to add C and enter \"cpp\" to add C++;\n");
printf(" Enter \"-c\" to delete C.\n");
do {
printf("Your opion: ");
gets(a);
if (a[] == '-') del(a + );
else add(a);
printf("Enter \"r\" to run again or any other key to quit: ");
gets(key);
} while (key[] == 'r');
return ;
}

打包下载地址:

http://files.cnblogs.com/haipzm/Regedity.zip

注意,如果系统提示缺少某dll文件,请到网上下载,并复制到C:\Windows\System32目录下。

C++利用注册表添加桌面右键新建菜单的更多相关文章

  1. Win10系统桌面右键新建没有内容怎么恢复

    Win10系统桌面右键新建没有内容怎么恢复 添加txt文本文档 运行->regedit,打开注册表编辑器 展开HKEY_CLASSES_ROOT 找到.txt 选中.txt,修改右侧窗格的“默认 ...

  2. win8.1右键新建菜单添加新建php文件

    最近在学习php没使用IDE,一直使用编辑器,但每次新建文件都要手动该扩展名比较麻烦.于是想着能不能在右键新建菜单直接新建php文件.于是开始百度... 步骤一:win+R打开运行(管理员身份运行) ...

  3. 【转载】Win10系统桌面右键新建没有Word、Excel、PPT怎么恢复?

    Win10系统桌面右键新建没有Word.Excel.PPT怎么恢复? 以下正文转载至: 网址:http://www.xitongzhijia.net/xtjc/20170307/93471.html ...

  4. 添加找回鼠标右键新建菜单里的新建office2003/2007/2010文档的简洁方法

    鼠标右键新建菜单里的新建office文档丢失了怎么办?我们可以通过一些优化设置软件如优化大师来定制,但更简单的方法是只需要导入相应的注册表设置就行了. 下面即在鼠标右键新建菜单里添加新建office2 ...

  5. Win10 自定义右键新建菜单

    Win10 自定义右键新建菜单 regedit打开: 计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ ...

  6. 利用注册表在右键添加VS15的快捷方式打开文件夹

    1.简介 最近安装VS15 Preview 5,本版本可以打开"文件夹" 是否可以向Visual Studio Code一样在文件夹或文件右键菜单添加"Open with ...

  7. 利用注册表在右键添加VisualCode快捷方式

    分为两种配置,第一种是对于文件右键也就是 关联文件 第一步: Win+R 打开运行,输入regedit,打开注册表,找到HKEY_CLASSES_ROOT\*\shell分支,如果没有shell分支, ...

  8. 修改注册表添加IE信任站点及启用Activex控件

    Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/In ...

  9. win10无法新建文件夹怎么办 win10右键新建菜单设置方法

    有朋友安装了win10系统后发现右键菜单中没有新建项,而平时使用新建 - 文件夹项的机率很高.如何才能恢复桌面右键菜单中的新建项呢? 右键点击桌面空白处,在右键菜单中发现没有新建项: 桌面右键菜单没有 ...

随机推荐

  1. Mac下配置JAVA_HOME

    http://blog.csdn.net/shallowgrave/article/details/39367119 闲来无事,装个Hbase玩玩,突然发现Mac下默认安装的JDK7,没有配置JAVA ...

  2. 客户端获取服务端自定义类数据 z

    客户端获取服务端自定义类数据 问题一:超时问题,在最后获取数据的时候突然提示服务超时,服务已断开 解决:配置文件添加: <bindings> <wsHttpBinding> & ...

  3. 开发工具及服务年度大奖评选 I Bugtags 荣获最具成长潜力奖

    作为全球最大中文 IT 社区和服务平台.中国最大技术管理者平台的 CSDN 在中国北京总部举办了一场 2015 年开发工具及服务年度大奖评选活动,此次活动目的在于推动开发服务及工具质量的提升,提高行业 ...

  4. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  5. git remove cache

    若在提交.gitignore之前,不小心提交了无用的文件入repo,可以用以下命令在repo中去除这些文件 git rm -r --cached <filename or .> git a ...

  6. fw:sed的高级用法

    转的,找不到原创了.... sed高级用法 <收藏> 首先,应该明白模式空间的定义.模式空间就是读入行所在的缓存,sed对文本行进行的处理都是在这个缓存中进行的.这对接下来 的学习是有帮助 ...

  7. Eclipse is running in a JRE, but a JDK is required 解决方法

    本文非原创,转自http://liguoliang.com/2010/eclipse-is-running-in-a-jre-but-a-jdk-is-required/ 安装Maven后每次启动出现 ...

  8. Social networks and health: Communicable but not infectious

    Harvard Men’s Health Watch Poet and pastor John Donne famously proclaimed “No man is an island.” It ...

  9. 【LeetCode】14. Longest Common Prefix 最长前缀子串

    题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子 ...

  10. 慕课网-安卓工程师初养成-2-2 认识Java标识符

    来源:http://www.imooc.com/code/1177 问:标识符是神马? 答:标识符就是用于给 Java 程序中变量.类.方法等命名的符号. 使用标识符时,需要遵守几条规则: 1.  标 ...