Win8下建立shortcut到开始界面

在win8前建立开始菜单都很容易,但到win8就有点不一样了,它的开始菜单是metro风格的。下面我们来看下具体的实现代码,有兴趣的朋友可以自己测试下,它的作用是设置shortcut到metro start menu.  如果是要阻止到start menu的话,把APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL改为PKEY_AppUserModel_PreventPinning。

void SetShortcutStartPinOption()

{

wchar_t szPath[MAX_PATH];

SHGetSpecialFolderPath(nullptr, szPath, CSIDL_PROGRAMS, FALSE);
PathAppend(szPath, L"testapp.lnk");
int nRet = 1;
// initialize the COM library
CoInitialize(NULL);


IPropertyStore *pps;
if (SUCCEEDED(SHGetPropertyStoreFromParsingName(szPath, NULL, GPS_READWRITE, __uuidof(IPropertyStore), (void**)&pps)))
{
PROPVARIANT pv;

// --- Set StartPinOption.
if (SUCCEEDED(pps->GetValue(PKEY_AppUserModel_StartPinOption, &pv)))
{

if (SUCCEEDED(InitPropVariantFromUInt32(APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL, &pv)))
{

if (SUCCEEDED(pps->SetValue(PKEY_AppUserModel_StartPinOption, pv)))
{

if (SUCCEEDED(pps->Commit()))
{
nRet = 0;
}
}
}
}
}

if (pps != NULL)
pps->Release();
CoUninitialize();
return nRet;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值