就是得一个窗体,如打开了一个word,或者文件夹。然后写一个代码设置它的透明度。这样可以吗?

解决方案 »

  1.   

    记事本为例,参考:
    using System.Runtime.InteropServices;[DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    [DllImport("user32.dll")]
    private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string lpszClass, string lpszWindow);
    [DllImport("user32.dll")]
    public static extern bool SetLayeredWindowAttributes(
        IntPtr hWnd, int crKey, byte bAlpha, int dwFlags);
    [DllImport("user32.dll")]
    public static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, 
        IntPtr hrgnUpdate, uint flags);public const int GWL_EXSTYLE = -20;
    public const int WS_EX_LAYERED = 0x00080000;
    public const int LWA_ALPHA = 0x00000002;
    public const int RDW_INVALIDATE = 1;
    public const int RDW_ERASE = 4;
    public const int RDW_ALLCHILDREN = 0x80;
    public const int RDW_FRAME = 0x400;private void button1_Click(object sender, EventArgs e)
    {
        //设置透明
        IntPtr vHandle = FindWindow("Notepad", null);
        SetWindowLong(vHandle, GWL_EXSTYLE,
            GetWindowLong(vHandle, GWL_EXSTYLE) | WS_EX_LAYERED);
        SetLayeredWindowAttributes(vHandle, 0, 255 / 2/*透明度*/, LWA_ALPHA); 
    }private void button2_Click(object sender, EventArgs e)
    {
        //恢复
        IntPtr vHandle = FindWindow("Notepad", null);
        SetWindowLong(vHandle, GWL_EXSTYLE,
            GetWindowLong(vHandle, GWL_EXSTYLE) & ~WS_EX_LAYERED);
        RedrawWindow(vHandle, IntPtr.Zero, IntPtr.Zero,
            RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
    }
      

  2.   

    如果您已经熟悉了创建和组织地标和文件夹的基本操作,那您将可在本章了解到更多修改地标和文件夹外观的方法。您可以修改单个地标或整个文件夹的风格、位置、视图,方法是:在地标面板中,右击地标或文件夹,在弹出菜单中选择“属性 ”(Properties),在新出现的“编辑”(Edit)对话框中修改风格(Style)、位置(Location) 和视图(View)等相关属性。
      

  3.   

    1楼仁兄,IntPtr vHandle = FindWindow("Notepad", null);
    这段代码改成获得word的焦点,怎么获取,也就是“Notepad”应该怎么改?