Miscellaneous system routines v0606

From EuWiki

Jump to: navigation, search

This page gathers information about loosely related routines which report system parameters or instruct Windows to do something.

Contents

Getting parameters

The getWinVersion() function returns a 3 element sequence:

  1. a string stating the OS main type, for instance "WIN_20000";
  2. A service package name;
  3. The build number.


getUserName() returns the user name as a string. You can see it at work in the EWX01.EXW demo program.


getSystemMetrics(request_code) returns an integer parameter which corresponds to request_code. If request_code is a sequence, a sequence of answers will b returned. See the long list of known codes in the documentation: the names are usually self explanatory. For finer details, you may look up the API docs for GetSystemMetrics(). See the imageview.exw demo program for an example of use.

OLE support

OLE is a scheme which enables to insert objects into specially designed applications, like inserting an image into a word processor document.

The library only provides routines to activate and deactivate OLE support, namely OleInitialize() and OleUninitialize(). Each call to OleInitialize() must be matched by a later call to OleUninitialize().

Executing a program

The shellExecute(command,file_specs,style) performs a command on some file system element, the first window to open being passed the requested style. file_spec may be a directory name, a file name, a mailslot, a pipe name, a registry entry,... whatever Windows treats as a file. command may either be "edit","explore','find","open", "print"or "properties". Actually, the list depends on the file being passed to the procedure. Yo find out more, look for registry keys below a "shell" key associated to the relevant object, in the HKCR hive.


Finer control is attained calling shellExecuteEx ( object verb, sequence file, object params, object defdir, object style, atom struct ). Compared to shellExecute(), the extras are:

  • you can pass a parameter string to the executable that will be launched, either explicitly or because of a file association;
  • The defdir directory specifies the starting directory. Use any atom to retain the current directory, or enter its name there;

Just set struct to 0, as it is not used.


Actually, this is an extended interface to ShellExecute(), not an interface to ShellExecuteEx().

The value this function returns is among the following:

  • 0: The operating system is out of memory or resources.
  • ERROR_FILE_NOT_FOUND: The specified file was not found.
  • ERROR_PATH_NOT_FOUND: The specified path was not found.
  • ERROR_BAD_FORMAT: The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image).
  • SE_ERR_ACCESSDENIED: The operating system denied access to the specified file.
  • SE_ERR_ASSOCINCOMPLETE: The file name association is incomplete or invalid.
  • SE_ERR_DDEBUSY: The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
  • SE_ERR_DDEFAIL: The DDE transaction failed.
  • SE_ERR_DDETIMEOUT: The DDE transaction could not be completed because the request timed out.
  • SE_ERR_DLLNOTFOUND: The specified DLL was not found.
  • SE_ERR_FNF: The specified file was not found.
  • SE_ERR_NOASSOC: There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
  • SE_ERR_OOM: There was not enough memory to complete the operation.
  • SE_ERR_PNF: The specified path was not found.
  • SE_ERR_SHARE: A sharing violation occurred.


The HOV.EXW, www.exw or shexec.exw demo program shows how to use these routines.

Sound

Two routines are provided:

  • Beep(which_sound) causes the following sound to be played:
    • -1 Standard beep using the computer speaker
    • MB_ICONASTERISK SystemAsterisk
    • MB_ICONEXCLAMATION SystemExclamation
    • MB_ICONHAND SystemHand
    • MB_ICONQUESTION SystemQuestion
    • MB_OK
  • playSound(file_specs) plays the file, normally a .wav one, and returns w32False on failure, w32True on success. Possible forms for file_spec are:
    • 0 or an empty sequence. This requests stopping any playing in progress at once.
    • A simple filename, such as a ".WAV" file to play. This sets up the flags as SND_FILENAME and SND_ASYNC.
    • A pair {FileName, Flags} which gives you more control over the flag settings. The Flags can be either a single atom or a sequence of sound flags.
    • A triple {FileName, Flags, ResourceId} is available the sound you need to play is contained in the resources of an executable file. In this case FileName is is a sequence with one element in it; a handle to an executable file. ResourceId is the id of the resource to play.

Available flags foor playSound are (from the Microsoft (tm) documentation):

SND_APPLICATION
The sound is played using an application-specific association. Use this if you need a MP3 player for instance.
SND_ALIAS
The pszSound parameter is a system-event alias in the registry or the WIN.INI file. Do not use with either SND_FILENAME or SND_RESOURCE.
SND_ALIAS_ID
The pszSound parameter is a predefined sound identifier.

SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

SND_FILENAME
The pszSound parameter is a filename.
SND_LOOP
The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event.
SND_MEMORY
A sound event's file is loaded in RAM. The parameter specified by pszSound must point to an image of a sound in memory.
SND_NODEFAULT
No default sound event is used. If the sound cannot be found, playSound returns silently without playing the default sound.
SND_NOSTOP
The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound.

If this flag is not specified, playSound attempts to stop the currently playing sound so that the device can be used to play the new sound.

SND_NOWAIT
If the driver is busy, return immediately without playing the sound.
SND_PURGE
Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped.

You must also specify the instance handle to stop SND_RESOURCE events.

SND_RESOURCE
The pszSound parameter is a resource identifier; hmod must identify the instance that contains the resource.
SND_SYNC
Synchronous playback of a sound event. PlaySound returns after the sound event completes.

See the playsounds.exw demo program for an example.

Personal tools