在win8前建立開始菜单都非常easy,但到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;

}