各位大神,我想讓窗口嵌入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有例子。