各位大神,我想让窗口嵌入Win7桌面,枚举所有WorkerW找到SHELLDLL_DefView,把父窗口设置为SHELLDLL_DefView
vb.net2015代码如下:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Private Declare Function EnumWindows Lib "user32" Alias "EnumWindows" (ByVal MyCallBack As EnumWindowsProc, ByVal lParam As Integer) As Integer
Private Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
Private Function EnumWindowsProcCallBack(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
If hwnd = FindWindow("WorkerW", vbNullString) Then
If hwnd = FindWindowEx(hwnd, vbNull, "SHELLDLL_DefView", vbNullString) Then
SetParent(Me.Handle, hwnd)
EnumWindowsProcCallBack = False
Else
EnumWindowsProcCallBack = True
End If
Else
EnumWindowsProcCallBack = True
End If
End Function
Dim MyCallBack As EnumWindowsProc
MyCallBack = New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
EnumWindows(MyCallBack, 0)
可是最终用Spy++查看并没有效果是怎么回事?跪求大神指点!多谢!
MyCallBack = New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
你的思路根本就不对。
你的函数指针只是你进程中的地址,跨进程传函数指针,根本不可能回调到你,相反会导致目标进程崩溃。
要想让你的消息处理程序在别的进程中执行,首先需要用writeprocessmemory注入你的代码到目标进程,然后createremotethread执行,而且VB的代码肯定是执行不了的。必须是C++手工写机器码。
这个具体的做法在罗云彬的一本Win32汇编教程中有。
不过windows提供了shell扩展,允许你在任务栏上插入带区界面,windows 7也提供了动态桌面api。这些都在platform sdk有例子。