SendMessage is a tool for sending Windows messages to any window. It's oriented very much at developers, but has applications for regular PC users, too (so if that's you, skip the next paragraph).
If you're a developer, then the program makes it easy to test how your application responds to a particular message - WM_ENDSESSION, say - without affecting anything else. There's a list of common messages built in, or you can specify another; you can enter WPARAM or LPARAM values; then choose your target window from a list, click "SendMessage" and watch the results.
What you can also do, though, is automate the process by passing parameters from the command line, and that has all kinds of possibilities. It can crash your system if you send the wrong message, so save your work first, but then try this example.
SendMessage.exe /message:16 /processname:cmd.exe
Message 16 is "WM_CLOSE", and so this one command will close every open command window on your system. Replace "cmd.exe" with some other executable name and it'll close that, instead.
You can also close windows by their title, like so:
SendMessage.exe /message:16 /windowtitle:"Untitled - Notepad"
That command will close every open Notepad window where you haven't opened or saved a file. (Or it'll try, anyway - if there's unsaved text then you'll be warned, first.)
If you just want to shut down programs from a shortcut then there are easier ways to do it, of course - the Windows TaskKill command in particular. But the whole point of SendMessage is it can handle any Windows message, which gives it all kinds of possibilities.
To minimize a window, say, try this.
SendMessage.exe /message:274 /windowtitle:"Untitled - Notepad" /wparam:61472
To maximize it, use this.
SendMessage.exe /message:274 /windowtitle:"Untitled - Notepad" /wparam:61488
You can even simulate clicks in an application. The following will click the Play/ Pause button in Windows Media Player.
SendMessage.exe /message:273 /windowtitle:"Windows Media Player" /wparam:32808 /lparam:0
Okay, that might not be something you want to automate right now, but it is a good example of the possibilities.
If you want to know more, then the documentation for scripting tools like AutoHotKey can provide some clues.
Be very careful, though. Sending the wrong messages could make an application behave oddly, or perhaps crash your system. Don't experiment while you've unsaved work.
Your Comments & Opinion
Wine lets you run Windows applications directly on your Linux desktop without needing an emulator.
Wine lets you run Windows applications directly on your Linux desktop without needing an emulator.
Arrange program windows on your desktop to enhance your productivity
Call Windows API functions from the command line
Control applications from shortcuts or the command line
Create, edit and convert images from the command line
A powerful, portable Notepad replacement
A powerful, portable Notepad replacement
An intelligent free cross-platform editor for developers
Easily create responsive websites, no design skills required.