如何获得桌面窗口的完整路径?

解决方案 »

  1.   

    BOOL SHGetSpecialFolderPath( HWND hwndOwner,
        LPTSTR lpszPath,
        int nFolder,
        BOOL fCreate
    );nFolder用CSIDL_DESKTOPDIRECTORY
      

  2.   

    /******************************************************/
    /*      得到当前工作路径                              */              
    /******************************************************/
    void GetWorkPath( char szPath[], int nSize )
    {
    GetModuleFileName( NULL, szPath, nSize );
    char* p = strrchr( szPath, '\\' ); *p = 0;
    }
      

  3.   

    获得各种系统目录只是能够创建快捷方式是不够的,我们还要将快捷方式创建到我们指定的位置当中,例如开始菜单、桌面以及IE快速启动栏,甚至启动程序组中。    为了获得这些特殊目录,我们必须使用SHGetSpecialFolderLocation函数,该函数需要三个参数:HWND hwndOwner, 母窗口的句柄;int nFolder, 指定的特殊目录;LPITEMIDLIST *ppidl    
    以下是代码示例:    LPITEMIDLIST ppidl;    //定义IDLIST指针
        charlinkpath[255];   //定义字符串,保存目录名
            获得桌面路径:    SHGetSpecialFolderLocation(NULL,0 ,&ppidl); 
        SHGetPathFromIDList(ppidl,linkpath);
            获得程序组路径    SHGetSpecialFolderLocation(NULL,CSIDL_PROGRAMS ,&ppidl); 
        SHGetPathFromIDList(ppidl,linkpath);
            获得启动程序项路径    SHGetSpecialFolderLocation(NULL,CSIDL_STARTUP  ,&ppidl); 
        SHGetPathFromIDList(ppidl,linkpath);
            获得IE快速启动栏路径    SHGetSpecialFolderLocation(NULL,CSIDL_APPDATA   ,&ppidl); 
        SHGetPathFromIDList(ppidl,linkpath);
        strcat(linkpath,"\Microsoft\Internet Explorer\Quick Launch");
    如果我们改变SHGetSpecialFolderLocation函数中的nFolder参数,就可以获得不同的特殊目录,更多的信息请查看MSDN帮助。
      

  4.   

    SHGetSpecialFolderPathRequirements
    Runs on Versions Defined in Include Link to 
    Windows CE OS 2.12 and later Shellapi.h     This function retrieves the path of a special folder, identified by its CSIDL. BOOL SHGetSpecialFolderPath(
    HWND hwndOwner,
    LPTSTR lpszPath,
    int nFolder,
    BOOL fCreate 
    );具体参数请查看msdn
      

  5.   

    BOOL SHGetSpecialFolderPath(
    HWND hwndOwner,
    LPTSTR lpszPath,
    int nFolder,
    BOOL fCreate 
    );