Help Embeding snes9x with a panel in VB.net

This is for people involved in the developement of Snes9x, or SNES emulators in general.
BUG REPORTS BELONG IN TECH SUPPORT/BUG TRACKING!
Post Reply
blitza700
Snes9x White Belt
Posts: 2
Joined: Thu Oct 26, 2017 9:57 am

Help Embeding snes9x with a panel in VB.net

Post by blitza700 »

Hi every one Noob here I have set up a computer to run a couple of games but I want to have like my own front end for it where it nests buttons to launch each game by terminating snes9x and then relaunching but with the game in a panel on a vb form.

The only thing I am having trouble with is nesting the snes9x window into the panel and I feel i'm missing something very simple I have gotten the kill and launch working but not the nesting any one got any surjections or snippets of code that I could try?

Sorry the code is messy but the button2_click works and with button1_click is where I have been trying different bits of coding that I have found round the internet (well pretty much all of it is snippets from the internet)

Code: Select all

Public Class Form1
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZED As Integer = 61488
    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

    Public Sub KillProcess(ByVal processName As String)

        On Error GoTo ErrHandler

        Dim oWMI
        Dim ret
        Dim sService
        Dim oWMIServices
        Dim oWMIService
        Dim oServices
        Dim oService
        Dim servicename

        oWMI = GetObject("winmgmts:")
        oServices = oWMI.InstancesOf("win32_process")

        For Each oService In oServices

            servicename = LCase(Trim(CStr(oService.Name) & ""))

            If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
                ret = oService.Terminate
            End If

        Next

        oServices = Nothing
        oWMI = Nothing

ErrHandler:
        Err.Clear()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        KillProcess("snes9x")
        Dim proc As System.Diagnostics.Process
        proc = Process.Start("C:\Users\SNES_Machine_002\Desktop\Aero the Acro-Bat (USA).sfc")
        proc.WaitForInputIdle()
        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)

    End Sub

    Private Sub Button2_click(sender As Object, e As EventArgs) Handles Button2.Click
        KillProcess("snes9x")
        Process.Start("C:\Users\SNES_Machine_002\Desktop\Aladdin (U) [!].smc")
    End Sub
End Class
blitza700
Snes9x White Belt
Posts: 2
Joined: Thu Oct 26, 2017 9:57 am

Re: Help Embeding snes9x with a panel in VB.net

Post by blitza700 »

Ok just a quick update to where I am.

I have Downloaded the source code and I'm going to try and figure out which code I will need to call to render the screen and to load roms but if any one has any knowledge on all of this then please let me know as anything will be a great help.
Post Reply