Snes9x.com
http://www.snes9x.com/phpbb3/

Help Embeding snes9x with a panel in VB.net
http://www.snes9x.com/phpbb3/viewtopic.php?f=8&t=24339
Page 1 of 1

Author:  blitza700 [ Thu Oct 26, 2017 10:10 am ]
Post subject:  Help Embeding snes9x with a panel in VB.net

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:
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

Author:  blitza700 [ Fri Oct 27, 2017 10:55 am ]
Post subject:  Re: Help Embeding snes9x with a panel in VB.net

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/