2010年7月28日 星期三

外部程序如何嵌套到窗体上

原出處

' API声明
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer


' 调用
Dim ptrHandle As IntPtr ' 外部程序的句柄
Dim intLeft As Integer, intTop As Integer ' 外部程序在窗体内的位置
Dim intWidth As Integer, intHeight As Integer ' 外部程序在窗体内的大小

' 获取外部程序的句柄
ptrHandle = FindWindow(vbNullString, "Adobe photoshop") ' 引号中是外部程序的标题名
' 嵌入当前窗体
SetParent(ptrHandle, Me.Handle)
' 设置外部程序在窗体内的位置和大小(省略)

' 移动到指定的位置
MoveWindow(ptrHandle.ToInt32, intLeft, intTop, intWidth, intHeight, 1)

沒有留言:

張貼留言