Using Sendmessage with applications like Notepad, Word, Dreamweaver

Asked

Viewed 164 times

3

I’m having a hard time working with SendMessage(), in some programs works from one method and with others from another...

To write on Notepad, I 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 if I need to send a message to a game, a spreadsheet in Word, Notepad++, Dreamweaver, etc, it doesn’t work...

How does it work in other cases? I read a little about Spy++, but it would be just like that?

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 into these programs if you want to write on your windows (or click on their internal buttons, enable features like save etc.) this way. There is a very high chance that your code will be blocked by Windows itself or by an antivirus.

But do not be 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 API’s, which are simpler and better documented than the Windows API’s.

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 the Netoffice, a layer wrapper that makes things much easier.

In the case of Dreamweaver, you use the Extension API’s. In this case you will work with Javascript, not C#.

For Notepad++, you can make your own plugins. The linked page 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 made in C#.

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

  • Thanks, I’ll read it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.