private void AttachWindowBtn_Clicked(object sender, MouseButtonEventArgs e) { if (AttachCore.IsAttached) { AttachCore.Detach(); SetDetach(); // widget // TODO : Weird behaviour when transparent window attached the second time. So hide it for now. // Need restart the software to attach to a new client window Widget.Hide(); //Widget.Close(); //Widget = null; } else { SetAttach(); if (AttachCore.AttachToClient(true)) { // widget if (Widget == null) { Widget = new WidgetWindow(this); Widget.TargetLostDetached += Widget_TargetLostDetached; Widget.Show(); IntPtr hwndWidget = new WindowInteropHelper(Widget).Handle; uint dwStyleWidget = Native.GetWindowLong(hwndWidget, (int)Native.WindowLongFlags.GWL_STYLE); dwStyleWidget |= (uint)Native.WindowStyles.WS_CHILDWINDOW; Native.SetWindowLong(hwndWidget, (int)Native.WindowLongFlags.GWL_STYLE, dwStyleWidget); Widget.AttachToClient(); AttachCore.AttachToClient(); } else { Widget.Show(); } } else { SetDetach(); } } }
public void AttachToClient() { Rect clientRect = AttachCore.GetClientWindowRect(); this.Left = clientRect.Width - 150; this.Top = 7; AttachCore.AttachToClient(); }