Click here to Skip to main content
11,492,639 members (51,988 online)
Click here to Skip to main content

MessageSender

, 24 Aug 2004 88.2K 5K 116
Rate this:
Please Sign up or sign in to vote.
Utility that allows sedning of window messages to a selected window from both MessageSender and target window thread context
Screenshot - MessageSender.jpg

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

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

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

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

In addition, add necessary code to InsertedDialogProc() in the DLL (file: 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

Sep 2, 2003

  • Initial public release

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.

Aug 23, 2004

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

Aug 20, 2007

  • WM_COPYDATA message can now be customized and sent from MessageSender thread context.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

No Biography provided

Comments and Discussions

 
Questioninfected exe? Pin
maltwhiskman25-Aug-10 22:13
membermaltwhiskman25-Aug-10 22:13 
AnswerRe: infected exe? Pin
Dmytro Ivanchykhin26-Aug-10 23:33
memberDmytro Ivanchykhin26-Aug-10 23:33 
Would be nice to know the "Hero" (instead of just "one AV package"). Indeed, as the source code is available, one can compile and compare resulting binaries with those posted here (MS Visual Studio 6 (as I remember, without SPs) has been initially used).

Regards,
D.I.
GeneralRe: infected exe? Pin
maltwhiskman30-Jun-11 18:57
membermaltwhiskman30-Jun-11 18:57 
QuestionHow to send a pointer to a data? Pin
ehaerim4-Jun-10 23:18
memberehaerim4-Jun-10 23:18 
AnswerRe: How to send a pointer to a data? Pin
Dmytro Ivanchykhin7-Jun-10 11:34
memberDmytro Ivanchykhin7-Jun-10 11:34 
QuestionHow to send WM_COPYDATA with a string? Pin
ehaerim17-Aug-07 23:51
memberehaerim17-Aug-07 23:51 
AnswerRe: How to send WM_COPYDATA with a string? Pin
Dmytro Ivanchykhin18-Aug-07 4:00
memberDmytro Ivanchykhin18-Aug-07 4:00 
GeneralRe: How to send WM_COPYDATA with a string? Pin
ehaerim18-Aug-07 4:23
memberehaerim18-Aug-07 4:23 
AnswerWM_COPYDATA customization added ... Pin
Dmytro Ivanchykhin20-Aug-07 9:18
memberDmytro Ivanchykhin20-Aug-07 9:18 
GeneralRe: WM_COPYDATA customization added ... Pin
ehaerim18-Oct-08 7:05
memberehaerim18-Oct-08 7:05 
Generalthe best Pin
DgMv30-Apr-06 13:44
memberDgMv30-Apr-06 13:44 
QuestionHow do I send special characters ? Pin
sanskypotov19-Aug-04 22:15
membersanskypotov19-Aug-04 22:15 
AnswerRe: How do I send special characters ? Pin
Dmytro Ivanchykhin21-Aug-04 12:23
memberDmytro Ivanchykhin21-Aug-04 12:23 
GeneralExcellent Pin
Brian Delahunty25-Sep-03 3:04
memberBrian Delahunty25-Sep-03 3:04 
GeneralVery cool! Pin
Chris Richardson11-Sep-03 16:00
memberChris Richardson11-Sep-03 16:00 
GeneralExcellent Pin
Simon Hughes9-Sep-03 0:21
memberSimon Hughes9-Sep-03 0:21 
GeneralRe: Excellent Pin
super_virus_future30-Dec-08 1:12
membersuper_virus_future30-Dec-08 1:12 
Generalgood... Pin
KRS-SSD8-Sep-03 4:19
memberKRS-SSD8-Sep-03 4:19 
GeneralUHU,,,, Pin
Snyp5-Sep-03 13:45
memberSnyp5-Sep-03 13:45 
GeneralExcellent Pin
Binarygb5-Sep-03 3:51
memberBinarygb5-Sep-03 3:51 
GeneralAwesome Tool Pin
lordelectro4-Sep-03 9:48
memberlordelectro4-Sep-03 9:48 
GeneralWoW!!! Pin
Caio Proiete3-Sep-03 15:42
memberCaio Proiete3-Sep-03 15:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 25 Aug 2004
Article Copyright 2003 by Dmytro Ivanchykhin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid