WinForms子表单到另一个进程

时间:2013-02-18 01:58:14

标签: c# winforms

我正在尝试在没有激活的情况下在其他进程表单上创建子表单,一切都很好,除了我的表单在显示时出现在屏幕前面 - 在f.Visible = true之后 - 但我需要将它们两个都放在后面

这是代码:

public class OSD {
    public class OSD_form:Form {
        protected override bool ShowWithoutActivation {
            get { return true; }
        }
        protected override CreateParams CreateParams {
            get {
                CreateParams p=base.CreateParams;

                //p.Style |= 0x40000000; // WS_CHILD
                p.ExStyle|=0x8000000; // WS_EX_NOACTIVATE
                p.ExStyle|=0x00080000; // WS_EX_LAYERED
                p.ExStyle|=0x0020; // WS_EX_TRANSPARENT

                return p;
            }
        }
    }
    private OSD_form f=null;
    public IntPtr AttachedTo=IntPtr.Zero;

    public OSD() {
        f=new OSD_form();

        f.FormBorderStyle=FormBorderStyle.None;
        f.ShowInTaskbar=false;
    }

    public void Show() {
        long l2=winapi.GetWindowLong(f.Handle,winapi.GWL_EXSTYLE);
        l2|=winapi.WS_EX_LAYERED;
        l2|=winapi.WS_EX_TRANSPARENT;
        winapi.SetWindowLong(f.Handle,winapi.GWL_EXSTYLE,new IntPtr(l2));
        winapi.SetLayeredWindowAttributes(f.Handle,0,(255*90)/100,winapi.LWA_ALPHA);

        window w=new window(AttachedTo);
        f.Width=160;
        f.Height=60;
        f.Left=w.Client.Left+4;
        f.Top=w.Client.Top+4;

        f.Show(new WindowWrapper(AttachedTo));

        f.Visible=true;

    }
}

0 个答案:

没有答案