mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. DotNET
  3. Main content

通过win32api让c#控制Windows任务栏

2009-10-12 109hotness 0likes 0comments

如果你要在你的C#程序中控制Windows的任务栏,有两个Windows api 可以帮到你!他们就是  FindWindowA 和 ShowWindow
C#中声明如下:
using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint = "FindWindowA")]
public static extern IntPtr FindWindowA(string lp1, string lp2);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern IntPtr ShowWindow(IntPtr hWnd, int _value);
其实Windows的任务栏就是一个特殊的窗口,所以操作窗口的方法,对任务栏一样适合!控制代码如下:
//获取任务栏
IntPtr hTray = Form1.FindWindowA("Shell_TrayWnd", String.Empty);
//显示任务栏
Form1.ShowWindow(hTray, 5);
//隐藏任务栏
Form1.ShowWindow(hTray, 0);

 

 

原文:http://www.pinvoke.net/default.aspx/user32/DrawAnimatedRects.html 

C# Signature:


[DllImport("user32.dll")]
static extern bool DrawAnimatedRects(IntPtr hwnd, int idAni,
   [In] ref RECT lprcFrom, [In] ref RECT lprcTo);
 


User-Defined Types:


IDANI_


Notes:


Only the IDANI_CAPTION constant will result in any animation. Any other constants have not been implemented on any Windows platform!


Tips & Tricks:


Since only IDANI_CAPTION is implemented, to get the effect of IDANI_OPEN, simply swap the lprcFrom and lprcTo rectangles, but still specify the IDANI_CAPTION constant.


Sample Code:


    /// <summary>
    /// This constant is not implemented on any Windows platform!
    /// </summary>
    public const System.Int32 IDANI_OPEN = 1;

    /// <summary>
    /// The window caption will animate from lprcFrom to lprcTo.
    /// </summary>
    public const System.Int32 IDANI_CAPTION = 3;

    [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
    struct RECT
    {
      public RECT(System.Drawing.Rectangle rectangle)
      {
        Left = rectangle.Left;
        Top = rectangle.Top;
        Right = rectangle.Right;
        Bottom = rectangle.Bottom;
      }
      public RECT(System.Drawing.Point location, System.Drawing.Size size)
      {
        Left = location.X;
        Top = location.Y;
        Right = location.X + size.Width;
        Bottom = location.Y + size.Height;
      }
      public System.Int32 Left;
      public System.Int32 Top;
      public System.Int32 Right;
      public System.Int32 Bottom;
    }

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern bool DrawAnimatedRects(System.IntPtr hwnd, int idAni,
      [System.Runtime.InteropServices.In] ref RECT lprcFrom,
      [Sy

Tag: Nothing
Last updated:2009-10-12

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang