문제

모든 창의 투명성을 설정하려고합니다. 다음 코드가 있습니다.

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);
        }

    }
}

코드를 실행할 때 아무 일도 일어나지 않습니다.

뭐가 잘못 되었 니??

도움이 되었습니까?

해결책

SetWindowLong 창 핸들 (HWND)을 가져 가지만 대신 프로세스 핸들을 전달합니다. 모든 인스턴스를 변경하십시오

theprocess.Handle

에게

theProcess.MainWindowHandle

그것을 변경 한 후, 테스트 한 Windows XP 시스템에서 작동했습니다. 이제 Windows를 정상으로 되 돌리려면 코드를 수정해야합니다.) 운 좋게도 Visual Studio 2010 창은 영향을받지 않았습니다.

다른 팁

코드 의이 부분 : ^ WS_EX_LAYERED ws_ex_layered 비트를 뒤집고

나는 당신이 원한다고 생각합니다 : | WS_EX_LAYERED

설정을 시도해 보셨습니까? 불투명도?

this.Opacity = 0.50;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top