2009-08-13 3 views
2

모든 창에 투명도를 설정하려고합니다. 나는 다음과 같은 코드를 가지고있다.C#에서 해당 핸들로 창 투명도를 설정할 수 있습니까?

public partial class Form1 : Form 
{ 
    [DllImport("user32.dll")] 
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

    [DllImport("user32.dll")] 
    static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

    [DllImport("user32.dll")] 
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags); 

    public const int GWL_EXSTYLE = -20; 
    public const int WS_EX_LAYERED = 0x80000; 
    public const int LWA_ALPHA = 0x2; 

    public Form1() 
    { 
     InitializeComponent(); 
     this.Load += new EventHandler(Form1_Load); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     Process[] processlist = Process.GetProcesses(); 

     foreach (Process theprocess in processlist) 
     { 
      SetWindowLong(theprocess.Handle, GWL_EXSTYLE, 
       GetWindowLong(theprocess.Handle, GWL_EXSTYLE)^WS_EX_LAYERED); 
      SetLayeredWindowAttributes(theprocess.Handle, 0, 128, LWA_ALPHA); 
     } 

    } 
} 

코드를 실행해도 아무런 변화가 없습니다.

무엇이 잘못 되었나요 ??

답변

5

SetWindowLong이 창 핸들을 (hWnd)이 필요하지만 :     ^ WS_EX_LAYERED  가 WS_EX_LAYERED 비트를 뒤집,

난 당신이 원하는 생각 대신 프로세스 핸들을 전달하십시오. 그을 변경 한 후

theProcess.MainWindowHandle 

theprocess.Handle 

의 모든 인스턴스를 변경 , 내가 그것을 테스트는 Windows XP 시스템에서 일했다. 다행히도 Visual Studio 2010 창은 영향을받지 않았습니다.

+0

정확히 내가 원했던 것이 !!! 감사 – Moon

1

the Opacity 설정을 시도해 보셨습니까?

this.Opacity = 0.50; 
+2

현재 창에 대한 불투명도 만 설정합니다. 이는 달성하려는 것이 아닙니다. – Thorarin

2

코드의이 부분 : '당신에게     | WS_EX_LAYERED