Using SendMessage with applications such as Notepad, Word, DreamWeaver

3

I'm having difficulty working with SendMessage() , some programs work from one method and others from another ...

To write to Notepad, do the following:

[DllImport("user32.dll")]
    public static extern IntPtr PostMessage(IntPtr Handle, uint Message, int lparam, int wParam);

[DllImport("user32.dll", EntryPoint = "FindWindowEx") ]
    public static extern IntPtr FindWindowEx(IntPtr Handle, IntPtr Child, string lparam, string wParam);

static Process p = Process.GetProcessesByName("Notepad")[0];
public static void Message()
{
    string msg = "Teste";
    IntPtr child = DLLs.FindWindowEx(p.MainWindowHandle, new IntPtr(0), "Edit", null);
    foreach(char c in msg){
        DLLs.PostMessage(child, 0x102, Convert.ToChar(c), 0);
    }
}

But your I need to send a message to a game, a spreadsheet in Word, Notepad ++, DreamWeaver, etc., does not work ...

How does it work in other cases? I read a bit about Spy ++, but would it be just the same?

    
asked by anonymous 24.08.2014 / 08:41

1 answer

3

The Windows API is very powerful, and it's fun to try the things we can do with it.

However, you are literally hacking these programs, if you want to write in your windows (or click on your internal buttons, activate features like save etc.) in this way. There is a very high chance your code will be blocked by Windows itself or by an antivirus.

But do not get discouraged, there are other ways to communicate with several of these programs. Often their developers allow other third-party programs to interact with them. This is the case for all Office programs (Word, Excel, Power Point, etc.). These programs have their own APIs, which are simpler and better documented than the Windows APIs.

In the case of Office, the official APIs are called Office Primary Interop Assemblies and Visual Studio Tools for Office . Better than using these tools, however, is to use NetOffice , a wrapper layer that makes things a lot easier.

For Dreamweaver, you use the Extension APIs . In this case you will work with Javascript, not with C #.

For Notepad ++, you can make your own plugins . The page linked here is a tutorial to make your first plugin in 10 minutes;) Take a look at the bottom of the page, have an example plugin done in C #.

Other programs may or may not have API's that you can use. It is up to you to search for each one. In general, the most commonly used software in the world often has some form of API integration. Good luck and good learning!

    
24.08.2014 / 14:56