Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi :)

I'm creating a kind of virtualbox (I'm just trying to learn with mini-projects and stuff). I've found a way to open applications within the dimensions of the windows form. So once I thought I had found a solution for this, I began testing it on different applications; it works with notepad, firefox, etc (they all open within the form itself). However, I tried it on a video game (RuneScape [don't judge lel]) and only the splash screen opened in the form. Once the splash screen had loaded the game's resourced, and the main client/game process started, the client opened outside of the box. In the task manager, it seems like the launcher and the client process rely on one another (i.e. if I kill rs2client.exe and leave runescape.exe running, both kill themselves and the game dies - and vice versa). How do I make it so that the window (main game client) that opens after the splash screen remains inside the form, just as the splash screen did?

This is my current code:
VB
Option Strict On
Option Explicit On
Public Class Form1
    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Dim proc As Process
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        proc = Process.Start("C:\Program Files\Jagex\RuneScape Launcher\runescape.exe")
        proc.WaitForInputIdle()
        proc.WaitForExit(1000)
        SetParent(proc.MainWindowHandle, Panel1.Handle)
    End Sub
End Class


What I have tried:

I've tried this (probably a very ill attempt for a solution):
VB
Option Strict On
Option Explicit On
Public Class Form1
    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Dim proc As Process
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        proc = Process.Start("C:\Program Files\Jagex\RuneScape Launcher\runescape.exe")
        proc.WaitForInputIdle()
        proc.WaitForExit(1000)
        SetParent(proc.MainWindowHandle, Panel1.Handle)
        proc = Process.Start("C:\ProgramData\Jagex\Launcher\rs2client.exe")
        proc.WaitForInputIdle()
        proc.WaitForExit(1000)
        SetParent(proc.MainWindowHandle, Panel1.Handle)
    End Sub
End Class


Thanks so much for any help! If you give a really complicated answer, that I don't know how to actually implement, be prepared to endure my inexperience (I'm trying to learn xD)!
Posted
Updated 22-Oct-17 14:27pm

1 solution

The problem is not your code, but the game you're trying to put in your window.

Most games run, by default, in "fullscreen". Meaning they don't draw to a window but draw directly to the screen. There is no window to "put in your window".

The game has to support "windowed" mode. If it doesn't, you're not going to get this to work. One the game is drawing to a window, you can then get the window handle and set the parent to your window.
 
Share this answer
 
Comments
[no name] 22-Oct-17 20:50pm    
Hi Dave,

Thanks for your imput! I should have clarified to avoid any confusion, the game is not available in full screen - it's a normal windowed form. The problem is, if I specify the start of the Game Launcher itself, I only get the splash screen to display in the panel; I need the resulting windows (the main client) to display.

Thanks for any help you can give! I've been struggling with this problem for a couple of days, I've tried threading, timers, etc. I'm just not very good with the language yet.

I look forward to hearing back! :)
Dave Kreskowiak 22-Oct-17 22:33pm    
OK, so you're going to have to get the window handle of the game window. It would appear that it's not the same window as the splash-screen.

There is no "one size fits all" method of doing this that's going to work for every application and game.

I don't know if your version of Visual Studio has the SPY++ tool, but you can use that to examine all of the properties of the game window to find if there's anything you can use to "search" for the window when your app runs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900