很多底层操作的函数,Visual Studio 2005.NET 的 API 库中并没有提供,这个时候,我
们就要在 C#开发中调用 Win32 的函数来进行相应的操作。一大批 Win32 底层操作的函数
都存在于 cordll.dll 动态链接库中。
调用 Win32 的申明:
using System.Runtime.InteropServices;
很多客户的应用程序需要独占屏幕,而不需要下方的 Windows 任务栏。因此显示/隐藏
Windows 任 务 栏 是 一 个 很 实 用 的 功 能 。 这 个 时 候 就 需 要 调 用 coredll.dll 里 的
FindWindow( … )和 ShowWindow( … )函数来实现任务栏的显示和隐藏(Windows 的任务
栏实际上也是一个特殊的 Windows 窗口)。
[DllImport("coredll.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow( string lpWindowName, string lpClassName );
[DllImport("coredll.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow( int hwnd, int nCmdShow );
public const int SW_SHOW = 5; //显示窗口常量
public const int SW_HIDE = 0; //隐藏窗口常量
下面是一个隐藏/显示 Windows 任务栏的小例子:
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int Hwnd = FindWindow("HHTaskBar", null);
if (Hwnd != 0)
{
ShowWindow(Hwnd, SW_HIDE); //隐藏任务栏
button2.Enabled = true;
button1.Enabled = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
int Hwnd = FindWindow("HHTaskBar", null);
if (Hwnd != 0)
{
ShowWindow(Hwnd, SW_SHOW); //显示任务栏
button1.Enabled = true;
button2.Enabled = false;
}
}