自定义 Windows Mobile 设备上的任务栏
使用标志禁用/启用手持设备中的任务栏
引言
本文基本上提供了基于 Compact Framework 的手持设备任务栏启用或禁用功能。
背景
Compact Framework 本身不支持在设备中禁用或启用任务栏。因此,我使用了平台调用 (P/Invoke)。只需将此代码复制并粘贴到您的项目中,并根据您想要对任务栏执行的操作传递两个参数。
使用代码
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace PPC.Common
{
public class LockTaskBar
{
[DllImport("CoreDll.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string className, string WindowsName);
[DllImport("coredll.dll", EntryPoint = "EnableWindow")]
public static extern bool EnableWindow(IntPtr hwnd, bool bEnable);
/// <summary>
/// this is for enable and disable task bar.
/// Basically this is provide access control Start menu.
/// </summary>
/// <param name="HHTaskBar">HHTaskBar</param>
/// <param name="enabled">default false</param>
/// <returns></returns>
public static bool Execute(string HHTaskBar,bool enabled)
{
bool IsState = false;
try
{
IntPtr hwnd = FindWindow(HHTaskBar, null);
if (!hwnd.Equals(IntPtr.Zero))
{
if (enabled)
{
IsState = EnableWindow(hwnd, false);
}
else
{
IsState =EnableWindow(hwnd, true);
}
}
}
catch (DllNotFoundException dllex)
{
throw dllex;
}
catch (Exception ex)
{
throw ex;
}
return IsState;
}
}
}
只需将代码复制并粘贴到您的项目中,并调用 Execute
方法,传递窗口句柄字符串 HHTaskBar
。 如果要禁用“开始”菜单,请传递 true
,否则传递 false
。
历史
- 第一个版本:2008/01/01。