⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shfolder.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 僔僃儖偵曄峏傪捠抦偡傞
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int WINAPI ShChangeNotify ( const ITEMIDLIST *pItemIdList ) {

   SFGAOF SfGaof = SFGAO_FOLDER ;

   if ( ! SUCCEEDED ( ShGetAttributesInternal ( pItemIdList, & SfGaof ) ) ) return 1 ;

   int nCommand = ( SfGaof & SFGAO_FOLDER ) ? SHCNE_UPDATEDIR : SHCNE_UPDATEITEM ;

   SHChangeNotify ( nCommand, SHCNF_IDLIST, pItemIdList, NULL ) ;

   return 0 ;
}



/////////////////////////////////
//          撪晹娭悢           //
/////////////////////////////////



// SHBindToParent 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
static HRESULT ShBindToParent ( const ITEMIDLIST *pItemIdList, REFIID RefIid, void **ppObject, const ITEMIDLIST ua **pItemIdListLast ) {

   if ( ! ppObject ) return E_POINTER ;
   if ( ! pItemIdList ) return E_INVALIDARG ;

   *ppObject = NULL ;
   if ( pItemIdListLast ) *pItemIdListLast = NULL ;

   IShellFolder *pIShellFolder ;
   HRESULT hResult = SHGetDesktopFolder ( & pIShellFolder ) ;
   if ( SUCCEEDED ( hResult ) ) {

      const ITEMIDLIST ua *pLast = ShILFindLastID ( pItemIdList ) ;

      if ( pLast == pItemIdList ) hResult = pIShellFolder->QueryInterface ( RefIid, ppObject ) ;
      else {
         size_t nLength = (const char*) pLast - (const char*) pItemIdList ;
         ITEMIDLIST *pParent = (ITEMIDLIST*) malloc ( nLength + sizeof(pItemIdList->mkid.cb) ) ;
         if ( ! pParent ) hResult = E_OUTOFMEMORY ;
         else {
            memmove ( pParent, pItemIdList, nLength ) ;
            ((ITEMIDLIST*)( (char*) pParent + nLength ))->mkid.cb = 0 ;
            hResult = pIShellFolder->BindToObject ( pParent, 0, RefIid, ppObject ) ;
            free ( pParent ) ;
         }
      }

      pIShellFolder->Release () ;

      if ( pItemIdListLast ) *pItemIdListLast = pLast ;
   }

   return hResult ;
}



// ILCombine 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// 俀偮偺 ITEMIDLIST 傪楢寢偟丄怴偟偄 ITEMIDLIST 傪嶌惉
// 偳偪傜偐偑 NULL 側傜偽丄ITEMIDLIST 偺暋惢傪嶌傞
static ITEMIDLIST *ShILCombine ( const ITEMIDLIST *pBase, const ITEMIDLIST *pAdd ) {

   if ( ! pBase && ! pAdd ) return NULL ;

   size_t nBaseSize = ( pBase ) ? ( ShILGetSize ( pBase ) - sizeof(pBase->mkid.cb) ) : 0 ;
   size_t nAddSize = ( pAdd ) ? ( ShILGetSize ( pAdd ) - sizeof(pAdd->mkid.cb) ) : 0 ;

   ITEMIDLIST *pNew = (ITEMIDLIST*) ShAlloc ( nBaseSize + nAddSize + sizeof(pBase->mkid.cb) ) ;
   if ( ! pNew ) return NULL ;

   if ( pBase ) memmove ( pNew, pBase, nBaseSize ) ;
   if ( pAdd ) memmove ( (char*) pNew + nBaseSize, pAdd, nAddSize ) ;
   ((ITEMIDLIST*)( (char*) pNew + nBaseSize + nAddSize ))->mkid.cb = 0 ;

   return pNew ;
}



// ILFindLastID 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// ITEMIDLIST 偐傜枛旜偺 ITEMID 傪庢摼偡傞
static const ITEMIDLIST ua *ShILFindLastID ( const ITEMIDLIST *pItemIdList ) {

   if ( ! pItemIdList ) return NULL ;

   const ITEMIDLIST ua *pCurrent = pItemIdList ;

   while ( 1 ) {
      const ITEMIDLIST ua *pNext = (const ITEMIDLIST*) ( (const char*) pCurrent + pCurrent->mkid.cb ) ;
      if ( ! pNext->mkid.cb ) break ;
      pCurrent = pNext ;
   }

   return pCurrent ;
}



// ILGetSize 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// ITEMIDLIST 偺僒僀僘傪曉偡
static size_t ShILGetSize ( const ITEMIDLIST *pItemIdList ) {

   if ( ! pItemIdList ) return 0 ;

   const ITEMIDLIST ua *pLast = ShILFindLastID ( pItemIdList ) ;

   return (const char*) pLast - (const char*) pItemIdList + pLast->mkid.cb + sizeof(pItemIdList->mkid.cb) ;
}



// ITEMIDLIST 偐傜懏惈傪庢摼偡傞
// 帠慜偵昁梫側忣曬傪 SFGAOF 偵儅僗僋偟偰偍偔
static HRESULT ShGetAttributesInternal ( const ITEMIDLIST *pItemIdList, SFGAOF *pSfGaof ) {

   HRESULT hResult = E_FAIL ;

   IShellFolder *pIShellFolder ;
   if ( SUCCEEDED ( ShBindToParent ( pItemIdList, IID_IShellFolder, (void**) & pIShellFolder, & pItemIdList ) ) ) {
      hResult = pIShellFolder->GetAttributesOf ( 1, (LPCITEMIDLIST*) & pItemIdList, pSfGaof ) ;
      pIShellFolder->Release () ;
   }

   return hResult ;
}



#ifndef NTFUNC_IMPORT_IMPLICITLY
static void __cdecl ExitProc ( void ) {
   if ( hShell32 ) FreeLibrary ( hShell32 ) ;
   hShell32 = NULL ;
}
#endif



#ifndef NTFUNC_IMPORT_IMPLICITLY
static int FreeLibraryOnDetach ( void ) {
#ifdef _USRDLL
   return atexit ( ExitProc ) ;
#else
   return 0 ;
#endif
}
#endif



/////////////////////////////////
//           STRRET            //
/////////////////////////////////



static size_t strlcpy ( char *dst, const char *src, size_t bufsiz ) ;
static size_t wcslcpy ( wchar_t *dst, const wchar_t *src, size_t bufsiz ) ;
static int a2wlcpy ( wchar_t *dst, const char *src, int bufsiz ) ;
static int w2alcpy ( char *dst, const wchar_t *src, int bufsiz ) ;



// StrRetToBufA 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// STRRET 傪暥帤楍偵曄姺偡傞
static HRESULT StrretToBufA ( STRRET *pStrret, const ITEMIDLIST *pItemIdList, char *szBuffer, int nBufferSize ) {

   HRESULT hResult = E_FAIL ;

   switch ( pStrret->uType ) {
      case STRRET_WSTR :
         if ( nBufferSize && pStrret->pOleStr ) {
            w2alcpy ( szBuffer, pStrret->pOleStr, nBufferSize ) ;
            ShFree ( pStrret->pOleStr ) ;
            pStrret->pOleStr = NULL ;
            hResult = S_OK ;
         }
         break ;
      case STRRET_OFFSET :
         if ( nBufferSize ) {
            strlcpy ( szBuffer, (const char*) pItemIdList + pStrret->uOffset, nBufferSize ) ;
            hResult = S_OK ;
         }
         break ;
      case STRRET_CSTR :
         if ( nBufferSize ) {
            strlcpy ( szBuffer, pStrret->cStr, nBufferSize ) ;
            hResult = S_OK ;
         }
         break ;
   }

   return hResult ;
}



// StrRetToBufW 偲摨偠
// Win95/98/NT4 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// STRRET 傪暥帤楍偵曄姺偡傞
static HRESULT StrretToBufW ( STRRET *pStrret, const ITEMIDLIST *pItemIdList, wchar_t *szBuffer, int nBufferSize ) {

   HRESULT hResult = E_FAIL ;

   switch ( pStrret->uType ) {
      case STRRET_WSTR :
         if ( nBufferSize && pStrret->pOleStr ) {
            wcslcpy ( szBuffer, pStrret->pOleStr, nBufferSize ) ;
            ShFree ( pStrret->pOleStr ) ;
            pStrret->pOleStr = NULL ;
            hResult = S_OK ;
         }
         break ;
      case STRRET_OFFSET :
         if ( nBufferSize ) {
            a2wlcpy ( szBuffer, (const char*) pItemIdList + pStrret->uOffset, nBufferSize ) ;
            hResult = S_OK ;
         }
         break ;
      case STRRET_CSTR :
         if ( nBufferSize ) {
            a2wlcpy ( szBuffer, pStrret->cStr, nBufferSize ) ;
            hResult = S_OK ;
         }
         break ;
   }

   return hResult ;
}



// 巜掕偝傟偨挿偝傑偱暥帤楍傪僐僺乕偡傞乮ANSI斉乯
// bufsiz 偼 dst 偵廂傔傞偙偲偺偱偒傞嵟戝偺暥帤悢乮廔抂僰儖暥帤傪娷傓乯
// src 偺暥帤悢傪曉偡乮廔抂僰儖暥帤傪娷傑側偄乯
static size_t strlcpy ( char *dst, const char *src, size_t bufsiz ) {

   size_t srclen = strlen ( src ) ;

   if ( bufsiz ) {
      size_t cpylen = ( srclen < bufsiz ) ? srclen : bufsiz - 1 ;
      memmove ( dst, src, cpylen * sizeof(char) ) ;
      dst [ cpylen ] = 0 ;
   }

   return srclen ;
}



// 巜掕偝傟偨挿偝傑偱暥帤楍傪僐僺乕偡傞乮UNICODE斉乯
// bufsiz 偼 dst 偵廂傔傞偙偲偺偱偒傞嵟戝偺暥帤悢乮廔抂僰儖暥帤傪娷傓乯
// src 偺暥帤悢傪曉偡乮廔抂僰儖暥帤傪娷傑側偄乯
static size_t wcslcpy ( wchar_t *dst, const wchar_t *src, size_t bufsiz ) {

   size_t srclen = wcslen ( src ) ;

   if ( bufsiz ) {
      size_t cpylen = ( srclen < bufsiz ) ? srclen : bufsiz - 1 ;
      memmove ( dst, src, cpylen * sizeof(wchar_t) ) ;
      dst [ cpylen ] = 0 ;
   }

   return srclen ;
}



// 巜掕偝傟偨挿偝傑偱暥帤楍傪僐僺乕偡傞乮ANSI仺UNICODE斉乯
// bufsiz 偼 dst 偵廂傔傞偙偲偺偱偒傞嵟戝偺暥帤悢乮廔抂僰儖暥帤傪娷傓乯
// 杮棃偺 dst 偺暥帤悢傪曉偡乮廔抂僰儖暥帤傪娷傑側偄乯
static int a2wlcpy ( wchar_t *dst, const char *src, int bufsiz ) {

   size_t length = strlen ( src ) ;
   if ( (intptr_t) length != (int) length ) return -1 ;

   int srclen = (int) length ;
   int dstlen = MultiByteToWideChar ( CP_ACP, 0, src, srclen, NULL, 0 ) ;

   if ( bufsiz ) {
      int cpylen = ( dstlen < bufsiz ) ? dstlen : bufsiz - 1 ;
      MultiByteToWideChar ( CP_ACP, 0, src, srclen, dst, cpylen ) ;
      dst [ cpylen ] = 0 ;
   }

   return ( dstlen ) ? dstlen - 1 : 0 ;
}



// 巜掕偝傟偨挿偝傑偱暥帤楍傪僐僺乕偡傞乮UNICODE仺ANSI斉乯
// bufsiz 偼 dst 偵廂傔傞偙偲偺偱偒傞嵟戝偺暥帤悢乮廔抂僰儖暥帤傪娷傓乯
// 杮棃偺 dst 偺暥帤悢傪曉偡乮廔抂僰儖暥帤傪娷傑側偄乯
static int w2alcpy ( char *dst, const wchar_t *src, int bufsiz ) {

   size_t length = wcslen ( src ) ;
   if ( (intptr_t) length != (int) length ) return -1 ;

   int srclen = (int) length ;
   int dstlen = WideCharToMultiByte ( CP_ACP, 0, src, srclen, NULL, 0, NULL, NULL ) ;

   if ( bufsiz ) {
      int cpylen = ( dstlen < bufsiz ) ? dstlen : bufsiz - 1 ;
      memzero ( dst, ( cpylen + 1 ) * sizeof(char) ) ;
      WideCharToMultiByte ( CP_ACP, 0, src, srclen, dst, cpylen, NULL, NULL ) ;
   }

   return ( dstlen ) ? dstlen - 1 : 0 ;
}



////////////////////////////////////
//       儐乕僥傿儕僥傿乮1乯      //
////////////////////////////////////



// CSIDL偺僼僅儖僟柤傪庢摼偡傞乮ANSI斉乯
// Win95 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// 摦嶌偼 SHGetSpecialFolderPath 偲摨偠丄偨偩偟 fCreate 偼柍帇偡傞
// 惉岟偟偨傜 0 傪, 幐攕偟偨傜 0 埲奜傪曉偡
int WINAPI GetSpecialFolderPathA ( HWND hWnd, char *szPath, int nCsidl, int fCreate ) {

   int nResult = 1 ;
   *szPath = 0 ;

   ITEMIDLIST *pItemIdList = ShOpenSpecialItemIdList ( nCsidl ) ;
   if ( pItemIdList ) {
      if ( ! ShGetPathA ( pItemIdList, szPath ) ) nResult = 0 ;
      ShCloseItemIdList ( pItemIdList ) ;
   }

   return nResult ;
}



// CSIDL偺僼僅儖僟柤傪庢摼偡傞乮UNICODE斉乯
// Win95 偱偼僄僋僗億乕僩偝傟偰偄側偄偨傔帺慜偱張棟
// 摦嶌偼 SHGetSpecialFolderPath 偲摨偠丄偨偩偟 fCreate 偼柍帇偡傞
// 惉岟偟偨傜 0 傪, 幐攕偟偨傜 0 埲奜傪曉偡
int WINAPI GetSpecialFolderPathW ( HWND hWnd, wchar_t *szPath, int nCsidl, int fCreate ) {

   int nResult = 1 ;
   *szPath = 0 ;

   ITEMIDLIST *pItemIdList = ShOpenSpecialItemIdList ( nCsidl ) ;
   if ( pItemIdList ) {
      if ( ! ShGetPathW ( pItemIdList, szPath ) ) nResult = 0 ;
      ShCloseItemIdList ( pItemIdList ) ;
   }

   return nResult ;
}



////////////////////////////////////
//       儐乕僥傿儕僥傿乮2乯      //
////////////////////////////////////



// CSIDL偺僼僅儖僟傪奐偔乮ANSI斉乯
// 惉岟偟偨傜 0 傪, 幐攕偟偨傜 0 埲奜傪曉偡
int WINAPI OpenSpecialFolderA ( HWND hWnd, const char *szVerb, int nCsidl, int nShowCmd ) {

   int nResult = 1 ;

   ITEMIDLIST *pItemIdList = ShOpenSpecialItemIdList ( nCsidl ) ;
   if ( pItemIdList ) {
      if ( ! ShExecuteA ( hWnd, szVerb, pItemIdList, NULL, NULL, nShowCmd ) ) nResult = 0 ;
      ShCloseItemIdList ( pItemIdList ) ;
   }

   return nResult ;
}



// CSIDL偺僼僅儖僟傪奐偔乮UNICODE斉乯
// 惉岟偟偨傜 0 傪, 幐攕偟偨傜 0 埲奜傪曉偡
int WINAPI OpenSpecialFolderW ( HWND hWnd, const wchar_t *szVerb, int nCsidl, int nShowCmd ) {

   int nResult = 1 ;

   ITEMIDLIST *pItemIdList = ShOpenSpecialItemIdList ( nCsidl ) ;
   if ( pItemIdList ) {
      if ( ! ShExecuteW ( hWnd, szVerb, pItemIdList, NULL, NULL, nShowCmd ) ) nResult = 0 ;
      ShCloseItemIdList ( pItemIdList ) ;
   }

   return nResult ;
}



////////////////////////////////////
//       儐乕僥傿儕僥傿乮3乯      //
////////////////////////////////////



// 僔僃儖偵峏怴傪捠抦乮ANSI斉乯
int WINAPI ShellChangeNotifyA ( const char *szPathName ) {

   ITEMIDLIST *pItemIdList = ShOpenItemIdListA ( szPathName ) ;
   if ( ! pItemIdList ) return 1 ;

   ShChangeNotify ( pItemIdList ) ;
   ShCloseItemIdList ( pItemIdList ) ;

   return 0 ;
}



// 僔僃儖偵峏怴傪捠抦乮UNICODE斉乯
int WINAPI ShellChangeNotifyW ( const wchar_t *szPathName ) {

   ITEMIDLIST *pItemIdList = ShOpenItemIdListW ( szPathName ) ;
   if ( ! pItemIdList ) return 1 ;

   ShChangeNotify ( pItemIdList ) ;
   ShCloseItemIdList ( pItemIdList ) ;

   return 0 ;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -