110,538
社区成员
发帖
与我相关
我的任务
分享
HWND WndHandle;
// 获取任务栏的窗口句柄,并显示
WndHandle = FindWindow(_T("Shell_TrayWnd"), NULL);
ShowWindow(WndHandle, SW_SHOW);
HWND WndHandle2;
// 获取开始按钮句柄,并显示
WndHandle2 = FindWindow(_T("Button"), NULL);
ShowWindow(WndHandle2, SW_SHOW);
public static void SetTaskBar(uint istate)
{
IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
IntPtr hStar = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Button", null);
if (trayHwnd != IntPtr.Zero && hStar!=IntPtr.Zero)
{
ShowWindow(trayHwnd, istate);
ShowWindow(hStar, istate);
}
}
[System.Runtime .InteropServices .DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[System.Runtime .InteropServices .DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
/// <summary>
/// SetTaskBar 1 表示显示, 0 表示隐藏
/// </summary>
/// <param name="istate"></param>
public static void SetTaskBar(uint istate)
{
IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
if (trayHwnd != IntPtr.Zero)
{
ShowWindow(trayHwnd, istate);
}
}
•引入Windows API 的声明
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow); <script type="text/javascript"><!-- google_ad_client = "pub-5834986413902221"; /* 728x90 */ google_ad_slot = "1368486102"; google_ad_width = 728; google_ad_height = 90; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> •显示/隐藏任务栏窗口
IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
if (trayHwnd != IntPtr.Zero)
{
ShowWindow(trayHwnd, 0);
}
上面的代码中, ShowWindow 的第二参数, 1 表示显示, 0 表示隐藏