如何利用API将MATLAB的DLL生成的窗体嵌入VB窗体中??
如何利用API将MATLAB的DLL生成的窗体嵌入VB窗体中?? 思路:1、使用FindWindow查找Matlab生成的窗体
2、使用SetParent将该窗体设置为VB程序窗体的子窗体即可。
举个例子,假如:Windows自带的计算器窗口是Matlab生成的窗体,按如下代码处理:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
Dim lngChildHwnd As Long
Dim lngP As Long
lngChildHwnd = FindWindow(vbNullString, "¼ÆËãÆ÷")
lngP = SetParent(lngChildHwnd, Me.hWnd)
End Sub
Private Sub Form_Load()
Shell "c:\windows\system32\calc.exe", vbNormalFocus
Me.WindowState = 2
End Sub
你好 如果在vb.net中能不能把lngP = SetParent(lngChildHwnd, Me.hWnd)中Me.hWnd换成TabControl控件 Public Excel As Excel.Application = Nothing
Public Workbook As Microsoft.Office.Interop.Excel.Workbook
Public Worksheet As Microsoft.Office.Interop.Excel.Worksheet
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Int32, ByVal hWndNewParent As Int32) As Int32
Excel = New Excel.Application
Dim ExcelWnd As Integer = Excel.Hwnd
SetParent(ExcelWnd, Me.TabPage4.Handle)
Excel.Visible = True
Excel.WindowState = XlWindowState.xlMaximized
补充:VB , 基础类