Option Explicit
Private Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32 " (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32 " (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32 " (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32 " (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32 " (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32 " () As Long
Private Declare Function DestroyWindow Lib "user32 " (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32 " (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32 " () As Long
Private Declare Function Putfocus Lib "user32 " Alias "SetFocus " (ByVal hwnd As Long) As Long
Const GW_HWNDNEXT = 2
Dim mWnd As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn 't a child
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 FunctionPrivate Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Pid As Long
'Lock the window update
LockWindowUpdate GetDesktopWindow
'Execute notepad.Exe
Pid = Shell("c:\windows\notepad.exe ", vbNormalFocus)
If Pid = 0 Then MsgBox "Error starting the app "
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
'Set the notepad 's parent
SetParent mWnd, Me.hwnd
'Put the focus on notepad
Putfocus mWnd
'Unlock windowupdate
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
DestroyWindow mWnd
'End this program
TerminateProcess GetCurrentProcess, 0
End Sub
在论坛考得总提示 找不到dll入口
Private Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32 " (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32 " (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32 " (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32 " (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32 " (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32 " () As Long
Private Declare Function DestroyWindow Lib "user32 " (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32 " (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32 " () As Long
Private Declare Function Putfocus Lib "user32 " Alias "SetFocus " (ByVal hwnd As Long) As Long
Const GW_HWNDNEXT = 2
Dim mWnd As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn 't a child
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 FunctionPrivate Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Pid As Long
'Lock the window update
LockWindowUpdate GetDesktopWindow
'Execute notepad.Exe
Pid = Shell("c:\windows\notepad.exe ", vbNormalFocus)
If Pid = 0 Then MsgBox "Error starting the app "
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
'Set the notepad 's parent
SetParent mWnd, Me.hwnd
'Put the focus on notepad
Putfocus mWnd
'Unlock windowupdate
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
DestroyWindow mWnd
'End this program
TerminateProcess GetCurrentProcess, 0
End Sub
在论坛考得总提示 找不到dll入口
解决方案 »
- 查询的问题?
- System Error &H8007007E(-21470247707)是什么意思?
- 急!我把所有的拿出来!求解!
- 打卡机与数据库连接的接口程序?
- 请教:如何将treeview的所有节点保存到一个xml文件?
- 请高手帮忙,在线揭贴:修改第n1,n2列值时,第n3,n4列值分别为第n1、n2列值的3倍,然后,第ni列的值为n1+n2。怎么写??(datagrid是和
- 请问有没有类似ListView的控件,但是内容可以马上修改(象Excel)
- VB如何调用VC开发的DLL,请大虾看小弟的做法,并请教,参与有分
- dialog窗口用dialog.show 1是打开的意思,对吗?dialog.hide是隐藏?请问如何退出?而不是隐藏?
- ACCESS制作安装盘的问题!
- 如何整个这样的菜单(有图)
- 关于工资管理系统中自定义公式的实现方法
就这里总提示 找不到dll入口
你传的全是0,还查什么查?