Sample (notepd.csl)

C Scripting Language
Reference Manual
Version 4.4.0

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using the CSL executive
Language
Directives
System library
String library
Math library
Regular expression lib.
File library
Database library
Async Communication
Registry/Profile handling
Windows control
   winActivate
   winClose
   winCapsLock
   winFind
   winHide
   winIsMaximized
   winIsMinimized
   winIsVisible
   winMaximize
   winMinimize
   winNumLock
   winPostText
   winPostVKey
   winPrintScreen
   winRestore
   winScrollLock
   winShow
   Sample (notepd.csl)
C API
C++ Class Interface
CSL links
  

This sample uses several functions of the window control library.

It launches notepad.exe and finds the corresponding window handle. Then some text is written to the client area and the file is saved.

Finally there are minimizing/maximizing operations run and notepad is closed again.

NOTE:

Depending on the version and language of your notepad.exe you will have to change the title text in the winFind() function below to run the sample. Otherwise the notepad window may not be found.

#loadLibrary 'ZcSysLib'
#loadLibrary 'ZcWinLib'
#loadLibrary 'ZcFileLb'
 
/*
 * w i n W a i t F o r
 *
 * Wait until a window with given title is open
 */
static var winWaitFor(const title, const maxsecs)
{
   const start = sysElapsed();
   var win[10][2]; // space for window records
   while (!winFind(title, win)) {
      sysSleep(300); // wait a while
      if (sysElapsed()-start >= maxsecs)
         throw '%%% window '|title|' not found!';
   } // for
   return win[0][0]; // handle
} // winWaitFor
 
main()
{
   // Launch notepad.exe. We use the "start" command since we want
   // sysCommand to return immediately and not to wait till notepad
   // has ended:
   sysLog('starting notepad...');
   sysCommand('start notepad.exe');
 
   // Now wait for notepad to start.
   // I used a german notepad.exe of Windows 2000, for other locales
   // or versions the title must be changed accordingly:
   sysLog('waiting for window...');
   const handle = winWaitFor('Unbenannt - Editor', 5);
 
   // make sure window is activated
   sysLog('activate window...');
   winActivate(handle);
 
   // write text to the client area
   sysLog('post some text...');
   winPostText('Hello world!');
 
   sysLog('save file...');
   // make sure file does not exist in advance:
   try { fileDelete('C:\\CslTest.txt'); } catch (var exc[]) {}
 
   // select 'save as..' by the menu:
   winPostVKey(VK_MENU); // open menu
   winPostVKey(VK_DOWN); // move down to "save as..."
   winPostVKey(VK_DOWN);
   winPostVKey(VK_DOWN);
   winPostVKey(VK_DOWN);
   winPostText('\n');    // could also use winPostVKey(VK_RETURN) here
 
   // write file name into file dialog and save by enter:
   winPostText('C:\\CslTest.txt\n');
 
   // Now fool around with the window
   sysLog('maximize...');
   winMaximize(handle);
   sysSleep(1000);
 
   sysLog('restore...');
   winRestore(handle);
   sysSleep(1000);
 
   sysLog('minimize...');
   winMinimize(handle);
   sysSleep(1000);
 
   sysLog('restore...');
   winRestore(handle);
   sysSleep(1000);
 
   // Close notepad. This could of cause also be done with VKeys.
   // Using winClose is a 'hard' close giving the application no
   // chance to complain anything.
   sysLog('close window...');
   winClose(handle);
 
   sysPrompt('press enter to finish...');
} // main
  Copyright © IBK Landquart Last revision: 27.05.2002 << Back  Top  Next >>