C++實(shí)現(xiàn)添加桌面右鍵新建菜單
對(duì)于程序員來說,新建一個(gè)cpp文件是再頻繁不過的事情了。
為了方便,我們習(xí)慣在桌面右鍵新建文件,而不是新建一個(gè)文本文檔,然后修改后綴名。
百度谷歌查詢了一下,終于知道如何添加注冊(cè)表。
手癢,抽出時(shí)間用cpp寫了一個(gè)程序,方便以后操作。
客戶需求是永遠(yuǎn)無法滿足的,經(jīng)同學(xué)測(cè)試,陸續(xù)寫了三個(gè)版本。
接下來直接貼代碼~
第一個(gè)版本,只能添加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; }
第二個(gè)版本,精簡(jiǎn)了代碼,支持添加用戶輸入的后綴。
/* * 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; }
第三個(gè)版本,支持多次添加,并允許刪除已添加的注冊(cè)表。
/* * 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; }
打包下載地址:
http://xiazai.jb51.net/201601/yuanma/Regedity(jb51.net).zip
注意,如果系統(tǒng)提示缺少某dll文件,請(qǐng)到網(wǎng)上下載,并復(fù)制到C:\Windows\System32目錄下。
上一篇:詳解C++語言中的加法運(yùn)算符與賦值運(yùn)算符的用法
欄 目:C語言
下一篇:使用C++進(jìn)行Cocos2d-x游戲開發(fā)入門過程中的要點(diǎn)解析
本文標(biāo)題:C++實(shí)現(xiàn)添加桌面右鍵新建菜單
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2580.html
您可能感興趣的文章
- 04-02c語言沒有round函數(shù) round c語言
- 01-10數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)-用棧實(shí)現(xiàn)表達(dá)式求值的方法詳解
- 01-10使用OpenGL實(shí)現(xiàn)3D立體顯示的程序代碼
- 01-10深入理解C++中常見的關(guān)鍵字含義
- 01-10求斐波那契(Fibonacci)數(shù)列通項(xiàng)的七種實(shí)現(xiàn)方法
- 01-10C語言 解決不用+、-、&#215;、&#247;數(shù)字運(yùn)算符做加法
- 01-10使用C++實(shí)現(xiàn)全排列算法的方法詳解
- 01-10c++中inline的用法分析
- 01-10用C++實(shí)現(xiàn)DBSCAN聚類算法
- 01-10深入全排列算法及其實(shí)現(xiàn)方法


閱讀排行
- 1C語言 while語句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
- 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對(duì)數(shù)函數(shù)的表達(dá)式 c語言中對(duì)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機(jī)閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 04-02jquery與jsp,用jquery
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11ajax實(shí)現(xiàn)頁面的局部加載