Jump to content

Recommended Posts

Posted

boas pessoal queria saber se é possível abrir um exe externo dentro de um form.

não estou a falar de Shell("etc") nem de process.start("etc")

estou a falar num form com um exe externo aberto dentro.

tipo o webbrowser só que em vez de ser um url ser um programa.

obrigado a todos que me possam ajudar.

Posted

é simples amigo o exe vai abrir um jogo.

e no form eu queira por botões que interagissem com o jogo.

o jogo ficava tipo touchscreen.

mas o que acontece ´quando eu clico num botao do form o jogo perde focus e minimiza.

eu tenho uma versão trial do que eu quero fazer mas é em delphi e é trial.

queria fazer em vb.net

Posted (edited)
Imports

System.Runtime.InteropServices
Public

Class Form1
<DllImport(
"User32", CharSet:=CharSet.Auto, ExactSpelling:=True)> Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr

End Function

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim PROCHANDLE As System.IntPtr = -1

For Each proc In Process.GetProcesses

If LCase(proc.ProcessName) = "notepad" Then
PROCHANDLE = proc.Handle

End If

Next

If PROCHANDLE = -1 Then
PROCHANDLE = Process.Start(
"C:\windows\notepad.exe").Handle
SetParent(PROCHANDLE,
Me.Handle)

End If

End Sub
End Class

eu estou a usar este código mas quando eu carrego no form o wordpad minimiza. eu queria que ele fixasse dentro do form mesmo que eu carregasse no form.

Edited by thoga31
GeSHi
Posted

Primeiro link da referência do google que te dei:

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
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim proc As Process
       proc = Process.Start("C:\WINDOWS\notepad.exe")
       proc.WaitForInputIdle()
       SetParent(proc.MainWindowHandle, Me.Handle)
       SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
       Me.BringToFront()
   End Sub
End Class

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.