如何prevent被固定在Windows 7的应用程序?应用程序、prevent、Windows

2023-09-04 02:00:14 作者:仅一心 不二情

我想prevent从钉扎我的.NET应用程序到任务栏的用户。我发现在旧的新的一些code事情的做到了这一点。但是,它是在C ++中。

I am trying to prevent the user from pinning my .NET app to the taskbar. I've found some code on the Old New Thing that does just that. However, it is in C++.

#include <shellapi.h>
#include <propsys.h>
#include <propkey.h>

HRESULT MarkWindowAsUnpinnable(HWND hwnd)
{
 IPropertyStore *pps;
 HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps));
 if (SUCCEEDED(hr)) {
  PROPVARIANT var;
  var.vt = VT_BOOL;
  var.boolVal = VARIANT_TRUE;
  hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
  pps->Release();
 }
 return hr;
}


BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
 MarkWindowAsUnpinnable(hwnd);
 return TRUE;
}

我有很少的运气将其转换为C#。有人可以帮忙吗?

I am having very little luck converting it to c#. Can someone help?

推荐答案

您也可以下载Windows您需要翻译的code在帖子中为C#API code包有必要的P / Invoke调用。

You can download the Windows API Code Pack which has the necessary p/invoke calls you need to translate the code in your post to C#.

既可以使用库中的全部或找到您所需要(搜索它 SHGetPropertyStoreForWindow ,然后它的其他依赖关系)的具体要求和定义。

Either use the library in whole or find the specific calls and definitions you require (search it for SHGetPropertyStoreForWindow and then its other dependencies).