调用外部程序显示在主窗体中
现在已经能够调用外部程序显示在主窗口中,Dim hwnd As IntPtr
hwnd = GetActiveWindow()
Dim p1 As New Process
p1 = Process.Start("NotePad.exe")
p1.WaitForInputIdle()
SetParent(p1.MainWindowHandle, hwnd)
GetClientRect(hwnd, rect1)
SetWindowPos(p1.MainWindowHandle, 0, 0, 0, rect1.Right - rect1.Left, rect1.Bottom - rect1.Top, SWP_SHOWWINDOW)
ShowWindow(p1.MainWindowHandle, 3)
但是外部程序遮掉了主窗口中的TreeView,MenuStrip,ToolStrip,如何才能把外部程序只显示在空的地方呢? vb.net 外部Exe --------------------编程问答-------------------- 你在你的主窗口的子窗口调用外部程序并显示,同时设置好子窗口的位置大小不就可以吗 --------------------编程问答-------------------- 演示代码
Public Class Form1
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Dim npro As Process = Process.Start("notepad.exe")
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
SetWindowPos(npro.MainWindowHandle.ToInt32, -1, 10, 10, 123, 456, 0)
'MoveWindow(npro.MainWindowHandle.ToInt32, 10, 10, 123, 456, True)
SetParent(npro.MainWindowHandle.ToInt32, Panel1.Handle.ToInt32)
End Sub
End Class
movewindow也可以 --------------------编程问答-------------------- 2楼的代码不起作用哦; --------------------编程问答-------------------- 学习学习,有帮助呀. --------------------编程问答-------------------- 记得有个API是可以的...但是好像不稳定 --------------------编程问答--------------------
窗体上没有Panel哦
补充:.NET技术 , VB.NET