• win32 IFolderView2::GetCurrentFolderFlags的使用


    转载:https://www.cnblogs.com/strive-sun/p/14068047.html

    下面的例子是将桌面的图标隐藏起来,使用了FWF_NOICONS样式。

    #include <ShlObj.h>     // Shell API
    #include <atlcomcli.h>  // CComPtr & Co.
    #include <string> 
    #include <iostream> 
    #include <system_error>
    #include <vector>
    #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
    
    // Throw a std::system_error if the HRESULT indicates failure.
    template< typename T >
    void ThrowIfFailed(HRESULT hr, T&& msg)
    {
        if (FAILED(hr))
            throw std::system_error{ hr, std::system_category(), std::forward<T>(msg) };
    }
    
    // RAII wrapper to initialize/uninitialize COM
    struct CComInit
    {
        CComInit() { ThrowIfFailed(::CoInitialize(nullptr), "CoInitialize failed"); }
        ~CComInit() { ::CoUninitialize(); }
        CComInit(CComInit const&) = delete;
        CComInit& operator=(CComInit const&) = delete;
    };
    
    // Query an interface from the desktop shell view.
    void FindDesktopFolderView(REFIID riid, void** ppv, std::string const& interfaceName)
    {
        CComPtr<IShellWindows> spShellWindows;
        ThrowIfFailed(
            spShellWindows.CoCreateInstance(CLSID_ShellWindows),
            "Failed to create IShellWindows instance");
    
        CComVariant vtLoc(CSIDL_DESKTOP);
        CComVariant vtEmpty;
        long lhwnd;
        CComPtr<IDispatch> spdisp;
        ThrowIfFailed(
            spShellWindows->FindWindowSW(
                &vtLoc, &vtEmpty, SWC_DESKTOP, &lhwnd, SWFO_NEEDDISPATCH, &spdisp),
            "Failed to find desktop window");
    
        CComQIPtr<IServiceProvider> spProv(spdisp);
        if (!spProv)
            ThrowIfFailed(E_NOINTERFACE, "Failed to get IServiceProvider interface for desktop");
    
        CComPtr<IShellBrowser> spBrowser;
        ThrowIfFailed(
            spProv->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&spBrowser)),
            "Failed to get IShellBrowser for desktop");
    
        CComPtr<IShellView> spView;
        ThrowIfFailed(
            spBrowser->QueryActiveShellView(&spView),
            "Failed to query IShellView for desktop");
      
        ThrowIfFailed(
            spView->QueryInterface(riid, ppv),
            "Could not query desktop IShellView for interface " + interfaceName);
    }
    
    
    void ToggleDesktopIcons()
    {
        CComPtr<IFolderView2> spView;
        FindDesktopFolderView(IID_PPV_ARGS(&spView), "IFolderView2");
    
        DWORD flags = 0;
        ThrowIfFailed(
            spView->GetCurrentFolderFlags(&flags),
            "GetCurrentFolderFlags failed");
        ThrowIfFailed(
            spView->SetCurrentFolderFlags(FWF_NOICONS, flags ^FWF_NOICONS),
            "SetCurrentFolderFlags failed");
    
      
    }
    
    
    
    int wmain(int argc, wchar_t** argv)
    {
        try
        {
            CComInit init;
    
            ToggleDesktopIcons();
    
            std::cout << "Desktop icons have been toggled.\n";
        }
        catch (std::system_error const& e)
        {
            std::cout << "ERROR: " << e.what() << ", error code: " << e.code() << "\n";
            return 1;
        }
    
        return 0;
    }
  • 相关阅读:
    再谈 最速下降法/梯度法/Steepest Descent
    再谈 共轭方向法/Conjugate Direction Method In Optimization
    最速下降法/steepest descent,牛顿法/newton,共轭方向法/conjugate direction,共轭梯度法/conjugate gradient 及其他
    conjugate gradient method (共轭梯度法)
    牛顿法
    海森矩阵 Hessian matrix
    Jackknife,Bootstraping, bagging, boosting, AdaBoosting, Random forest 和 gradient boosting的区别
    机器学习算法中如何选取超参数:学习速率、正则项系数、minibatch size
    机器学习中的数学(3)-模型组合(Model Combining)之Boosting与Gradient Boosting
    无约束最优化方法
  • 原文地址:https://www.cnblogs.com/Toya/p/15744952.html
Copyright © 2020-2023  润新知