zoukankan      html  css  js  c++  java
  • 打开文件夹,并选中文件

    #ifndef    ExploreFileH
    #define ExploreFileH
     
    #include <Windows.h>
    #include <Shlobj.h>




    #ifdef UNICODE
    #define ExploreFile ExploreFileW
    #elif _UNICODE
    #define ExploreFile ExploreFileW
    #else
    #define ExploreFile ExploreFileA
    #endif




    BOOL
    ExploreFileA (const char* pszFile)
    {
    wchar_t wszFile [MAX_PATH + 1] = {0};
    if (!MultiByteToWideChar(
    CP_ACP,
    MB_PRECOMPOSED,
    pszFile,
    -1,
    wszFile,
    MAX_PATH))
    {
    return FALSE;
    }

    return ExploreFileW (wszFile);
    }




    BOOL
    ExploreFileW (const wchar_t* pwszFile)
    {
    LPITEMIDLIST pidl;
    LPCITEMIDLIST cpidl, cpidl2;
    IShellFolder* pDesktopFolder;

    ULONG ulEaten;
    DWORD dwAttributes;
    HRESULT hr;

    if (pwszFile == NULL) {
    return FALSE;
    }

    ulEaten = wcslen (pwszFile);

    if (FAILED (SHGetDesktopFolder (&pDesktopFolder))) {
    return FALSE;
    }

    hr = pDesktopFolder->ParseDisplayName (
    NULL,
    0,
    (LPOLESTR)pwszFile,
    &ulEaten,
    &pidl,
    &dwAttributes);

    if (FAILED (hr)) {
    pDesktopFolder->Release ();
    return FALSE;
    }

    cpidl2 = cpidl = pidl;


    CoInitialize (NULL);
    if (FAILED (SHOpenFolderAndSelectItems (
    cpidl,
    0,
    &cpidl2, // 一定要弄个cpidl2,否则会有内存泄露,一次4K,木有搞懂,高手帮解答。
    NULL)))
    {
    pDesktopFolder->Release ();
    CoUninitialize ();
    return FALSE;
    }

    pDesktopFolder->Release ();
    CoUninitialize ();
    return TRUE;
    }



    #endif // ExploreFileH
  • 相关阅读:
    typescript提示implicitly has an 'any' type 问题
    element-ui中的table可分页多选功能-记住上一页勾选数据
    CSS加载会阻塞页面显示?
    网络流(EK算法)
    网络流(dinic算法)
    洛谷p1120小木棍(剪枝优化)
    三种背包模板
    HDU2089-不要62(数位dp)
    windy数(数位dp)
    素数判定(待填坑)
  • 原文地址:https://www.cnblogs.com/lin1270/p/2267775.html
Copyright © 2011-2022 走看看