Most Windows programs are controlled by "messages", signals which keep it up-to-date with what’s happening (you’ve moved the mouse) or tell it what to do: close down, perhaps.
If you’re thinking "so what?", then you may have a point. The typical PC user doesn’t have to know anything about this at all. If you’d like to automate common tasks via scripts or shortcuts, though, it may be worth looking at how this system can work for you.
You’ll need to start by finding a way to send Windows messages yourself. SendMessage is portable, free, and a reasonable choice (there are 32-bit and 64-bit builds -- be sure to choose the appropriate one for your PC).
The program is very much developer-oriented, but you don’t need to understand the complexities to make it do something useful. Just right-click the executable, select "Create Shortcut"; right-click the shortcut, select "Properties", and change the Target to suit your needs.
(Before you start, though, keep in mind that sending the wrong message can leave your system unstable, maybe cause a crash, so save any work first.)
Once you’re ready, try amending your shortcut target to read something like this (replacing "SendMessage.exe" with the name of the executable on your system).
SendMessage.exe /message:16 /processname:cmd.exe
This sends message 16 ("WM_CLOSE") to every process with an executable name of cmd.exe, which should then close every open command window on your system. Replace "cmd.exe" with some other executable name and it’ll close that, instead, at least in theory (if a window has unsaved work then it may display an alert, first).
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.
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 SendMessage’s possibilities.
If you want to know more, then the documentation for scripting tools like AutoHotKey can provide some clues, and Google searches may then help you further. But again, be very careful. Sending inappropriate messages could make applications (or your entire system) unstable. Don’t experiment while you’ve unsaved work.
via BetaNews http://feeds.betanews.com/~r/bn/~3/6hZvG5kHjhI/
Aucun commentaire:
Enregistrer un commentaire