wangwenx190 2016-04-09 12:01 采纳率: 100%
浏览 2030
已采纳

vb.net用EnumWindows嵌入桌面的问题

各位大神,我想让窗口嵌入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++查看并没有效果是怎么回事?跪求大神指点!多谢!

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-04-09 13:35
    关注

    MyCallBack = New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
    你的思路根本就不对。
    你的函数指针只是你进程中的地址,跨进程传函数指针,根本不可能回调到你,相反会导致目标进程崩溃。
    要想让你的消息处理程序在别的进程中执行,首先需要用writeprocessmemory注入你的代码到目标进程,然后createremotethread执行,而且VB的代码肯定是执行不了的。必须是C++手工写机器码。
    这个具体的做法在罗云彬的一本Win32汇编教程中有。

    不过windows提供了shell扩展,允许你在任务栏上插入带区界面,windows 7也提供了动态桌面api。这些都在platform sdk有例子。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗