获取固定到任务栏的快捷方式的图标

15 篇文章 0 订阅

这是之前不知道从哪里找到的demo代码,是获取固定到任务栏的快捷方式的图标信息的。也就是将此程序锁定到任务栏后,通过下面的代码可以获取到锁定到任务栏的信息。相信也可以实现锁定到任务栏,我这里仅仅是搬运过来备忘。代码实测可以运行。

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <tchar.h>

#include <windows.h>
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "uuid.lib")
#include <shlobj.h>

#include <initguid.h>

DEFINE_GUID(CLSID_TaskbandPin, 0x90AA3A4E,0x1CBA,0x4233,0xB8,0xBB,0x53,0x57,0x73,0xD4,0x84,0x49);

static IID iids[] = {
	{ 0x60274FA2, 0x611F, 0x4B8A, { 0xA2,0x93,0xF2,0x7B,0xF1,0x03,0xD1,0x48 } },
	{ 0xBBD20037, 0xBC0E, 0x42F1, { 0x91,0x3F,0xE2,0x93,0x6B,0xB0,0xEA,0x0C } },
	{ 0xC3C6EB6D, 0xC837, 0x4EAE, { 0xB1,0x72,0x5F,0xEC,0x52,0xA2,0xA4,0xFD } }
};

DECLARE_INTERFACE_(IFlexibleTaskbarPinnedList, IUnknown)
{
	STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE;
	STDMETHOD_(ULONG, AddRef)(THIS) PURE;
	STDMETHOD_(ULONG, Release)(THIS) PURE;
	STDMETHOD(EnumObjects)(THIS_ IEnumFullIDList **) PURE;
};

int main(int argc, char *argv[])
{
#if defined(UNICODE) || defined(_UNICODE)
	setlocale(LC_CTYPE, ".ACP");
#endif
	HRESULT hr = CoInitialize(NULL);
	if (hr == S_OK)
	{
		IUnknown *punkn = NULL;
		hr = CoCreateInstance(CLSID_TaskbandPin, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&punkn);
		if (hr == S_OK)
		{
			IFlexibleTaskbarPinnedList *pftpl = NULL;
			for (size_t i = 0; i < ARRAYSIZE(iids); i++)
			{
				hr = punkn->QueryInterface(iids[i], (void **)&pftpl);
				if (hr == S_OK)
				{
					break;
				}
			}
			if (hr == S_OK)
			{
				IEnumFullIDList *lpeil = NULL;
				hr = pftpl->EnumObjects(&lpeil);
				if (hr == S_OK)
				{
					ULONG ulFetched = 0;
					LPITEMIDLIST pidl = NULL;
					hr = lpeil->Reset();
					do {
						hr = lpeil->Next(1, &pidl, &ulFetched);
						if (hr == S_OK)
						{
							SHFILEINFO shfi = { 0 };
							SHGetFileInfo((LPCTSTR)pidl, 0, &shfi, sizeof(shfi), SHGFI_PIDL | SHGFI_DISPLAYNAME);
							_tprintf(_T("%s\n"), shfi.szDisplayName);
							CoTaskMemFree(pidl);
						}
					} while (hr == S_OK);
					lpeil->Release();
				}
				pftpl->Release();
			}
			punkn->Release();
		}
		CoUninitialize();
	}
	return !getchar();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值