SetParent 你的外部程序窗体的句柄, Me.hwnd
解决方案 »
- vb6.0怎么修改access数据库中指定位置的数据?
- 关于richtextbox中的rtf格式文本
- 如何以administrator身份加载程序?
- 自己new出来的那个没界面的webbrowser,能用navigate吗?
- 请告诉我<<Visual Basic 6.0 插件开发人员指南>>电子书的下载地址
- 关于TDBGrid控件的属性(3).在线等,一个问题100分.马上结帐?
- ime function
- 请高工帮忙,关于SONY EVI-D70摄像头的控制码
- vb中如何加载3d控件
- excel vba基础教程
- vb中出现 在加载某窗口时,出现 OUT OF MEMORY,在关闭程序时出现提示:
- win98(fat32)下做的程序,在NT4.0(fat16)下面能用吗?
For Each ctl In Me.Controls
Debug.Print ctl.Name
Debug.Print TypeName(ctl)
Next
lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, _
ByVal lpWindowName As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As LongPrivate OldParent&
Private Hwnd1&Private Sub Form_Load()
Drive1.Drive = App.Path
Dir1.Path = App.Path
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Command1_Click() '调用程序为本程序子窗口
Dim myexe As Long
Dim newhwnd As Long
Dim newexe As Long
Dim myvalue As Long myexe = Shell(File1.Path & "\" & File1.FileName, vbNormalFocus) '调用程序
If myexe = 0 Then
MsgBox ""
Exit Sub
End If
newhwnd = FindWindow(ByVal 0&, ByVal 0&) '获取windows句柄
Do While newhwnd <> 0
If GetParent(newhwnd) = 0 Then
myvalue = GetWindowThreadProcessId(newhwnd, newexe) '获取窗口的进程
If newexe = myexe Then
Hwnd1& = newhwnd
Exit Do
End If
End If
newhwnd = GetWindow(newhwnd, GW_HWNDNEXT) '获取窗口值
Loop
OldParent& = SetParent(Hwnd1&, Me.Hwnd) '指定本程序为打开程序的父窗口
End SubPrivate Sub Command2_Click() '释放程序
SetParent Hwnd1&, OldParent&
End SubPrivate Sub Command3_Click()
End
End Sub
Call EnumChildWindows(这里是外部程序窗体的句柄, AddressOf EnumChildProc, &H0)End Sub'module code
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, _
ByVal lParam As Long) As Long
'working vars
Dim sTitle As String
Dim sClass As String
Dim sIDType As String
Dim itmX As ListItem 'get the window title / class name
sTitle = GetWindowIdentification(hwnd, sIDType, sClass)
'这里显示出所有的控件名,类型,caption
Debug.Print sTitle
Debug.Print sIDType
Debug.Print sClass
Debug.Print " "
EnumChildProc = 1
End Function
Private Function GetWindowIdentification(ByVal hwnd As Long, _
sIDType As String, _
sClass As String) As String Dim nSize As Long
Dim sTitle As String 'get the size of the string required
'to hold the window title
nSize = GetWindowTextLength(hwnd)
'if the return is 0, there is no title
If nSize > 0 Then
sTitle = Space$(nSize + 1)
Call GetWindowText(hwnd, sTitle, nSize + 1)
sIDType = "title"
sClass = Space$(64)
Call GetClassName(hwnd, sClass, 64)
Else
'no title, so get the class name instead
sTitle = Space$(64)
Call GetClassName(hwnd, sTitle, 64)
sClass = sTitle
sIDType = "class"
End If
GetWindowIdentification = TrimNull(sTitle)End FunctionPrivate Function TrimNull(startstr As String) As String Dim pos As Integer pos = InStr(startstr, Chr$(0))
If pos Then
TrimNull = Left$(startstr, pos - 1)
Exit Function
End If
'if this far, there was
'no Chr$(0), so return the string
TrimNull = startstr
End Function