[译]邮件发送者
By robot-v1.0
本文链接 https://www.kyfws.com/applications/messagesender-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2529 个词 阅读量 0[译]邮件发送者
原文地址:https://www.codeproject.com/Articles/4909/MessageSender
原文作者:Dmytro Ivanchykhin
译文由本站 robot-v1.0 翻译
前言
Utility that allows sedning of window messages to a selected window from both MessageSender and target window thread context
该实用程序允许从消息发件人和目标窗口线程上下文将窗口消息发送到所选窗口
- 下载源文件62.5 KB(Download source files - 62.5 KB)
- 下载MessageSender-44.0 KB(Download MessageSender - 44.0 KB)
介绍(Introduction)
有时(例如出于测试目的)可能希望将消息发送到某些应用程序的窗口.原来,(It may be desirable sometimes (for instance, for testing purposes) to send a message to a window of some application. Initially,) MessageSender
通常是为了发送此类消息而创建的(was created just for sending such messages, normally) WM_USER + XXX
要么(or) WM_APP + XXX
或某些不包含指针的系统消息.后来,我添加了一些其他功能,例如上下文和时间自定义.一些消息,例如(or some system messages not containing pointers. Later, I added a few more features such as context and time customization. A few messages, such as) WM_SETTEXT
和(and) WM_SETFONT
,也可以定制.他们的名单还不多.我只是为我最喜欢的人而做的.(, can also be customized. Their list is not so long though; I did it just for my favorite ones.)
设置和操作(Settings and Operations)
-
窗口选择(Window Selection)
您可以提供窗口的句柄或其标题和类.另外,由于Lim Bio Liong及其文章,您可以使用窗口查找工具(You can provide the handle of a window or its title and class. Alternatively, you can use a window-finding tool thanks to Lim Bio Liong and his article) MS Spy ++样式的窗口查找器(MS Spy++ style Window Finder) .另外,您可以浏览下一个/上一个或父/第一个子窗口.(. Also, you can navigate along next/previous or parent/first child windows.)
-
讯息选择(Message Selection)
输入消息代码(十六进制)或从列表中选择一条消息,并指定其(Enter message code (hex) or select a message from the list, specifying their) wParam
和(and) lParam
.对于一些消息,您可以以更自然的方式自定义其参数.对于那些值应该是指针的人来说,它特别有用.举例来说,(. For a few messages, you can customize their parameters in a more natural way. It is especially useful for those whose values should be pointers. See, for instance,) WM_SETTEXT
要么(or) WM_SETFONT
.(.)
-
发送方式(Sending Method)
您可以选择(You can select among the) SendMessage()
,(,) PostMessage()
和(and) SendMessageTimeout()
发送消息的功能.(functions to send a message.)
-
语境(Context)
某些消息无法从其他线程发送到Windows.如果选择了目标窗口线程上下文,(Some messages cannot be sent to windows from a different thread. If target window thread context is selected,) MessageSender
首先在目标窗口上安装一个钩子,注入(first installs a hook on the target window, injecting)**msgsndr.dll(msgsndr.dll)**到其进程地址空间.在第一次调用hook函数的过程中,将在目标线程上下文中创建一个新的隐藏窗口.该窗口将用作发送消息时的媒介.即(to its process address space. During the first call to the hook function, a new hidden window will be created in the target thread context. This window will serve as a medium while sending messages. Namely,) MessageSender
将打包原始消息并使用打包发送(will pack an original message and send it packed using) WM_COPYDATA
到那个隐藏的窗口.然后,窗口过程将其解压缩并转发到其目标.请注意,最后的步骤将不在(to that hidden window. Then the window procedure unpacks it and forwards to its target. Note that the last steps will be performed not in) MessageSender
,但在目标线程上下文中.(, but in the target thread context.)
-
时间值(Time Values)
通常,一旦您按下"发送!",消息就会发送一次.按钮.通过指定相应的值,您可以稍后或在链中几次执行此操作.(Normally messages will be sent once, as soon as you press the “Send it!” button. By specifying correspondent values, you can do it later or a few times in a chain.)
使用代码(Using the Code)
我希望代码或多或少是不言自明的.工作区包含两个项目,MessageSender(EXE)和msgsndr(注入DLL).主应用程序对话框是(I hope that the code is more or less self-explanatory. The workspace contains two projects, MessageSender (EXE) and msgsndr (injecting DLL). The main application dialog is) CMessageSenderDlg
(文件:((files:)**MessageSenderDlg.cpp(MessageSenderDlg.cpp)**和(and)MessageSenderDlg.h(MessageSenderDlg.h)).().)
您可能想为更多消息添加自定义.为了保护我的代码免于频繁更改,我派生了(It is possible that you would like to add customization for more messages. To protect my code from frequent changes, I derived) CSendMessageDialog
(文件:((files:)**SendMessageDialog.h(SendMessageDialog.h)**和(and)SendMessageDialog.cpp(SendMessageDialog.cpp))来自() from) CMessageSenderDlg
.相应地实现其部分或全部功能:(. Implement accordingly some or all of its functions:)
class CSendMessageDialog : public CMessageSenderDlg
{
...
protected:
// TODO: add members keeping message specific values here
// TODO: implement accordingly some or all next functions to customize
// a message
virtual void AddConstantsToCombo();
// called from IniConstListCombo()
virtual void MessageChanged(UINT unMessage);
// called from OnChangeEditMessage()
virtual void CustomizeMessage(UINT unMessage);
// called from OnButtonCustomize()
virtual void PreSendMessage(SendingMessage*);
// called from OnButtonSend()
virtual void PrepareMessageLocal(SendingMessage*);
// called from SendMsgLocalContext()
virtual CString DisplayMessageLocalResults(SendingMessage*);
// called from SendMsgLocalContext()
virtual void PrepareMessageTarget(SendingMessage*);
// called from SendMsgTargetContext()
virtual CString DisplayMessageTargetResults(SendingMessage*);
// called from SendMsgTargetContext()
}
另外,向其中添加必要的代码(In addition, add necessary code to) InsertedDialogProc()
在DLL中(文件:(in the DLL (file:)msgsndr \ msgsndr.cpp(msgsndr\msgsndr.cpp)).我已经用(). I have marked correspondent places by) TODO
评论.如果您从事这项工作,请不要忘记给我发送副本!(comments. If you do this job, please do not forget to send me a copy!)
警告(Warning)
发送一些消息可能会导致不可预测的结果.目标应用程序可能会停止正常运行,并且您可能会丢失一些数据.建议关闭除正在测试的应用程序之外的所有应用程序.(Sending some messages may cause unpredictable results. Target applications may stop working properly and you can lose some data. It is recommended to close all applications but the one you’re testing.)
历史(History)
2003年9月2日(Sep 2, 2003)
- 首次公开发行(Initial public release)
2003年9月9日(Sep 9, 2003)
- 现在,“查找窗口"工具可以捕获更多窗口,包括禁用的和隐藏的子窗口.(“Find window” tool is now able to catch more windows, including disabled and hidden child windows.)
- 沿下一个/上一个或父/第一个子窗口的导航已添加.(Navigation along next/previous or parent/first child windows was added.)
- 消息处理结果现在在两个本地都可用(即(Message processing result is now available in both local (i.e.)
MessageSender
)和目标窗口线程上下文.() and target window thread context.)
2004年8月23日(Aug 23, 2004)
- 有关线程/进程/可执行文件路径的信息(后者在Windows NT下不可用).(Information about thread / process / path to the executable file (the latter is not available under Windows NT).)
- 可以在已经找到的窗口中来回导航.(Possibility to navigate back and forth through already found windows.)
- 使用"查找窗口"工具时,主窗口会自动缩小.(Main window is automatically reduced in size while using the “Find window” tool.)
2007年8月20日(Aug 20, 2007)
WM_COPYDATA
现在可以自定义消息并从(message can now be customized and sent from)MessageSender
线程上下文.(thread context.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Windows Win2K MFC Visual-Studio Dev 新闻 翻译