日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

VC++得到系统特殊文件夹路径

發布時間:2025/3/12 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC++得到系统特殊文件夹路径 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

地址:http://blog.csdn.net/morewindows/article/details/8745532轉載請標明出處,謝謝。

歡迎關注微博:http://weibo.com/MoreWindows??????

?

?????? VC++ 得到系統特殊文件夾路徑

?????? Windows程序來說,得到系統特殊文件夾路徑是個非常實用的功能。比如要執行一些系統程序像cmd.exemspaint.exeping.exe時最好加上絕對路徑(通常為C:\WINDOWS\system32),否則有可能會出現找不到指定文件的錯誤。還有要創建桌面快捷方式、啟動菜單快捷方式等等也須要使用系統特殊文件夾路徑。

?????? 在批處理中,要獲取系統特殊文件夾路徑非常簡單。如%SystemDrive%就能得到系統盤符。在VC++中,主要通過SHGetSpecialFolderPath函數來獲取系統特殊文件夾路徑。下面來看看這個函數的介紹:

?

一.SHGetSpecialFolderPath

函數功能:Retrieves the path of a special folder

函數原型:

BOOLSHGetSpecialFolderPath(

?????? HWNDhwndOwner,

?????? LPTSTRlpszPath,

?????? int nFolder,

?????? BOOLfCreate

);

參數說明:

第一個參數hwndOwner

A handle to the owner window that the client should specify if it displays a dialog box or message box.

第二個參數lpszPath

A pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.

第三個參數nFolder

A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.

詳細可見http://msdn.microsoft.com/zh-cn/library/windows/desktop/bb762494(v=vs.85).aspx

第四個參數fCreate

Indicates whether the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.

?

二.代碼示例

給出獲取部分系統特殊文件夾路徑的示例代碼:

[cpp] view plaincopy print?
  • //?VC++得到系統特殊文件夾路徑??
  • //http://blog.csdn.net/morewindows/article/details/8745532??
  • //By?MoreWindows(?http://blog.csdn.net/MoreWindows?)??
  • #include?<windows.h>??
  • #include?<shlobj.h>??
  • #include?<stdio.h>??
  • int?main()??
  • {?????
  • ????printf("????VC++得到系統特殊文件夾路徑??\n");??
  • ????printf("?-?http://blog.csdn.net/morewindows/article/details/8745532?-\n");??
  • ????printf("?--?By?MoreWindows(?http://blog.csdn.net/MoreWindows?)?--\n\n");???
  • ??
  • ????const?int?MAXN?=?9;??
  • ????int?nArrCSIDL[]?=?{??
  • ????????CSIDL_WINDOWS,??
  • ????????CSIDL_SYSTEM,??
  • ????????CSIDL_PROGRAM_FILES,??
  • ????????CSIDL_DESKTOP,??
  • ????????CSIDL_FAVORITES,??
  • ????????CSIDL_FONTS,??
  • ????????CSIDL_COOKIES,??
  • ????????CSIDL_HISTORY,??
  • ????????CSIDL_APPDATA,??
  • ????};??
  • ????char?*pstrCSIDL[]?=?{??
  • ????????"CSIDL_WINDOWS",??
  • ????????"CSIDL_SYSTEM",??
  • ????????"CSIDL_PROGRAM_FILES",??
  • ????????"CSIDL_DESKTOP",??
  • ????????"CSIDL_FAVORITES",??
  • ????????"CSIDL_FONTS",??
  • ????????"CSIDL_COOKIES",??
  • ????????"CSIDL_HISTORY",??
  • ????????"CSIDL_APPDATA",??
  • ????};??
  • ????int?i;??
  • ????for?(i?=?0;?i?<?MAXN;?i++)??
  • ????{??
  • ????????char?szBuffer[MAX_PATH];??
  • ????????SHGetSpecialFolderPath(NULL,?szBuffer,?nArrCSIDL[i],?FALSE);??
  • ????????printf("%s\n\t%s\n",?pstrCSIDL[i],?szBuffer);??
  • ????}??
  • ????getchar();??
  • ????return?0;??
  • }??
  • // VC++得到系統特殊文件夾路徑 //http://blog.csdn.net/morewindows/article/details/8745532 //By MoreWindows( http://blog.csdn.net/MoreWindows ) #include <windows.h> #include <shlobj.h> #include <stdio.h> int main() { printf(" VC++得到系統特殊文件夾路徑 \n");printf(" - http://blog.csdn.net/morewindows/article/details/8745532 -\n");printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n"); const int MAXN = 9;int nArrCSIDL[] = {CSIDL_WINDOWS,CSIDL_SYSTEM,CSIDL_PROGRAM_FILES,CSIDL_DESKTOP,CSIDL_FAVORITES,CSIDL_FONTS,CSIDL_COOKIES,CSIDL_HISTORY,CSIDL_APPDATA,};char *pstrCSIDL[] = {"CSIDL_WINDOWS","CSIDL_SYSTEM","CSIDL_PROGRAM_FILES","CSIDL_DESKTOP","CSIDL_FAVORITES","CSIDL_FONTS","CSIDL_COOKIES","CSIDL_HISTORY","CSIDL_APPDATA",};int i;for (i = 0; i < MAXN; i++){char szBuffer[MAX_PATH];SHGetSpecialFolderPath(NULL, szBuffer, nArrCSIDL[i], FALSE);printf("%s\n\t%s\n", pstrCSIDL[i], szBuffer);}getchar();return 0; }

    ?

    三.運行結果

    運行結果如下圖所示(圖片不能打開?請訪問)

    ?

    ?

    地址:http://blog.csdn.net/morewindows/article/details/8745532轉載請標明出處,謝謝。

    歡迎關注微博:http://weibo.com/MoreWindows??????

    總結

    以上是生活随笔為你收集整理的VC++得到系统特殊文件夹路径的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。