C++利用注册表添加桌面右键新建菜单
对于程序员来说,新建一个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++利用注册表添加桌面右键新建菜单的更多相关文章
- Win10系统桌面右键新建没有内容怎么恢复
Win10系统桌面右键新建没有内容怎么恢复 添加txt文本文档 运行->regedit,打开注册表编辑器 展开HKEY_CLASSES_ROOT 找到.txt 选中.txt,修改右侧窗格的“默认 ...
- win8.1右键新建菜单添加新建php文件
最近在学习php没使用IDE,一直使用编辑器,但每次新建文件都要手动该扩展名比较麻烦.于是想着能不能在右键新建菜单直接新建php文件.于是开始百度... 步骤一:win+R打开运行(管理员身份运行) ...
- 【转载】Win10系统桌面右键新建没有Word、Excel、PPT怎么恢复?
Win10系统桌面右键新建没有Word.Excel.PPT怎么恢复? 以下正文转载至: 网址:http://www.xitongzhijia.net/xtjc/20170307/93471.html ...
- 添加找回鼠标右键新建菜单里的新建office2003/2007/2010文档的简洁方法
鼠标右键新建菜单里的新建office文档丢失了怎么办?我们可以通过一些优化设置软件如优化大师来定制,但更简单的方法是只需要导入相应的注册表设置就行了. 下面即在鼠标右键新建菜单里添加新建office2 ...
- Win10 自定义右键新建菜单
Win10 自定义右键新建菜单 regedit打开: 计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ ...
- 利用注册表在右键添加VS15的快捷方式打开文件夹
1.简介 最近安装VS15 Preview 5,本版本可以打开"文件夹" 是否可以向Visual Studio Code一样在文件夹或文件右键菜单添加"Open with ...
- 利用注册表在右键添加VisualCode快捷方式
分为两种配置,第一种是对于文件右键也就是 关联文件 第一步: Win+R 打开运行,输入regedit,打开注册表,找到HKEY_CLASSES_ROOT\*\shell分支,如果没有shell分支, ...
- 修改注册表添加IE信任站点及启用Activex控件
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/In ...
- win10无法新建文件夹怎么办 win10右键新建菜单设置方法
有朋友安装了win10系统后发现右键菜单中没有新建项,而平时使用新建 - 文件夹项的机率很高.如何才能恢复桌面右键菜单中的新建项呢? 右键点击桌面空白处,在右键菜单中发现没有新建项: 桌面右键菜单没有 ...
随机推荐
- c语言中的二分法
\\\题外:对于printf引号中的内容一定要细心书写 ; 数组由a[0]开始计数,切记:尤其是与for循环中i=1 搞混 运用a[i+1]等超前数据时 需先用 for(i=0;i<=n-1;i ...
- systick优先级的理解
sysTick系统嘀嗒定时器并非STM32独有的,它是Cortex内核的部分,CM3为它专门开出一个异常类型,并且在中断向量表中占有一席之地(异常号15).这样它可以很方便的移植到不同厂商出CM3内核 ...
- Laravel中URL,ACTION,ROUTE区别
创建路由如下所示: Route::get('articles',['uses'=>'ArticlesController@index','as'=>'articles.index']); ...
- Java中的注解是如何工作的?--annotation学习一
自Java5.0版本引入注解之后,它就成为了Java平台中非常重要的一部分.开发过程中,我们也时常在应用代码中会看到诸如@Override,@Deprecated这样的注解.这篇文章中,我将向大家讲述 ...
- MySQL 绿色版安装方法图文教程
一.下载,这里使用绿色解压缩版 http://mirror.services.wisc.edu/mysql/Downloads/MySQL-5.1/mysql-noinstall-5.1.32-win ...
- MongoDB基本命令的使用
成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显示 ...
- java多线程之ThreadLocal
ThreadLocal为每个线程保存变量,以保证数据同步. package Thread.Common; import java.util.Random; import java.util.concu ...
- Sql Server Text 类型列 查询和更新
Text(ntext.image)类型为大数据字段,因为存储方式不同,也决定了其查询和更新不同于一般方法. 1.表定义: 2.查询: Like查询是可用的: select * from dbo.nod ...
- 第七届蓝桥杯C++B组省赛
1.煤球数目 2.生日蜡烛 3.凑算式 4.快速排序 5.抽签 6.方格填数 7.剪邮票 8.四平方和 9.交换瓶子 10.最大比例 今天是周三了,周天刚考完,这次做的还是不好(上次是全省最后一名). ...
- java网格布局管理器
public class GirdLayoutPosition extends JFrame{ public GirdLayoutPosition() { Container ...