网上关于IFolderView2接口调用的示例有点少。

下面的例子是将桌面的图标隐藏起来,使用了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;
}

另外,我在寻找IFolderView2::GetSortColumns的使用实例,如果有人碰巧做过这样的案例,可以在评论区中告诉我。

win32 - IFolderView2::GetCurrentFolderFlags的使用的更多相关文章

  1. C#[Win32&WinCE&WM]应用程序只能运行一个实例:MutexHelper

    前言 在开发应用程序时,通常只让程序运行一个实例.所以,就要判断程序是否已经运行. 下面是我自己在项目中使用到,封装好的帮助类.有 普通的 C# 应用程序 和 Windows CE 和 Windows ...

  2. java.lang.UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序。

    JNA 调用 dll 库时,保错: ///////////////// 通过 JNA 引入 DLL 库 //////////// /** * ID_FprCap.dll 负责指纹的采集, 指纹仪的初始 ...

  3. 初次认识 C# win32 api

    第一次接触win32api,刚开始的时候有点迷迷糊糊的. Windows API 就是windows应用程序接口. win api向上就是windows应用程序,向下就是windows操作系统核心. ...

  4. [老文章搬家] [翻译] 深入解析win32 crt 调试堆

    09 年翻译的东西. 原文见:  http://www.nobugs.org/developer/win32/debug_crt_heap.html 在DeviceStudio的Debug编译模式下, ...

  5. Virus.Win32.Virlock.b分析

    0x00 样本说明 分析样本是被0b500d25f645c0b25532c1e3c9741667的样本感染得到.感染前的文件是Tcpview.exe,一款windows网络连接查看工具. 感染前后文件 ...

  6. cocos2d-x 从win32到android移植的全套解决方案

    引言:我们使用cocos2d-x引擎制作了一款飞行射击游戏,其中创新性地融入了手势识别功能.但是我们在移植过程中遇到了很多的问题,同时也发现网上的资料少而不全.所以在项目行将结束的时候,我们特地写了这 ...

  7. Git使用出错:Couldn‘t reserve space for cygwin‘s heap, Win32

    今天使用Git在命令行下更新代码遇到了问题,起初觉得是自己安装某软件导致冲突,从网上搜索了一下找到类似问题,成功解决问题. 错误信息如下: E:\storm-sql>git pull origi ...

  8. ATL封装IE内核启示:使用Win32/ATL建立窗口

    开发大型GUI界面程序MFC当仁不让,但如果是开发图形应用程序,并不需要大规模界面控件,没有必要链接庞大的MFC库,直接使用platform sdk会很麻烦,这时ATL中的关于Windows的封装就是 ...

  9. Win32 OpenProcess打开进程失败,返回5无权限操作

    Win32 OpenProcess打开进程失败,返回5无权限操作,相信你会碰到这样的事,在IDE中可以,单独却不可以了,其实这时就需要提权了,否则是无法打开的,OpenProcess提权至Debug即 ...

  10. win32进程名查找进程PID

    1. #include <Psapi.h> #pragma comment(lib, "Psapi.lib") DWORD GetProcIDFromName(LPCT ...

随机推荐

  1. linux 内存盘的使用方式与验证

    linux 内存盘的使用方式与验证 背景 某些情况下, 硬盘的写入是一个很大的瓶颈 使用 内存文件系统的方式应该能够极大的提高IO的速度. 内存盘的优点是比较快, 缺点就是数据不是持久化的. 其实还是 ...

  2. [转帖]goproxy的设置

    goproxy.io 是全球最早的 Go modules 镜像代理服务之一 [大陆地区建议使用 proxy.golang.com.cn],采用 CDN 加速服务为开发者提供依赖下载, 该服务由一批热爱 ...

  3. [转帖]Nginx反向代理中使用proxy_redirect重定向url

    https://www.cnblogs.com/kevingrace/p/8073646.html 在使用Nginx做反向代理功能时,有时会出现重定向的url不是我们想要的url,这时候就可以使用pr ...

  4. [转帖] Strace的介绍与使用

    https://www.cnblogs.com/skandbug/p/16264609.html Strace简介 strace命令是一个集诊断.调试.统计于一体的工具,常用来跟踪进程执行时的系统调用 ...

  5. [转帖]比 Python 快 35000 倍!LLVM&Swift 之父宣布全新编程语言 Mojo:编程被颠覆了

    https://www.infoq.cn/article/GFfVLVpkIGOcKYB85Opb "Mojo 可能是近几十年来最大的编程语言进步." 近日,由 LLVM 和 Sw ...

  6. [转帖]如何优雅的使用 Systemd 管理服务

    https://zhuanlan.zhihu.com/p/271071439 背景:我们在构建 Kubernetes 容器化平台时,会在节点上部署各种 agent ,虽然容器化当道的今天很多程序可以直 ...

  7. 使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑

    对象中有时间类型的时候(时间类型会被变成字符串类型数据) const obj = { date: new Date() } console.log(typeof obj.date === 'objec ...

  8. 从零开始匹配vim(2)——快捷键绑定

    如果说 vim有什么最吸引人,我想vim允许你自由的定义各种快捷键算是一个原因吧.你可以通过绑定各种快捷键来使经常使用的功能更加便利.通俗的讲,快捷键映射就是我按下某个键,我想让vim将它当成另一个键 ...

  9. 【任务调度】Spring 的动态定时任务之 ScheduledTaskRegistrar(解决方案一)

    前言 ​ 在做SpringBoot项目的过程中,有时客户会提出按照指定时间执行一次业务的需求. ​ 如果客户需要改动业务的执行时间,即动态地调整定时任务的执行时间,那么可以采用SpringBoot自带 ...

  10. [MySQL] 给root用户设置权限

    mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'root'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'roo ...