“鲜为人知”的SendWindowMessage

标签: , , , ,

有同学看到标题可以能比较奇怪,这有什么鲜为人知的。这里说的是潜藏在MS office Word VBA中的一个SendWindowMessage方法。百度了一下,国内除了一些个别的office教材中偶尔提到外,很少有提到过这个method。这里记录一下。

先看一下MSDN的定义

SendWindowMessage Method

Sends a Windows message and its associated parameters to the specified task.

expression.SendWindowMessage(Message, wParam, IParam)

expression Required. An expression that returns a Task object.

Message Required Long. A hexidecimal number that corresponds to the message you want to send. If you have the Microsoft Platform Software Development Kit, you can look up the name of the message in the header files (Winuser.h, for example) to find the associated hexadecimal number (precede the hexidecimal value with &h).

wParam , lParam Required Long. Parameters appropriate for the message you’re sending. For information about what these values represent, see the reference topic for that message in the documentation included with the Microsoft Platform Software Development Kit. To retrieve the appropriate values, you may need to use the Spy utility (which comes with the kit).

SendWindowMessage提供了脚本与传统windows窗体消息的接口。通过它我们可以通过vbscript脚本控制windows窗体做任何事情。不过毕竟是脚本实现,不知道MS大叔是不是出于安全的考虑,这个SendWindowMessage所依附的Task Object只能通过窗体名字来获取窗体,而不是通常的窗口句柄。这就导致一个问题:只能获取到顶层父窗体。也就是说我们只能控制顶层父窗体。

不过总体来说,虽然有着各种限制(需要WORD支持,只能操纵顶层父窗体),仍然是非常有用的一个方法,例如干坏事:)捕获消息很简单,用MS自家的spy++就可以。

原文链接:“鲜为人知”的SendWindowMessage

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. 再谈CreateObject函数,VBS到底能调用哪些对象?
  2. OpenWrt配置he.net的6in4隧道访问IPv6
  3. 使用正确版本的XMLHTTP
  4. BinScope Binary Analyzer
  5. ZTE中兴F460超级管理员密码

留下回复