How to automate Windows. (Compute's Getting Started with Windows Utilities)
by Mark Minasi
Not everyone wants to learn C in order to get a few things done, in Windows. And not everyone has to.
There's a class of Windows tasks that have fallen through the cracks. These are applications that are too small or too specialized for a commercial application, yet are of use to a number of Windows users. This is nothing new in the computer world; such problems faced early users of DOS and all other operating systems. But for the past five years or more, the DOS world has been so influential that if there's some kind of need, someone has filled it.
My columns for Compute run about 2000 words. As I often use a Windows-based text editor to write those columns, I needed a word-counting program. I envisioned marking my text in the text editor, copying it to the Clipboard, and running a utility to count the words.
The fly in the ointment? Nobody's ever written such a utility.
Just as the first fish that climbed out of the ocean to an uncertain life on land had to cope with heretofore-unknown problems ("How will we stay wet?" "What do we do for food now that plankton doesn't teem around us in the ocean?"), we early evolvers to Windows must grapple with the fact that those ubiquitous DOS utilities haven't caught up with us yet. Don't get me wrong I'm not saying that Windows lacks big applications. It' doesn't. But how do you tie together a number of applications as you can with the DOS batch language? For a concrete example, I'm often asked this question in class: "How can I set it up so that, every time I start up Windows, all my applications are open and arranged in the same way?" The answer is: You can't.
That is, you can't unless you have one of the few programs around that performs the same functions for Windows that the batch language performs for DOS. I've found only six: WinBatch, BatchWorks, Norton DeBatch Builder, Bridge-Batch, Prokey For Windows, WordBASIC, and Visual Basic.
I first ran across WinBatch (Wilson -Window-Ware, 2701 California Avenue SW, Suite 212, Seattle, Washington 98116; 206-938-1740; $69.95) as part of a disk of shareware that came with a book on Windows. The book wasn't very good; it purported to reveal secrets of Windows that weren't secret to anybody who knew how to print out a readme file, but the WinBatch program was worth the price of admission.
Your batch files are executed by WinBatch's command interpreter. For example, to start the Windows calculator, you would include this in your program:
Run is a built-in WinBatch verb. Calc.exe is, of course, the Calculator program. The ""is an optional passed parameter. While the Calculator takes no parameters (that I know of), you could use this to tell the Notepad to start up with your AUTO-EXEC. BAT already loaded in it like so:
Positively nifty. You can then end the Notepad with the winclose verb, which looks like this:
The winclose verb takes only one argument, a string that matches the title of a window. Since Notepad has a title that begins with the word Notepad, winclose can find the Notepad and close it even if you don't specify the full name of the title. Now you know enough to write a simple WinBatch program, one that would open the Notepad and then close it. (Silly, yes, but then all first programs are silly.)
1. Start up a text editor, such as Notepad.
2. Type these two lines: run("notepad.exe",") winclose("note")
3. Save this file as first.ptb (the extension is important).
4. From Program Manager, click File and Run, type batch.exe first.ptb, and press the Enter key.
Assuming that you have batch.exe, and you've put it in a directory that Windows can find, you'll see the Note-pad open and close.
WinBatch also contains a winplace verb. You use it to size and move a window to a particular location. The syntax looks like this:
where ulx and uly are the (x,y) Cartesian coordinates of the desired upper-left-hand corner for the window, and Irx and Iry are the (x,y) Cartesian coordinates of the desired lower-right-hand corner of the window.
The coordinate system describes the Windows desktop with (0,0) in the extreme upper left-hand corner, and (1000,1000) in the lower right hand corner. You could write a short WinBatch program to start up Notepad and put it in the upper right hand corner of the desktop with just these two lines:
Finally, WinBatch contains a macro capability that allows you to attach programs to the menu of any Windows program. When writing recently about memory management, I often needed to convert numbers from hexadecimal to decimal. That involved minimizing my word processor, starting up the Calculator, punching in the hex number to be converted, converting it to decimal, returning to the word processor, and typing the decimal value into my text. With WinBatch, I reduced all of that to a single mouse click.
If it seems that I've spent several lines on WinBatch at the expense of the others, it's time to reveal a secret. WinBatch, PubTech BatchWorks, and Norton Desktop Batch Builder are all the same product. If you need to automate your desktop, you'll find that this product will give you the power you need. WinBatch is shareware, PubTech BatchWorks was $99 the last time I checked, and Batch Builder comes with Norton Desktop. No matter how it's packaged, it's reasonably priced.
The fourth product was written by the same people who gave us the Windows Recorder. BridgeBatch (Softbridge, 125 Cambridge Park Drive, Cambridge, Massachusetts 02140; 800-955-9190; $179) is a powerful tool that can do all the things that its little brother can't, such as record mouse movements and clicks.
Just as I was finishing this article, I came across an old friend in a new package. In the early days of the PC business, there was a terrific keystroke recorder called Prokey. It was an industry standard, but then it seemed to fade away. I was pleased to see that Prokey's developer, Rose-Soft, has created a Windows version, called Prokey for Windows (CE Software, 1801 Industrial Circle, West Des Moines, Iowa 50265; 515-224-1995). This fine program is as good as Bridge Batch, but it costs only $99.
Microsoft has two relatively easy-to-use programming languages that you can use to build larger programs, such as the word counter that I outlined earlier. Now and then, an application is revealed to contain a hidden gem. Sometimes, that gem is a truly precious stone, and such is the case with WordBASIC. You can't buy WordBASIC; it comes free with Word For Windows. Microsoft even gives away a demonstration copy of WinWord that contains the entire programming language. You're limited to a two-page document, but you can do a lot in two pages. (Hint: If you're running out of space, go to 4-point text and use the enlarged view.)
WordBASIC supports DDE and a whole raft of commands, making it a complete programming language all in itself.
WordBASIC is clearly related to its Microsoft sibling product, Visual Basic (Microsoft, One Microsoft Way, Redmond, Washington 98052; 800-426-9400; $199). I could easily devote several pages just to Visual Basic, but let me suggest two things. First, it's inexpensive, extensible, and powerful: There's even a Professional Toolkit that lets you build OLE client applications--not OLE servers, alas, but perhaps soon? Get on the VB bandwagon, and you'll find tons of company; there are books, toolkits, and lots of public domain and shareware code written in VB. Secondly, if you want to really learn to play around with VB and WordBASIC, pick up the only book I've ever read that thoroughly explains what DDE is all about, and best of all it explains it using WordBASIC and Visual Basic examples. Windows 3.1 Programming For Mere Mortals by Woody Leonard is published by Addison-Wesley.
Anyone can learn one of these languages. I wrote my hexadecimal converter macro within the first hour of working with WinBatch. My word counter took three hours from the time that I first opened the Visual Basic box to when I had the whole thing done complete with menus, speedkeys, and a pretty icon. There are some great tools out there, and they don't cost a lot, so get one today and start hacking, Windows style!