I wrote the attached Win32asm program to replace a
Windows Scripting Host (WHS) script. The script was
designed to:

Automatically open WordPad
Open a previously constructed Rich Text Format file
Change orientation to Landscape
Change all borders to 0.25"

At this point the user can view the report, insert
page breaks, enter comments, and then print the

When I first tried to do this using asm, I thought I
could just open WordPad with the filename in the
command line, find the window name, and send messages
using PostMessage or SendMessage. This didn't work
at all. I later found on the MSDN pages a reference
that stated that applications built using MFC don't
handle the PostMessage and SendMessage messages at

So instead, the program does not create any window and
therefore never gets focus for keyboard input. After
WordPad is opened, it gets focus, and the keybd_event
actions are sent to WordPad. Actually they are sent to
whichever window has focus. I ran an experiment where
I inserted a pause after opening WordPad, then changed
to an already opened Notepad window and after my program
finishes it's pause, the keybd_event is sent to the
Notepad window.

I tried AttachThreadInput to send my key stokes directly
to the WordPad thread I created, but the same thing
happened if the focus was changed to a different window.

I thought this might be helpful. My reasoning was that
WSH and VBS can be dangerous if installed and set to
automatically execute scripts from downloaded e-mail.
If anyone has anothe way of accomplishing something
similar, or has a better way, or suggestions for
improvement I would be grateful to this knowledge!

Posted on 2001-10-02 05:26:24 by farrier
Hi, looking for a way to automate wordpad to load with orientation set to Landscape. Please can you advise if you managed to develop a script to do this, as i'm trying to find a way. Thanks
Posted on 2010-08-19 03:42:32 by uklogistics

The attachment is lost for some reason, and I don't have that file on my current computer.  I'll see if I can find it on my old machines later today.

Posted on 2010-08-19 10:19:34 by farrier