線上訂房服務-台灣趴趴狗聯合訂房中心
網站公告 :


Delphi K.Top討論區 » 難以歸類主題的討論區(C++Builder) » 如何捷取〝桌面〞的完整路徑!?
發表新文章
瀏覽次數:4483
推到 Plurk!
推到 Facebook!

如何捷取〝桌面〞的完整路徑!?

尚未結案
m8815010
版主




發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#1 發表時間:2005-10-15 15:09:01 IP:61.63.xxx.xxx 未訂閱



如主題,請問要如何做!?

例如現在的 currect user 是David,那我希望可以取到
C:\Documents and Settings\David\桌面 這個path,how!?



有找到一隻api可以做到相近的:

int len=256;
char* buf=new char[len];
ZeroMemory(buf,len);
GetEnvironmentVariable("USERPROFILE",buf,len);
ShowMessage(buf);
delete buf;


但這只能取到 C:\Documents and Settings\David 這裏而已!




請教各位大大如何才能找到完整的呢!    




conundrum
尊榮會員




發表:893
回覆:1272
積分:638
註冊:2004-01-06

發送簡訊給我
#2 發表時間:2005-10-15 15:51:39 IP:218.175.xxx.xxx 未訂閱

1 登入使用者
2 regedit


Desktop.htt




        


        



        classid="clsid:72267F6A-A6F9-11D0-BC94-00C04FB67863"
        id=ActiveDesktopMover
    STYLE="position:absolute; container:positioned; LEFT: 0;TOP: 0; WIDTH: 0; HEIGHT: 0;zIndex: 5"
>







        classid="clsid:72267F6A-A6F9-11D0-BC94-00C04FB67863"
        id=ActiveDesktopMoverW
    STYLE="position:absolute; container:positioned; LEFT: 0;TOP: 0; WIDTH: 0; HEIGHT: 0;zIndex 19"
>







 


先說 庵來亂看的

shell32.dll

台灣災難都是事後算帳
無人飛行載具(Unmanned Aerial Vehicle,UAV)為什麼沒大量應用於救災行列

RedSnow
版主




發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#3 發表時間:2005-10-16 00:42:30 IP:61.230.xxx.xxx 未訂閱

m8815010 您好:

我原先找到資料的連結失效 (http://classic.physiol.cam.ac.uk/users/ljw1004/) 了,但是站上有一篇類似的作法,且較為精簡,您參考一下吧:

【分享】ㄧ個讀取桌面資料夾的方法 (請參考 axsoft 版主提供的那一個範例)
http://delphi.ktop.com.tw/topic.php?topic_id=34777


  7 天天敲鍵盤 v 時時按滑鼠 8

conundrum
尊榮會員




發表:893
回覆:1272
積分:638
註冊:2004-01-06

發送簡訊給我
#4 發表時間:2005-10-16 23:37:01 IP:218.175.xxx.xxx 未訂閱

http://www.china-askpro.com/msg10/qa57.shtml

VC++

自動打開“我的電腦”

編號:
QA000957
    
    

建立日期:
1999年5月10日
最後修改日期:
2004年9月4日

所屬類別:
C/C++ - Windows API
    
    




我的問題是在Win95 or Win98 下,能不能編一個程式實現這樣的功能. 該程式先自動打開“我的電腦”, 然後在自動關閉, 然後在類比按鍵Alt+F4出現關機介面, 最後在類比輸入"Alt+y"關閉電腦。 能實現的話,如何實現?採用的語言為vc++ 5.0 。謝謝!(wenwp01)

可以使用SHGetSpecialFolderLocation函數獲得“我的電腦”所對應的虛擬檔夾的id。然後使用ShellExecuteEx打開這個虛擬檔夾。
    使用API函數SHGetSpecialFolderLocation。shlobj.h裏有SHGetSpecialFolderLocation的原型聲明。這個函數可以幫我們找到Windows的桌面目錄、啟動目錄、我的文檔目錄等。
    SHGetSpecialFolder需要三個參數。 第一個參數是HWND,它指定了"所有者視窗":在調用這個函數時可能出現的對話方塊或訊息方塊。第二個參數是一個整數id,決定哪個目錄是待查找目錄,它的取值可能是:

CSIDL_BITBUCKET
回收站

CSIDL_CONTROLS
控制面板

CSIDL_DESKTOP
Windows 桌面Desktop

CSIDL_DESKTOPDIRECTORY
Desktop的目錄

CSIDL_DRIVES
我的電腦

CSIDL_FONTS
字體目錄

CSIDL_NETHOOD
網上鄰居

CSIDL_NETWORK
網上鄰居虛擬目錄

CSIDL_PERSONAL
我的文檔

CSIDL_PRINTERS
印表機

CSIDL_PROGRAMS
程式組

CSIDL_RECENT
最近打開的文檔

CSIDL_SENDTO
“發送到”菜單項

CSIDL_STARTMENU
任務條啟動功能表項

CSIDL_STARTUP
啟動目錄

CSIDL_TEMPLATES
文檔範本




這裏只是最常用的部分。完整的請參考http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp。
    最後一個參數是pidl位址。SHGetSpecialFolderLocation把地址寫到pidl。
    下面是一個例子:
    LPITEMIDLIST pidl;
    TCHAR szPath [MAX_PATH];
    LPMALLOC pMalloc;
    
    if ( SUCCEEDED( SHGetSpecialFolderLocation ( NULL, CSIDL_DRIVES, &pidl )))
    {
    SHELLEXECUTEINFO sei;
    ZeroMemory(&sei, sizeof(sei));
    sei.cbSize = sizeof(sei);
    sei.fMask = SEE_MASK_IDLIST;
    sei.lpIDList = pidl;
    sei.lpVerb = "open";
    sei.hwnd = AfxGetMainWnd()->GetSafeHwnd();
    sei.nShow = SW_SHOWNORMAL;
    ShellExecuteEx(&sei);
    if ( SUCCEEDED( SHGetMalloc ( &pMalloc )))
    {
    pMalloc->Free ( pidl );
    pMalloc->Release();
    }
    }
    
    由於“我的電腦”是虛擬檔夾,所以必須使用ShellExecuteEx函數,如果是普通檔夾,則可以使用SHGetPathFromIDList獲得檔案名,然後利用ShellExecute函數打開。例如要打開“發送到”檔夾,可以這樣:
    if ( SUCCEEDED( SHGetSpecialFolderLocation ( NULL, CSIDL_SENDTO, &pidl )))
    {
    if ( SHGetPathFromIDList ( pidl, szPath ))
    {
    ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),
    "open", szPath, NULL, NULL,
    SW_SHOWNORMAL);
    }
    
    if ( SUCCEEDED( SHGetMalloc ( &pMalloc )))
    {
    pMalloc->Free ( pidl );
    pMalloc->Release();
    }
    }
    
    
    如果是虛擬檔夾,SHGetPathFromIDList函數會失敗。
    對於普通檔夾也可以使用SHGetSpecialFolderPath函數,而不使用SHGetSpecialFolderLocation函數,這樣更簡單些,但運行環境必須是Windows 2000以後的作業系統或安裝了IE 4.0以上版本。
    關閉窗口和關機參考QA000166 "如何利用VB實現作業系統或者某一應用程式的自動關閉"。

    

此問題由李海回答。

附加關鍵字:編程, 根源程式, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, Windows API, win32, api, windows api, gdi32, kernel





http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp

SHGetSpecialFolderLocation
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=79916

CSIDL



--------------------------------------------------------------------------------

CSIDL values provide a unique system-independent way to identify special folders used frequently by applications, but which may not have the same name or location on any given system. For example, the system folder may be "C:\Windows" on one system and "C:\Winnt" on another. These constants are defined in Shlobj.h and Shfolder.h.

Constants

CSIDL_FLAG_CREATE (0x8000)

Version 5.0. Combine this CSIDL with any of the following CSIDLs to force the creation of the associated folder.

CSIDL_ADMINTOOLS (0x0030)

Version 5.0. The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.

CSIDL_ALTSTARTUP (0x001d)

The file system directory that corresponds to the user's nonlocalized Startup program group.

CSIDL_APPDATA (0x001a)

Version 4.71. The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed.

CSIDL_BITBUCKET (0x000a)

The virtual folder containing the objects in the user's Recycle Bin.

CSIDL_CDBURN_AREA (0x003b)

Version 6.0. The file system directory acting as a staging area for files waiting to be written to CD. A typical path is C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning.

CSIDL_COMMON_ADMINTOOLS (0x002f)

Version 5.0. The file system directory containing administrative tools for all users of the computer.

CSIDL_COMMON_ALTSTARTUP (0x001e)

The file system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Microsoft Windows NT systems.

CSIDL_COMMON_APPDATA (0x0023)

Version 5.0. The file system directory containing application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data.

CSIDL_COMMON_DESKTOPDIRECTORY (0x0019)

The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems.

CSIDL_COMMON_DOCUMENTS (0x002e)

The file system directory that contains documents that are common to all users. A typical paths is C:\Documents and Settings\All Users\Documents. Valid for Windows NT systems and Microsoft Windows 95 and Windows 98 systems with Shfolder.dll installed.

CSIDL_COMMON_FAVORITES (0x001f)

The file system directory that serves as a common repository for favorite items common to all users. Valid only for Windows NT systems.

CSIDL_COMMON_MUSIC (0x0035)

Version 6.0. The file system directory that serves as a repository for music files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Music.

CSIDL_COMMON_PICTURES (0x0036)

Version 6.0. The file system directory that serves as a repository for image files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Pictures.

CSIDL_COMMON_PROGRAMS (0x0017)

The file system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT systems.

CSIDL_COMMON_STARTMENU (0x0016)

The file system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems.

CSIDL_COMMON_STARTUP (0x0018)

The file system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT systems.

CSIDL_COMMON_TEMPLATES (0x002d)

The file system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT systems.

CSIDL_COMMON_VIDEO (0x0037)

Version 6.0. The file system directory that serves as a repository for video files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Videos.

CSIDL_CONTROLS (0x0003)

The virtual folder containing icons for the Control Panel applications.

CSIDL_COOKIES (0x0021)

The file system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies.

CSIDL_DESKTOP (0x0000)

The virtual folder representing the Windows desktop, the root of the namespace.

CSIDL_DESKTOPDIRECTORY (0x0010)

The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop.

CSIDL_DRIVES (0x0011)

The virtual folder representing My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.

CSIDL_FAVORITES (0x0006)

The file system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites.

CSIDL_FONTS (0x0014)

A virtual folder containing fonts. A typical path is C:\Windows\Fonts.

CSIDL_HISTORY (0x0022)

The file system directory that serves as a common repository for Internet history items.

CSIDL_INTERNET (0x0001)

A virtual folder representing the Internet.

CSIDL_INTERNET_CACHE (0x0020)

Version 4.72. The file system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Local Settings\Temporary Internet Files.

CSIDL_LOCAL_APPDATA (0x001c)

Version 5.0. The file system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data.

CSIDL_MYDOCUMENTS (0x000c)

Version 6.0. The virtual folder representing the My Documents desktop item.

CSIDL_MYMUSIC (0x000d)

The file system directory that serves as a common repository for music files. A typical path is C:\Documents and Settings\User\My Documents\My Music.

CSIDL_MYPICTURES (0x0027)

Version 5.0. The file system directory that serves as a common repository for image files. A typical path is C:\Documents and Settings\username\My Documents\My Pictures.

CSIDL_MYVIDEO (0x000e)

Version 6.0. The file system directory that serves as a common repository for video files. A typical path is C:\Documents and Settings\username\My Documents\My Videos.

CSIDL_NETHOOD (0x0013)

A file system directory containing the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood.

CSIDL_NETWORK (0x0012)

A virtual folder representing Network Neighborhood, the root of the network namespace hierarchy.

CSIDL_PERSONAL (0x0005)

Version 6.0. The virtual folder representing the My Documents desktop item. This is equivalent to CSIDL_MYDOCUMENTS.

Previous to Version 6.0. The file system directory used to physically store a user's common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System.

CSIDL_PRINTERS (0x0004)

The virtual folder containing installed printers.

CSIDL_PRINTHOOD (0x001b)

The file system directory that contains the link objects that can exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood.

CSIDL_PROFILE (0x0028)

Version 5.0. The user's profile folder. A typical path is C:\Documents and Settings\username. Applications should not create files or folders at this level; they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.

CSIDL_PROFILES (0x003e)

Version 6.0. The file system directory containing user profile folders. A typical path is C:\Documents and Settings.

CSIDL_PROGRAM_FILES (0x0026)

Version 5.0. The Program Files folder. A typical path is C:\Program Files.

CSIDL_PROGRAM_FILES_COMMON (0x002b)

Version 5.0. A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT, Windows 2000, and Windows XP systems. Not valid for Windows Millennium Edition (Windows Me).

CSIDL_PROGRAMS (0x0002)

The file system directory that contains the user's program groups (which are themselves file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs.

CSIDL_RECENT (0x0008)

The file system directory that contains shortcuts to the user's most recently used documents. A typical path is C:\Documents and Settings\username\My Recent Documents. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the My Recent Documents submenu of the Start menu.

CSIDL_SENDTO (0x0009)

The file system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo.

CSIDL_STARTMENU (0x000b)

The file system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu.

CSIDL_STARTUP (0x0007)

The file system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT or starts Windows 95. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup.

CSIDL_SYSTEM (0x0025)

Version 5.0. The Windows System folder. A typical path is C:\Windows\System32.

CSIDL_TEMPLATES (0x0015)

The file system directory that serves as a common repository for document templates. A typical path is C:\Documents and Settings\username\Templates.

CSIDL_WINDOWS (0x0024)

Version 5.0. The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows.

Remarks

These values supersede the use of environment variables for this purpose.

A CSIDL is used in conjunction with one of four Shell functions, SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation, and SHGetSpecialFolderPath, to retrieve a special folder's path or pointer to an item identifier list (PIDL).

Combine CSIDL_FLAG_CREATE with any of the other CSIDLs to force the creation of the associated folder. The remaining CSIDLs correspond to either file system folders or virtual folders. Where the CSIDL identifies a file system folder, a commonly used path is given as an example. Other paths may be used. Some CSIDLs can be mapped to an equivalent %VariableName% environment variable. CSIDLs are more reliable, however, and should be used if possible.

See Also




台灣災難都是事後算帳
無人飛行載具(Unmanned Aerial Vehicle,UAV)為什麼沒大量應用於救災行列

發表人 - conundrum 於 2005/10/16 23:42:34

m8815010
版主




發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#5 發表時間:2005-10-18 17:19:53 IP:61.63.xxx.xxx 未訂閱


感謝conundrum大、和RedSnow大的回覆~

conundrum大的第一篇我有點看不懂要做什麼!
RedSnow大的回應已達可解的地步,conundrum大的再回應也正確並更加詳盡~,感謝conundrum大先!

但由於變成RedSnow大先解題的,分數只好給RedSnow大了!

再次感謝兩位!




系統時間:2014-10-20 19:19:03,  線上使用者 204 / Max 457,主題數:97,452,回覆數:219,685。  聯絡我們 | Delphi.KTop討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!
5151線上健康照護網 | 台灣西醫網 | 台灣中醫網 | 台灣牙科網 | 台灣照護網 | 趴趴狗旅遊網
大花蓮旅遊網 | 大花蓮民宿網 | 花蓮旅遊網 | 花蓮旅遊 | 花蓮旅遊 | 花蓮住宿
花蓮民宿網 | 花蓮旅遊 | 花蓮住宿 | 花蓮民宿 | 花蓮旅遊 | 花蓮民宿
花蓮住宿 | 大南投旅遊網 | 大南投民宿網 | 日月潭風景區 | 日月潭旅遊網 | 日月潭民宿網
日月潭住宿網 | 宜蘭旅遊網 | 宜蘭民宿網 | 宜蘭住宿網 | 宜蘭旅遊網 | 宜蘭民宿網
宜蘭住宿網 | 宜蘭旅遊網 | 宜蘭民宿網 | 宜蘭住宿網 | 台東旅遊網 | 台東民宿網
台東住宿網 | 台東旅遊網 | 台東民宿網 | 台東住宿網 | 台東旅遊 | 台東民宿
台東住宿 | 綠島旅遊網 | 綠島民宿網 | 綠島住宿網 | 綠島旅遊網 | 綠島民宿網
綠島住宿網 | 綠島旅遊網 | 綠島民宿網 | 綠島住宿網 | 集集旅遊網 | 集集民宿網
集集住宿網 | 關子嶺旅遊網 | 關子嶺民宿網 | 白河旅遊網 | 白河民宿網 | 心脈大師
尊榮牙醫診所 |