From 045448675e8af9df0c4866a9cab85eea49eb7be9 Mon Sep 17 00:00:00 2001 From: uberhalit Date: Sat, 25 Feb 2017 17:04:47 +0100 Subject: [PATCH] Fixed "Could not get mainControlHandle" for some custom builds --- CitraTouchControl/MainWindow.xaml.cs | 82 ++++++++++++---------------- CitraTouchControl/MenuWindow.xaml.cs | 6 +- README.md | 2 +- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/CitraTouchControl/MainWindow.xaml.cs b/CitraTouchControl/MainWindow.xaml.cs index 8f30d7d..1b78fbf 100644 --- a/CitraTouchControl/MainWindow.xaml.cs +++ b/CitraTouchControl/MainWindow.xaml.cs @@ -240,13 +240,17 @@ private IntPtr GetKeyFromControl(string controlName) if (citraMainControlHwnd == IntPtr.Zero) { citraMainControlHwnd = FindWindowEx(citraHwnd, IntPtr.Zero, "Qt5QWindowIcon", "centralwidgetWindow"); - //citraMainControlHwnd = FindChildWindow(windowHandle, "Qt5QWindowIcon", "centralwidgetWindow"); - //citraMainControlHwnd = FindChildWindow(windowHandle, "Qt5QWindowIcon", "GRenderWindowClassWindow"); - //citraMainControlHwnd = FindChildWindow(windowHandle, "Qt5QWindowOwnDCIcon", null); + //citraMainControlHwnd = FindChildWindow(citraHwnd, IntPtr.Zero, "Qt5QWindowIcon", "centralwidgetWindow"); + //citraMainControlHwnd = FindChildWindow(citraHwnd, IntPtr.Zero, "Qt5QWindowIcon", "GRenderWindowClassWindow"); if (citraMainControlHwnd == IntPtr.Zero) { - MessageBox.Show(this, "ERROR: Could not get mainControlHandle!\nPlease try to restart Citra and this application.", "CitraTouchControl"); - return key; + citraMainControlHwnd = FindChildWindow(citraHwnd, IntPtr.Zero, "Qt5QWindowOwnDCIcon", null); + //citraMainControlHwnd = FindChildWindow(citraHwnd, IntPtr.Zero, "Qt5QWindowOwnDCIcon", "Citra"); + if (citraMainControlHwnd == IntPtr.Zero) + { + MessageBox.Show(this,"ERROR: Could not get mainControlHandle!\nPlease try to restart Citra and this application.", "CitraTouchControl"); + return key; + } } } @@ -363,6 +367,33 @@ internal static string GetProcessPath(Process process) return MethodResult; } + /// + /// Uses FindWindowEx() to recursively search for a child window with the given class and/or title, + /// starting after a specified child window. + /// If lpszClass is null, it will match any class name. It's not case-sensitive. + /// If lpszTitle is null, it will match any window title. + /// + public static IntPtr FindChildWindow(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszTitle) + { + // Try to find a match. + IntPtr hwnd = FindWindowEx(hwndParent, IntPtr.Zero, lpszClass, lpszTitle); + if (hwnd == IntPtr.Zero) + { + // Search inside the children. + IntPtr hwndChild = FindWindowEx(hwndParent, IntPtr.Zero, null, null); + while (hwndChild != IntPtr.Zero && hwnd == IntPtr.Zero) + { + hwnd = FindChildWindow(hwndChild, IntPtr.Zero, lpszClass, lpszTitle); + if (hwnd == IntPtr.Zero) + { + // If we didn't find it yet, check the next child. + hwndChild = FindWindowEx(hwndParent, hwndChild, null, null); + } + } + } + return hwnd; + } + #region IMPORTS private const uint WM_KEYDOWN = 0x0100; @@ -407,46 +438,5 @@ private struct RECT } #endregion - - #region UNUSED - - /* - /// - /// Uses FindWindowEx() to recursively search for a child window with the given class and/or title. - /// - public static IntPtr FindChildWindow(IntPtr hwndParent, string lpszClass, string lpszTitle) - { - return FindChildWindow(hwndParent, IntPtr.Zero, lpszClass, lpszTitle); - } - - /// - /// Uses FindWindowEx() to recursively search for a child window with the given class and/or title, - /// starting after a specified child window. - /// If lpszClass is null, it will match any class name. It's not case-sensitive. - /// If lpszTitle is null, it will match any window title. - /// - public static IntPtr FindChildWindow(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszTitle) - { - // Try to find a match. - IntPtr hwnd = FindWindowEx(hwndParent, IntPtr.Zero, lpszClass, lpszTitle); - if (hwnd == IntPtr.Zero) - { - // Search inside the children. - IntPtr hwndChild = FindWindowEx(hwndParent, IntPtr.Zero, null, null); - while (hwndChild != IntPtr.Zero && hwnd == IntPtr.Zero) - { - hwnd = FindChildWindow(hwndChild, IntPtr.Zero, lpszClass, lpszTitle); - if (hwnd == IntPtr.Zero) - { - // If we didn't find it yet, check the next child. - hwndChild = FindWindowEx(hwndParent, hwndChild, null, null); - } - } - } - return hwnd; - } - */ - - #endregion } } diff --git a/CitraTouchControl/MenuWindow.xaml.cs b/CitraTouchControl/MenuWindow.xaml.cs index ed368c5..dfd567e 100644 --- a/CitraTouchControl/MenuWindow.xaml.cs +++ b/CitraTouchControl/MenuWindow.xaml.cs @@ -56,8 +56,7 @@ private void bSave_Click(object sender, RoutedEventArgs e) { if (File.Exists(savePath)) { - var result = MessageBox.Show(this, "WARNING: Do you really wish to overwrite the last savegames?", - "CitraTouchControl", MessageBoxButton.YesNo); + var result = MessageBox.Show(this, "WARNING: Do you really wish to overwrite the last savegames?", "CitraTouchControl", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) return; File.Delete(savePath); @@ -79,8 +78,7 @@ private void bLoad_Click(object sender, RoutedEventArgs e) { if (!File.Exists(savePath)) return; - var result = MessageBox.Show(this, "WARNING: Do you really wish to overwrite the current savegames?", - "CitraTouchControl", MessageBoxButton.YesNo); + var result = MessageBox.Show(this, "WARNING: Do you really wish to overwrite the current savegames?", "CitraTouchControl", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) return; try diff --git a/README.md b/README.md index 2549b04..f1c19bd 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ It further features "savegame/bookmark replacement"; a very basic savestate syst | Platform | App | Working | Information | | ------------- | ------------- | ------------- | ------------- | | Android | [Microsoft Remote Desktop Beta](https://play.google.com/store/apps/details?id=com.microsoft.rdc.android.beta) | **_Yes_** | +| Android | [TeamViewer](https://play.google.com/store/apps/details?id=com.teamviewer.teamviewer.market.mobile) | Yes | annoying swipe gestures, needs portrait (90° rotation) and resolution set on host-pc, distorted sound | | Android | [AccessToGo RDP/Remote Desktop](https://play.google.com/store/apps/details?id=com.ericom.accesstogobyericom) | Yes | buggy, annoying touch-feedback, no network level auth | Android | [Microsoft Remote Desktop](https://play.google.com/store/apps/details?id=com.microsoft.rdc.android) | no | no portrait mode | -| Android | [TeamViewer](https://play.google.com/store/apps/details?id=com.teamviewer.teamviewer.market.mobile) | no | no portrait mode, no scaling, distorted sound | | Android | [RDP Remote Desktop aFreeRDP](https://play.google.com/store/apps/details?id=com.freerdp.afreerdp) | no | no (multi-)touch | | Android | [RDP Remote Desktop Connection](https://play.google.com/store/apps/details?id=com.thinstuff.rdc) | no | no (multi-)touch | | Android | [aRDP Pro: Secure RDP Client](https://play.google.com/store/apps/details?id=com.iiordanov.aRDP) | no | no (multi-)touch |