public GameInfo GameSetFocus(String gameInterested) { GameInfo gameResult = null; do { if (String.IsNullOrEmpty(gameInterested)) { gameResult = null; break; } gameResult = new GameInfo(gameInterested); if (this.gameProcess == null || this.gameProcess.HasExited) { gameResult = null; break; } //Get the handle to the top child window of the game process this.topWindowHandle = GetTopWindow(this.gameProcess.MainWindowHandle); //if the parent window doesnt have any child window if (topWindowHandle == IntPtr.Zero) { topWindowHandle = this.gameProcess.MainWindowHandle; } //set the game name gameResult.SetGameName(gameInterested); //set the game handle gameResult.SetGameHandle(topWindowHandle); //Enable the window to take keyboard or mouse input in case it was disabled bool setWindow = EnableWindow(topWindowHandle, true); //Bring the Mario window to front setWindow = BringWindowToTop(topWindowHandle); //Sleep for the operation to take place System.Threading.Thread.Sleep(sleepTime); if (!setWindow) { gameResult = null; break; } //Set the mario to be the foreground window setWindow = SetForegroundWindow(topWindowHandle); //Sleep for the operation to successfully be completed System.Threading.Thread.Sleep(sleepTime); if (!setWindow) { gameResult = null; break; } } while (false); return gameResult; }