IntPtr pWnd = Win32.FindWindow("Progman", "Program Manager");
Win32.SetParent(this.Handle, pWnd);嵌入桌面之后,设置透明
 Win32.SetWindowLong(this.Handle, Win32.GWL_EXSTYLE, Win32.GetWindowLong(this.Handle, Win32.GWL_EXSTYLE) |Win32.WS_EX_LAYERED);  Win32.SetLayeredWindowAttributes(this.Handle, 0x003F85CD, 100),  Win32.LWA_ALPHA);SetLayeredWindowAttributes返回false失败。请问如何解决。

解决方案 »

  1.   

    透明失败是因为调用Win32.SetParent(this.Handle, pWnd);导致的,
    但是我也不清楚为什么。下面的代码实现的效果应该是你要的,
    我刚才新建一个Form,测试了一下,没有问题,你核对一下!
    private const uint WS_EX_LAYERED = 0x80000; 
    private const int WS_EX_TRANSPARENT = 0x20; 
    private const int GWL_STYLE = (-16); 
    private const int GWL_EXSTYLE = (-20); 
    private const int LWA_ALPHA = 0x2; 
     
    [DllImport("user32", EntryPoint = "SetWindowLong")] 
    private static extern uint SetWindowLong( 
    IntPtr hwnd, 
    int nIndex, 
    uint dwNewLong 
    ); 
     
    [DllImport("user32", EntryPoint = "GetWindowLong")] 
    private static extern uint GetWindowLong( 
    IntPtr hwnd, 
    int nIndex 
    ); 
     
    [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")] 
    private static extern int SetLayeredWindowAttributes( 
    IntPtr hwnd, 
    int crKey, 
    int bAlpha, 
    int dwFlags 
    ); 
     
    /// <summary> 
    /// 设置窗体具有鼠标穿透效果 
    /// </summary> 
    public void SetPenetrate() 

        this.TopMost = true; 
        GetWindowLong(this.Handle, GWL_EXSTYLE); 
        SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED); 
        SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA); 

      

  2.   

    感谢2楼的回复。我的程序是要求内嵌到桌面里的。如果用了TopMost = true;就失去了嵌入桌面的效果了。
    谢谢你!
      

  3.   

    Win32.SetParent(this.Handle, pWnd);使窗体编程了桌面的子窗体。导致设置透明的参数WS_EX_LAYERED不可用。我只知道这些,不知道怎么处理。有没有办法把已经设置成子窗体的这个窗体伪装成顶级窗体之类的解决方案?
      

  4.   

    用API UpdateLayeredWindow 做成层窗体,并且设置为鼠标穿透等。
      

  5.   

    http://blog.csdn.net/hanghangaidoudou/article/details/4741173
      

  6.   

    你为什么要嵌入桌面呢?
    嵌入桌面很多问题的
    可以试试:
    SetWindowPos+HWND_BOTTOM把桌面设置为最低层
    然后屏幕最Win+D之类的操作