对于程序员来说,新建一个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. 如何刪除GitHub中的repository

    如何刪除一github中的repository,這本該是個非常簡單的操作,可一開始搜的時候,有不少文章比較含糊.這裡就記錄下來吧. 1.訪問https://github.com/settings/pr ...

  2. error-iis-Service Unavailable

    Service Unavailable Service Unavailable HTTP Error 503. The service is unavailable.

  3. c#生成缩略图

    publicstaticvoidGenThumbnail(Image imageFrom,stringpathImageTo,intwidth,intheight)         {         ...

  4. [Swift]枚举

    1. Swift的枚举的基本用法: 1) 和其它语言枚举的意义相同,就是用有限的一组值(不能是无限的)来表示一些特定的含义: 2) Swift使用关键字enum定义枚举类型,定义体中用case定义成员 ...

  5. redis在.net架构中的应用(1)--使用servicestack连接redis(转)

    引言:作为少有的.net架构下的大型网站,stackoverflow曾发表了一篇文章,介绍了其技术体系,原文链接http://highscalability.com/blog/2011/3/3/sta ...

  6. 常用开源Jabber(XMPP) IM服务器介绍(转)

      1. Openfire (Wildfire) 3.x授权: GPL or 商用操作系统平台:所有(使用Java开发)XMPP Jabber 协议实现情况:98%Tim 评价:安装和使用非常简单,安 ...

  7. mysql 怎么登录

    mysql -uroot -p回车后,输入密码,再回车即可.如果自己没有修改的话,默认密码为空.

  8. hdu 4712 Hamming Distance(随机数法)

    d.汉明距离是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量, 我们以d(x,y)表示两个字x,y之间的汉明距离.对两个字符串进行异或运算,并统计结果为 ...

  9. Mingyang.net:hibernate.hbm2ddl.auto配置详解【转】

    原文地址:http://www.cnblogs.com/feilong3540717/archive/2011/12/19/2293038.html hibernate.cfg.xml 中hibern ...

  10. (easy)LeetCode 258.Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...