Message Sender

Environment: VC6 SP3

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 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

Three ways are available:

  • By handle
  • By window class and title
  • Manual finding (MS Spy++-style window finding tool)

You can also navigate along next/previous or parent/first child windows, as well as back and forth through already found windows.

Message selection

Enter message code (hex) or select a message from the list and specify 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

Some messages cannot be sent to windows from a different thread. If the Target window thread context is selected, MessageSender first installs a hook on the target window, injecting msgsndr.dll 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, send it packed by using WM_COPYDATA to that hidden window, and then the window procedure unpacks it and forwards it to its target. Note that the last steps will be performed not in MessageSender, but in the target thread context.

Time values

Normally, a message will be sent once, as soon as you press the "Send it!" button. By specifying corresponding values, you can do it later or a few times in a chain.

Using the Code

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 and 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 and 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()
}

And, probably, also add necessary code to the InsertedDialogProc() in the DLL (file msgsndr\msgsndr.cpp)

I have marked the corresponding 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 except those that you're testing.

Downloads

Download MessageSender - 42 Kb
Download source - 57 Kb


Comments

  • Exceptional website supplies you with the simple truth around nike that just some buyers know of.

    Posted by icoppyapedcap on 04/24/2013 09:33pm

    KltIetWopXie [url=http://www.nikeyasuijp.com/]nike[/url]MltSwtUlxKvs [url=http://www.nikeyasuijp.com/nike-air-force1エアフォース1-c-14.html]ナイキ エアフォース[/url]RrlPrdBlwSvd [url=http://www.nikeyasuijp.com/nike-air-maxエアマックス-c-12.html]nike air max[/url]RtyXuzIwlIna [url=http://www.nikeyasuijp.com/nike-air-jordanエア-ジョーダン-c-13.html]nike air jordan[/url]BpnLhnWswAso

    Reply
  • It is very use full, there was a problem while working with Mouse event

    Posted by anantha.murugan on 05/07/2009 07:14am

    hi, this programe very usefull for me and interesting, i am facing a problem while passing mouse event, first mouse event some time sending operation is successful but in second attempt the application crashes what would be the problem????? application is XSITE window not normal window

    Reply
  • for witch OS ?

    Posted by Legacy on 09/26/2003 12:00am

    Originally posted by: Bruno Leclerc

    Under NT4, it don't works:
    Fonction Module32Next not found in Kernell32.dll.
    Is it because of NT 4 ?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds