国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++實現添加桌面右鍵新建菜單

2020-05-23 14:11:15
字體:
來源:轉載
供稿:網友
本文給大家匯總了3個版本的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[1024], buffer[128], result[1024*4];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 = 0; s[i] != '/0'; ++i) {    printf("Working.../n");    if (s[i] == '1') work_1();    else if (s[i] == '2') work_2();    else if (s[i] == '3') work_3();    else printf("%c is a wrong enter!/n", s[i]);  }  system("pause");  return 0;}

第二個版本,精簡了代碼,支持添加用戶輸入的后綴。

 /* * 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[1024]; char b[1024] = "reg add /"HKEY_CLASSES_ROOT//."; char c[1024] = "//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 0; }

第三個版本,支持多次添加,并允許刪除已添加的注冊表。

/* * 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[1024];char a[1024];void add(char* t) {  char b[1024] = "reg add /"HKEY_CLASSES_ROOT//.";  char c[1024] = "//ShellNew/" /v /"NullFile/" /t REG_SZ";  strcat(b, t);  strcat(b, c);  system(b);}void del(char* t) {  char d[1024] = "reg delete /"HKEY_CLASSES_ROOT//.";  char e[1024] = "//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[0] == '-') del(a + 1);    else add(a);    printf("Enter /"r/" to run again or any other key to quit: ");    gets(key);  } while (key[0] == 'r');  return 0;}


 

注意,如果系統提示缺少某dll文件,請到網上下載,并復制到C:/Windows/System32目錄下。



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 托里县| 全南县| 卢龙县| 平顶山市| 嵊州市| 外汇| 昌吉市| 西宁市| 平塘县| 资中县| 安远县| 安西县| 达尔| 石嘴山市| 宣汉县| 峨眉山市| 化隆| 客服| 银川市| 嘉鱼县| 庆元县| 天等县| 岱山县| 丹东市| 尼勒克县| 始兴县| 页游| 闸北区| 玉林市| 静海县| 安溪县| 绥阳县| 探索| 荆门市| 梓潼县| 五指山市| 阳新县| 阿拉善左旗| 肥城市| 林芝县| 沈阳市|