Esempio n. 1
0
 private static void OnIsPopupEventTransparentPropertyChanged(
     DependencyObject target,
     DependencyPropertyChangedEventArgs e)
 {
     try
     {
         if (!(target is Popup popup))
         {
             return;
         }
         if ((bool)e.NewValue)
         {
             HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual((Visual)popup.Child);
             InteropWindow.SetWindowLong(hwndSource.Handle, -20, InteropWindow.GetWindowLong(hwndSource.Handle, -20) | 32);
         }
         else
         {
             HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual((Visual)popup.Child);
             InteropWindow.SetWindowLong(hwndSource.Handle, -20, InteropWindow.GetWindowLong(hwndSource.Handle, -20) & -33);
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in setting popup event transparent: " + ex.ToString());
     }
 }
Esempio n. 2
0
        /// <summary>
        ///  Initializes the <see cref="InteropWindow"/>.
        /// </summary>
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            //This can be called more then once
            if (!firstRender)
            {
                return;
            }

            //Load the sound interop in JavaScript
            _interopSounds = new InteropSounds(JsRuntime);

            if (!await _interopSounds.Initialize(_controller.ActionSounds))
            {
                Console.WriteLine($"ERROR '{nameof(InteropSounds)}': Could not initialize sounds in JavaScript.");
            }

            //Load the window interop in JavaScript
            _interopWindow = new InteropWindow(JsRuntime);
            await _interopWindow.Initialize();

            //Force a refresh
            await InvokeAsync(StateHasChanged);
        }
Esempio n. 3
0
        private static void CheckIfAlreadyRunning()
        {
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_Log_Collector_Lockbgp", out App.sLogCollectorLock))
            {
                return;
            }
            bool flag = false;

            Logger.Info("LogCollector already running.");
            if (App.sOpt.Boot || App.sOpt.Apk || (App.sOpt.D || App.sOpt.Thin) || (App.sOpt.Silent || App.sOpt.Hidden))
            {
                flag = true;
            }
            if (!flag)
            {
                IntPtr window = InteropWindow.FindWindow((string)null, LocaleStrings.GetLocalizedString("STRING_BST_SUPPORT_UTILITY", ""));
                if (window != IntPtr.Zero)
                {
                    InteropWindow.SetForegroundWindow(window);
                }
                else
                {
                    CustomMessageWindow customMessageWindow = new CustomMessageWindow();
                    customMessageWindow.TitleTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_BST_SUPPORT_UTILITY", "");
                    customMessageWindow.BodyTextBlock.Text  = LocaleStrings.GetLocalizedString("STRING_LOGCOLLECTOR_RUNNING", "");
                    customMessageWindow.AddButton(ButtonColors.Blue, LocaleStrings.GetLocalizedString("STRING_OK", ""), (EventHandler)null, (string)null, false, (object)null, true);
                    customMessageWindow.ShowDialog();
                }
            }
            App.KillApplication();
        }
Esempio n. 4
0
        private static void CheckIfAlreadyRunning(bool hideMode)
        {
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock(Strings.GetPlayerLockName(MultiInstanceStrings.VmName, "bgp"), out Program.sFrontendLock))
            {
                return;
            }
            Logger.Info("Frontend already running");
            IntPtr zero = IntPtr.Zero;

            if (!hideMode)
            {
                IntPtr front = Program.BringToFront(MultiInstanceStrings.VmName);
                if (front != IntPtr.Zero)
                {
                    Logger.Info("Sending WM_USER_SHOW_WINDOW to Frontend handle {0}", (object)front);
                    InteropWindow.SendMessage(front, 1025U, IntPtr.Zero, IntPtr.Zero);
                }
                else
                {
                    Dictionary <string, string> data = new Dictionary <string, string>();
                    try
                    {
                        Logger.Info("ShowWindow result: " + HTTPUtils.SendRequestToEngine("showWindow", data, MultiInstanceStrings.VmName, 0, (Dictionary <string, string>)null, false, 1, 0, "", "bgp"));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning("Exception in ShowWindow request failed. Err: {0}", (object)ex.Message);
                    }
                }
            }
            Environment.Exit(0);
        }
Esempio n. 5
0
        internal void InitLayout()
        {
            MainWindow parentWindow  = this.ParentWindow;
            Grid       mFrontendGrid = parentWindow.mFrontendGrid;
            Point      point1        = mFrontendGrid.TranslatePoint(new Point(), (UIElement)parentWindow);

            if (this.IsInOverlayMode)
            {
                this.Background          = (Brush)Brushes.Transparent;
                this.mCanvas.Background  = (Brush)Brushes.Transparent;
                this.mCanvas2.Background = (Brush)Brushes.Transparent;
                this.mCanvas.Margin      = new Thickness();
                if (Oem.IsOEMDmm)
                {
                    this.Opacity = RegistryManager.Instance.TranslucentControlsTransparency;
                }
                else
                {
                    string path = Path.Combine(Path.Combine(RegistryManager.Instance.ClientInstallDir, "ImapImages"), this.ParentWindow.mTopBar.mAppTabButtons.SelectedTab.PackageName + ".png");
                    if (File.Exists(path))
                    {
                        this.mCanvasImage.ImageName = path;
                        this.mCanvas.Opacity        = 0.0;
                    }
                    else
                    {
                        this.mCanvas.Opacity = 1.0;
                    }
                }
                this.Handle = WindowInteropHelperExtensions.EnsureHandle(new WindowInteropHelper((Window)this));
                InteropWindow.SetWindowLong(this.Handle, -16, 1207959552);
            }
            else
            {
                IntereopRect fullscreenMonitorSize = WindowWndProcHandler.GetFullscreenMonitorSize(this.ParentWindow.Handle, true);
                double       width = (double)fullscreenMonitorSize.Width - (double)this.mSidebarWidth * MainWindow.sScalingFactor;
                if (!this.ParentWindow.EngineInstanceRegistry.IsSidebarVisible)
                {
                    width -= this.ParentWindow.mSidebar.Width * MainWindow.sScalingFactor;
                }
                double height = this.ParentWindow.GetHeightFromWidth(width, true, false);
                if (height > (double)fullscreenMonitorSize.Height)
                {
                    height = (double)fullscreenMonitorSize.Height;
                    width  = this.ParentWindow.GetWidthFromHeight(height, true, false);
                }
                double top  = this.ParentWindow.Top * MainWindow.sScalingFactor + height <= (double)(fullscreenMonitorSize.Y + fullscreenMonitorSize.Height) ? this.ParentWindow.Top * MainWindow.sScalingFactor : (double)fullscreenMonitorSize.Y + ((double)fullscreenMonitorSize.Height - height) / 2.0;
                double left = this.ParentWindow.Left * MainWindow.sScalingFactor + width + (double)this.mSidebarWidth * MainWindow.sScalingFactor <= (double)(fullscreenMonitorSize.X + fullscreenMonitorSize.Width) ? this.ParentWindow.Left * MainWindow.sScalingFactor : (double)fullscreenMonitorSize.X + ((double)fullscreenMonitorSize.Width - width - (double)this.mSidebarWidth * MainWindow.sScalingFactor) / 2.0;
                this.ParentWindow.ChangeHeightWidthTopLeft(width, height, top, left);
                this.Width          = this.ParentWindow.ActualWidth;
                this.Height         = this.ParentWindow.ActualHeight;
                this.Top            = this.ParentWindow.Top;
                this.Left           = this.ParentWindow.Left;
                this.mCanvas.Width  = this.ParentWindow.mFullScreenRestoredButNotSidebar ? mFrontendGrid.ActualWidth - this.ParentWindow.mSidebar.Width : mFrontendGrid.ActualWidth;
                this.mCanvas.Height = mFrontendGrid.ActualHeight;
                Point point2 = new Point(parentWindow.ActualWidth - (this.mCanvas.Width + point1.X), parentWindow.ActualHeight - (mFrontendGrid.ActualHeight + point1.Y));
                this.mCanvas.Margin = new Thickness(point1.X, point1.Y, point2.X, point2.Y);
            }
        }
Esempio n. 6
0
        public static bool HideSubWindow()
        {
            IntPtr subWindow = Opengl.GetSubWindow();

            if (subWindow == IntPtr.Zero)
            {
                return(false);
            }
            InteropWindow.ShowWindow(subWindow, 0);
            return(true);
        }
        /// <summary>
        ///  Initializes the <see cref="InteropWindow"/>.
        /// </summary>
        /// <remarks>
        ///  Base <see cref="BlazorComponent.OnAfterRenderAsync"/> returns null so do not call.
        /// </remarks>
        protected override async Task OnAfterRenderAsync()
        {
            //This can be called more then once
            if (_interopWindow != null)
            {
                return;
            }

            _interopWindow = new InteropWindow(JSRuntime);
            await _interopWindow.Initialize();
        }
Esempio n. 8
0
    public static string KeyCodeToUnicode(Key key)
    {
        int           num            = KeyInterop.VirtualKeyFromKey(key);
        uint          wScanCode      = InteropWindow.MapVirtualKey((uint)num, 0U);
        IntPtr        keyboardLayout = InteropWindow.GetKeyboardLayout(0U);
        StringBuilder pwszBuff       = new StringBuilder();

        InteropWindow.ToUnicodeEx((uint)num, wScanCode, new byte[(int)byte.MaxValue], pwszBuff, 5, 0U, keyboardLayout);
        Logger.Info("value........................." + pwszBuff.ToString());
        return(pwszBuff.ToString());
    }
Esempio n. 9
0
 private void mCloseBtn_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     this.ParentWindow.mIsDMMRecommendedWindowOpen = false;
     this.Hide();
     InteropWindow.ShowWindow(this.ParentWindow.Handle, 9);
     if (this.ParentWindow.Topmost)
     {
         return;
     }
     this.ParentWindow.Topmost = true;
     this.ParentWindow.Topmost = false;
 }
Esempio n. 10
0
 private HDApkInstaller(string apk, string vmName)
 {
     InteropWindow.FreeConsole();
     if (!HDApkInstaller.s_IsSilent)
     {
         this.InitializeComponents();
     }
     if (apk == null)
     {
         return;
     }
     this.Install(apk, vmName);
 }
Esempio n. 11
0
        /// <summary>
        ///  Initializes the <see cref="InteropWindow"/>.
        /// </summary>
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            //This can be called more then once
            if (!firstRender)
            {
                return;
            }

            _interopWindow = new InteropWindow(JsRuntime);
            await _interopWindow.Initialize();
        }
 internal void FocusFrontend()
 {
     if (this.CanfrontendBeResizedAndFocused() && !this.ParentWindow.mStreamingModeEnabled && (!this.ParentWindow.mIsFocusComeFromImap && this.ParentWindow.IsActive))
     {
         InteropWindow.SetFocus(this.mFrontendHandle);
         Logger.Debug("KMP REFRESH Frontend...." + Environment.StackTrace);
         this.SendFrontendRequestAsync("refreshWindow", (Dictionary <string, string>)null);
     }
     else
     {
         Logger.Debug("KMP CanfrontendBeResizedAndFocused false " + this.ParentWindow.mFrontendGrid.IsVisible.ToString() + this.sIsfrontendAlreadyVisible.ToString());
     }
 }
Esempio n. 13
0
        private static IntPtr BringToFront(string vmname)
        {
            Logger.Info(string.Format("Starting BlueStacks {0} Frontend", (object)vmname));
            string name = Oem.Instance.CommonAppTitleText + MultiInstanceStrings.VmName;
            IntPtr num  = IntPtr.Zero;

            try
            {
                num = InteropWindow.BringWindowToFront(name, false, false);
            }
            catch (Exception ex)
            {
                Logger.Error("Exception in bringing existing frontend window for VM {0} to the foreground", (object)(vmname + " Err : " + ex.ToString()));
            }
            return(num);
        }
Esempio n. 14
0
 private void SetTopmostState(bool isTop)
 {
     try
     {
         if (this.mParentWindow != null && !isTop && InteropWindow.GetTopmostOwnerWindow(this.mParentWindow).Topmost)
         {
             isTop = true;
         }
         if (this.mAppliedTopMost.HasValue)
         {
             bool?mAppliedTopMost = this.mAppliedTopMost;
             bool flag            = isTop;
             if (mAppliedTopMost.GetValueOrDefault() == flag & mAppliedTopMost.HasValue)
             {
                 return;
             }
         }
         if (this.Child == null || !(PresentationSource.FromVisual((Visual)this.Child) is HwndSource hwndSource))
         {
             return;
         }
         IntPtr handle = hwndSource.Handle;
         RECT   lpRect;
         if (!NativeMethods.GetWindowRect(handle, out lpRect))
         {
             return;
         }
         Logger.Debug("setting z-order " + isTop.ToString());
         if (isTop)
         {
             NativeMethods.SetWindowPos(handle, CustomPopUp.HWND_TOPMOST, lpRect.Left, lpRect.Top, (int)this.Width, (int)this.Height, 1563U);
         }
         else
         {
             NativeMethods.SetWindowPos(handle, CustomPopUp.HWND_BOTTOM, lpRect.Left, lpRect.Top, (int)this.Width, (int)this.Height, 1563U);
             NativeMethods.SetWindowPos(handle, CustomPopUp.HWND_TOP, lpRect.Left, lpRect.Top, (int)this.Width, (int)this.Height, 1563U);
             NativeMethods.SetWindowPos(handle, CustomPopUp.HWND_NOTOPMOST, lpRect.Left, lpRect.Top, (int)this.Width, (int)this.Height, 1563U);
         }
         this.mAppliedTopMost = new bool?(isTop);
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in set topmost state in custom popup: {0}", (object)ex);
     }
 }
Esempio n. 15
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     InteropWindow.RemoveWindowFromAltTabUI(new WindowInteropHelper((Window)this).Handle);
     if (!this.IsInOverlayMode)
     {
         this.ShowSideBarWindow();
     }
     else
     {
         this.Handle = new WindowInteropHelper((Window)this).Handle;
         InteropWindow.SetWindowLong(this.Handle, -16, 1207959552);
         this.ParentWindow.mFrontendHandler.UpdateOverlaySizeStatus();
         this.ParentWindow.LocationChanged += new EventHandler(this.ParentWindow_LocationChanged);
         this.ParentWindow.Activated       += new EventHandler(this.ParentWindow_Activated);
         this.ParentWindow.Deactivated     += new EventHandler(this.ParentWindow_Deactivated);
         this.UpdateSize();
     }
     this.Init();
 }
Esempio n. 16
0
 private void CustomPopUp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     if (!this.IsFocusOnMouseClick)
     {
         return;
     }
     try
     {
         if (!(PresentationSource.FromVisual((Visual)this.Child) is HwndSource hwndSource))
         {
             return;
         }
         InteropWindow.SetForegroundWindow(hwndSource.Handle);
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in setting popup as foreground window: {0}", (object)ex);
     }
 }
Esempio n. 17
0
 public static void NotifyExeCrashToParentWindow(string className, string windowName)
 {
     Logger.Info("Sending WM_USER_EXE_CRASHED message to class = {0}, window = {1}", (object)className, (object)windowName);
     try
     {
         IntPtr window = InteropWindow.FindWindow(className, windowName);
         if (window == IntPtr.Zero)
         {
             Logger.Info("Unable to find window : {0}", (object)className);
         }
         else
         {
             InteropWindow.SendMessage(window, 1035U, IntPtr.Zero, IntPtr.Zero);
         }
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format("Error Occured, Err: {0}", (object)ex.ToString()));
     }
 }
Esempio n. 18
0
 public static void NotifyAppCrashToParentWindow(string className, string windowName, int vmId)
 {
     Logger.Info("Sending WM_USER_APP_CRASHED message to class = {0}, window = {1}", (object)className, (object)windowName);
     try
     {
         IntPtr window = InteropWindow.FindWindow(className, windowName);
         if (window == IntPtr.Zero)
         {
             Logger.Info("Unable to find window : {0}", (object)className);
         }
         else
         {
             uint num = (uint)vmId;
             InteropWindow.SendMessage(window, 1034U, IntPtr.Zero, (IntPtr)(long)num);
         }
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format("Error Occured, Err: {0}", (object)ex.ToString()));
     }
 }
Esempio n. 19
0
        public static bool DoRunCmd(string request, string vmName)
        {
            bool flag = false;

            if (VmCmdHandler.RunCommand(request, vmName, "bgp") == "ok")
            {
                flag = true;
                if (request.Contains("mpi.v23"))
                {
                    Logger.Info("starting amidebug. not sending message to frontend.");
                    return(flag);
                }
                IntPtr window = InteropWindow.FindWindow((string)null, BlueStacks.Common.Strings.AppTitle);
                if (window != IntPtr.Zero)
                {
                    Logger.Info("Sending WM_USER_SHOW_WINDOW to Frontend Handle {0}", (object)window);
                    InteropWindow.SendMessage(window, 1025U, IntPtr.Zero, IntPtr.Zero);
                }
            }
            string appName      = "";
            string packageName  = "";
            string activityName = "";
            string imageName    = "";
            string appstore     = "";

            if (request.StartsWith("runex"))
            {
                string str = new Regex("^runex\\s+").Replace(request, "");
                packageName = str.Substring(0, str.IndexOf('/'));
                if (!new JsonParser(vmName).GetAppInfoFromPackageName(packageName, out appName, out imageName, out activityName, out appstore))
                {
                    Logger.Error("Failed to get App info for: {0}. Not adding in launcher dock.", (object)packageName);
                    return(flag);
                }
            }
            HDAgent.GetVersionFromPackage(packageName, vmName);
            string str1 = RegistryStrings.GadgetDir + imageName;

            return(flag);
        }
Esempio n. 20
0
 internal void UpdateSize()
 {
     if (!(this.ParentWindow.StaticComponents.mLastMappableWindowHandle != IntPtr.Zero) || this.mIsClosing)
     {
         return;
     }
     if (this.mIsShowWindow)
     {
         this.mIsShowWindow = false;
         Logger.Debug("KMP KeymapCanvasWindow UpdateSize");
         this.ParentWindow.mFrontendHandler.DeactivateFrontend();
         this.Show();
     }
     else
     {
         RECT rect = new RECT();
         InteropWindow.GetWindowRect(this.ParentWindow.StaticComponents.mLastMappableWindowHandle, ref rect);
         InteropWindow.SetWindowPos(this.Handle, (IntPtr)0, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, 16448U);
         this.ParentWindow.mFrontendHandler.FocusFrontend();
         this.SetOnboardingControlPosition(0.0, 0.0);
     }
 }
        internal void ResizeWindow()
        {
            Rectangle windowRectangle = this.GetWindowRectangle();

            if (this.ParentWindow.mStreamingModeEnabled)
            {
                InteropWindow.ShowWindow(this.mFrontendHandle, 5);
            }
            else
            {
                InteropWindow.SetWindowPos(this.mFrontendHandle, (IntPtr)0, windowRectangle.X, windowRectangle.Y, windowRectangle.Width, windowRectangle.Height, 16448U);
            }
            if (KMManager.dictOverlayWindow.ContainsKey(this.ParentWindow))
            {
                if (this.ParentWindow.StaticComponents.mLastMappableWindowHandle == IntPtr.Zero)
                {
                    this.ParentWindow.StaticComponents.mLastMappableWindowHandle = this.mFrontendHandle;
                }
                KMManager.dictOverlayWindow[this.ParentWindow].UpdateSize();
            }
            this.FocusFrontend();
            RegistryManager.Instance.FrontendHeight = windowRectangle.Height;
            RegistryManager.Instance.FrontendWidth  = windowRectangle.Width;
        }
Esempio n. 22
0
        internal bool GoToTab(string key, bool isLaunch = true, bool receivedFromImap = false)
        {
            Logger.Info("Test logs: GoToTab() key: " + key + ", isPresentInmDict: " + this.mDictTabs.ContainsKey(key).ToString());
            bool flag = false;

            if (InteropWindow.GetForegroundWindow() != this.ParentWindow.Handle)
            {
                this.ParentWindow.mIsFocusComeFromImap = true;
            }
            if (this.mDictTabs.ContainsKey(key))
            {
                if (Oem.IsOEMDmm && this.ParentWindow.mFrontendGrid.Visibility != Visibility.Visible)
                {
                    this.ParentWindow.mFrontendGrid.Visibility       = Visibility.Visible;
                    this.ParentWindow.mDmmProgressControl.Visibility = Visibility.Hidden;
                }
                AppTabButton mDictTab = this.mDictTabs[key];
                if (!mDictTab.IsSelected)
                {
                    mDictTab.IsLaunchOnSelection          = isLaunch;
                    mDictTab.mIsAnyOperationPendingForTab = KMManager.sGuidanceWindow != null && GuidanceWindow.sIsDirty;
                    mDictTab.Select(true, receivedFromImap);
                    flag = true;
                    EventHandler <TabChangeEventArgs> eventOnTabChanged = mDictTab.EventOnTabChanged;
                    if (eventOnTabChanged != null)
                    {
                        eventOnTabChanged((object)null, new TabChangeEventArgs(mDictTab.AppName, mDictTab.PackageName, mDictTab.mTabType));
                    }
                }
                else
                {
                    flag = true;
                }
            }
            return(flag);
        }
Esempio n. 23
0
        public static bool IsSubWindowVisible()
        {
            IntPtr subWindow = Opengl.GetSubWindow();

            return(!(subWindow == IntPtr.Zero) && InteropWindow.IsWindowVisible(subWindow));
        }
 internal void ShowGLWindow()
 {
     if (this.CanfrontendBeResizedAndFocused())
     {
         this.ResizeWindow();
     }
     else if (this.ParentWindow.mFrontendGrid.IsVisible)
     {
         if (this.ParentWindow.Handle.ToString().Equals("0", StringComparison.OrdinalIgnoreCase))
         {
             return;
         }
         this.sIsfrontendAlreadyVisible = true;
         if (this.mFrontendHandle == IntPtr.Zero)
         {
             ThreadPool.QueueUserWorkItem((WaitCallback)(obj =>
             {
                 try
                 {
                     this.ParentWindow.Dispatcher.Invoke((Delegate)(() =>
                     {
                         Rectangle windowRectangle = this.GetWindowRectangle();
                         Dictionary <string, string> dict = new Dictionary <string, string>()
                         {
                             {
                                 "ParentHandle",
                                 !this.ParentWindow.mStreamingModeEnabled ? this.ParentWindow.Handle.ToString() : "0"
                             },
                             {
                                 "X",
                                 windowRectangle.X.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                             },
                             {
                                 "Y",
                                 windowRectangle.Y.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                             },
                             {
                                 "Width",
                                 windowRectangle.Width.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                             },
                             {
                                 "Height",
                                 windowRectangle.Height.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                             },
                             {
                                 "isMute",
                                 this.ParentWindow.IsMuted.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                             }
                         };
                         if (windowRectangle.Width == 0 || windowRectangle.Height == 0)
                         {
                             this.sIsfrontendAlreadyVisible = false;
                         }
                         else
                         {
                             ThreadPool.QueueUserWorkItem((WaitCallback)(obj1 =>
                             {
                                 try
                                 {
                                     lock (this.mLockObject)
                                     {
                                         if (!(this.mFrontendHandle == IntPtr.Zero))
                                         {
                                             return;
                                         }
                                         JObject jobject = JObject.Parse(JArray.Parse(this.SendFrontendRequest("setParent", dict))[0].ToString());
                                         if (jobject["success"].ToObject <bool>())
                                         {
                                             this.mFrontendHandle = new IntPtr(jobject["frontendhandle"].ToObject <int>());
                                         }
                                         System.Action <MainWindow> reparentingCompletedAction = this.ReparentingCompletedAction;
                                         if (reparentingCompletedAction != null)
                                         {
                                             reparentingCompletedAction(this.ParentWindow);
                                         }
                                         Logger.Debug("Set parent call completed. handle: " + this.mFrontendHandle.ToString());
                                     }
                                 }
                                 catch (Exception ex)
                                 {
                                     Logger.Error("Failed to send Show event to engine... err : " + ex.ToString());
                                 }
                             }));
                         }
                     }));
                 }
                 catch (Exception ex)
                 {
                     Logger.Error("Failed to send Show event to engine... err : " + ex.ToString());
                 }
             }));
         }
         else
         {
             this.ResizeWindow();
         }
     }
     else
     {
         this.sIsfrontendAlreadyVisible = false;
         if (!(this.mFrontendHandle != IntPtr.Zero))
         {
             return;
         }
         InteropWindow.ShowWindow(this.mFrontendHandle, 0);
         if (!KMManager.dictOverlayWindow.ContainsKey(this.ParentWindow) || this.ParentWindow.WindowState == WindowState.Maximized)
         {
             return;
         }
         KMManager.ShowOverlayWindow(this.ParentWindow, false, false);
     }
 }
Esempio n. 25
0
 public static bool ResizeSubWindow(int x, int y, int cx, int cy)
 {
     InteropWindow.SetWindowPos(Opengl.GetSubWindow(), IntPtr.Zero, x, y, cx, cy, 16468U);
     return(true);
 }
        internal void ChangeFrontendToPortraitMode()
        {
            Rectangle windowRectangle = this.GetWindowRectangle();

            InteropWindow.SetWindowPos(this.mFrontendHandle, (IntPtr)0, windowRectangle.X, windowRectangle.Y, windowRectangle.Width, windowRectangle.Height, 16448U);
        }
Esempio n. 27
0
        /// <summary>
        ///     Helper method which will retrieve the IHTMLDocument2 for the supplied window,
        ///     or return the first if none is supplied.
        /// </summary>
        /// <param name="browserWindow">The InteropWindow to get the IHTMLDocument2 for</param>
        /// <returns>DocumentContainer</returns>
        private static DocumentContainer CreateDocumentContainer(IInteropWindow browserWindow)
        {
            DocumentContainer returnDocumentContainer = null;
            InteropWindow     returnWindow            = null;
            IHTMLDocument2    returnDocument2         = null;
            // alternative if no match
            InteropWindow  alternativeReturnWindow    = null;
            IHTMLDocument2 alternativeReturnDocument2 = null;

            // Find the IE windows
            foreach (var ieWindow in GetIeWindows())
            {
                Log.Debug().WriteLine("Processing {0} - {1}", ieWindow.Classname, ieWindow.Text);

                Accessible ieAccessible = null;
                var        directUiwd   = IEHelper.GetDirectUi(ieWindow);
                if (directUiwd != null)
                {
                    ieAccessible = new Accessible(directUiwd.Handle);
                }
                if (ieAccessible == null)
                {
                    if (browserWindow != null)
                    {
                        Log.Info().WriteLine("Active Window is {0}", browserWindow.Text);
                    }
                    if (!ieWindow.Equals(browserWindow))
                    {
                        Log.Warn().WriteLine("No ieAccessible for {0}", ieWindow.Text);
                        continue;
                    }
                    Log.Debug().WriteLine("No ieAccessible, but the active window is an IE window: {0}, ", ieWindow.Text);
                }

                try
                {
                    // Get the Document
                    var document2 = GetHtmlDocument(ieWindow);
                    if (document2 == null)
                    {
                        continue;
                    }

                    // Get the content window handle for the shellWindow.Document
                    var oleWindow           = (IOleWindow)document2;
                    var contentWindowHandle = IntPtr.Zero;
                    oleWindow?.GetWindow(out contentWindowHandle);

                    if (contentWindowHandle != IntPtr.Zero)
                    {
                        // Get the HTMLDocument to check the hasFocus
                        // See: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/60c6c95d-377c-4bf4-860d-390840fce31c/
                        var document4 = (IHTMLDocument4)document2;

                        if (document4.hasFocus())
                        {
                            Log.Debug().WriteLine("Matched focused document: {0}", document2.title);
                            // Look no further, we got what we wanted!
                            returnDocument2 = document2;
                            returnWindow    = InteropWindowFactory.CreateFor(contentWindowHandle);
                            break;
                        }
                        try
                        {
                            if (ieWindow.Equals(browserWindow))
                            {
                                returnDocument2 = document2;
                                returnWindow    = InteropWindowFactory.CreateFor(contentWindowHandle);
                                break;
                            }
                            if (ieAccessible != null && returnWindow == null && document2.title.Equals(ieAccessible.IEActiveTabCaption))
                            {
                                Log.Debug().WriteLine("Title: {0}", document2.title);
                                returnDocument2 = document2;
                                returnWindow    = InteropWindowFactory.CreateFor(contentWindowHandle);
                            }
                            else
                            {
                                alternativeReturnDocument2 = document2;
                                alternativeReturnWindow    = InteropWindowFactory.CreateFor(contentWindowHandle);
                            }
                        }
                        catch (Exception)
                        {
                            alternativeReturnDocument2 = document2;
                            alternativeReturnWindow    = InteropWindowFactory.CreateFor(contentWindowHandle);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error().WriteLine("Major problem: Problem retrieving Document from {0}", ieWindow.Text);
                    Log.Error().WriteLine(e);
                }
            }

            // check if we have something to return
            if (returnWindow != null)
            {
                // As it doesn't have focus, make sure it's active
                returnWindow.Restore();
                returnWindow.GetParent();

                // Create the container
                try
                {
                    returnDocumentContainer = new DocumentContainer(returnDocument2, returnWindow);
                }
                catch (Exception e)
                {
                    Log.Error().WriteLine(null, "Major problem: Problem retrieving Document.");
                    Log.Error().WriteLine(e);
                }
            }

            if (returnDocumentContainer == null && alternativeReturnDocument2 != null)
            {
                // As it doesn't have focus, make sure it's active
                alternativeReturnWindow.Restore();
                alternativeReturnWindow.GetParent();
                // Create the container
                try
                {
                    returnDocumentContainer = new DocumentContainer(alternativeReturnDocument2, alternativeReturnWindow);
                }
                catch (Exception e)
                {
                    Log.Error().WriteLine(null, "Major problem: Problem retrieving Document.");
                    Log.Error().WriteLine(e);
                }
            }
            return(returnDocumentContainer);
        }