PDA

View Full Version : اجرای یه فایل exe به صورت mdi در برنامه



Reza Safa
سه شنبه 25 دی 1386, 11:00 صبح
سلام دوستان من میخوام یک فایل exe در برنامه خودم
به صورت child در برنامه ام اجرا کنم
می خوام بونم چه طور میشه ایکارو کرد

اگه راه حل داره
کد مورد نظر رو هم قرار دهید تا هم من و دیگران استفا ده کنیم


من یک میزکار طراحی کردم که میز کارم مثل میز کار windows به صورت mdi است
فایل exe باید در فرم mdi بالا بیاد

Reza Safa
سه شنبه 25 دی 1386, 16:02 عصر
لطفا کمک کنید. خیلی لازمه

amirsajjadi
چهارشنبه 26 دی 1386, 13:24 عصر
با سلام



Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Integer, ByVal lpWindowName As Integer) As Integer
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Integer
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Integer) As Integer
Private Declare Function GetDesktopWindow Lib "user32" () As Integer
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Integer) AsInteger
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Integer, ByVal uExitCode As Integer) As Integer
Private Declare Function GetCurrentProcess Lib "kernel32" () As Integer
Private Declare Function Putfocus Lib"user32" Alias "SetFocus" (ByVal hwnd As Integer) As Integer
Const GW_HWNDNEXT = 2
Dim mWnd As Integer
Function InstanceToWnd(ByVal target_pid As Integer) As Integer
Dim test_hwnd As Integer, test_pid As Integer, test_thread_id As Integer
'Find the first window
test_hwnd = FindWindow(0, 0)
Do While test_hwnd <> 0
'Check if the window isn't achild
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Private SubForm1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
'Unload notepad
DestroyWindow(mWnd)
'End this program
TerminateProcess(GetCurrentProcess, 0)
End Sub
Private SubForm1_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Me.Load
Dim Pid As Integer
'Lock the window update
LockWindowUpdate(GetDesktopWindow)
'Execute notepad.Exe
Pid = Shell("notepad.exe", vbNormalFocus)
If Pid = 0 ThenMsgBox("Error starting the app")
'retrieve the handle of thewindow
mWnd = InstanceToWnd(Pid)
'Set the notepad's parent
SetParent(mWnd, Me.Handle.ToInt32)
'Put the focus on notepad
Putfocus(mWnd)
'Unlock windowupdate
LockWindowUpdate(False)
End Sub

Reza Safa
پنج شنبه 27 دی 1386, 06:40 صبح
ممنون از این که کمکم کردی
دوست عزیز درست عمل می کند اما وقتی MInmaize میکنم برنامه مورد نظر notepadبسنه می شود

amirsajjadi
پنج شنبه 27 دی 1386, 09:42 صبح
دوست من اگه برنامت میخواد مثل Desktop عمل کنه باید مثل دسکتاپ هم هیچ کدوم از عملیات Minimize ، Close ، Maximize رو نداشته باشه چون روی دسکتاپ هیچ وقت نمیتونید این سه عمل رو انجام بدید