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
  • 相关阅读:
    js4——字符转化
    js3——表格下拉
    笔记展现
    js2——定时跳转
    js学习——1
    明明在/etc/my.cnf 配置了mysql.sock,为什么会在/var/lib/mysql/mysql.sock 里边寻找
    RBAC用户权限管理数据库设计
    mysql 字节问题,中文和数字
    PHP闭包
    一致性哈希算法原理
  • 原文地址:https://www.cnblogs.com/lin1270/p/2267775.html
Copyright © 2011-2022 走看看