The API object provides easy-to-use access to certain Win32 API
functions which may be needed by applications that need to perform
some advanced tasks. While useful in scenarios where the standard
NSBasic features are not enough the API object requires careful
usage and some basic level of understanding of the Win32 API. Wrong
usage will not harm the system, but may cause some inconveniences to
the interactive user or unexpected behavior of the application or
the affected windows of other applications. It is recommended to
consult MSDN for details about the particular methods and
properties. To make this easier the most of the API object's members
are named after the closest Win32 API function.
Name |
Syntax |
Description |
FindWindow |
wnd =
object.FindWindow(title) |
Finds a top level window with
the specified title and returns its handle. If such
window is not found 0 is returned. |
ReleaseCapture |
object.ReleaseCapture() |
Releases the mouse capture
(See also Capture). |
SendMessage |
r =object.SendMessage(wnd,msg,wParam,lParam) |
Sends message to a window and
returns the result. This method cannot be used for windows of
other applications. |
WindowFromPoint |
wnd =
object.WindowFromPoint(X,Y) |
Returns the handle of the
window at point X,Y (in screen coordinates). |
ChildWindowFromPoint |
wnd =
object.ChildWindowFromPoint(wnd,X,Y) |
Returns the handle of the
child window of wnd at point X,Y (in screen
coordinates). Wnd is the parent window whose children are
searched. |
PostMessage |
r =object.PostMessage(wnd,msg,wParam,lParam) |
Posts message to the
specified window. In contrast to SendMessage this method can
be used over windows of other applications. |
ForegroundWindow |
wnd =
object.ForegroundWindow
object.ForegroundWindow = wnd |
Gets/Sets the foreground
window. |
Focus |
object.Focus = wnd
wnd = object.Focus |
Gets/Sets the window which
owns the keyboard focus. |
Capture |
object.Capture = wnd
wnd = object.Capture |
Gets/Sets the window which
has the mouse capture. To release capture call ReleaseCapture
(see above). |
EnableKeyboard |
object.EnableKeyboard
= boolValue
var = object.EnableKeyboard |
Gets/Sets the enabled state
of the hardware keyboard. Works only on Windows CE based
devices with hardware keyboard. |
WindowText |
object.WindowText(wnd)
= stringValue
var = object.WindowText(wnd) |
Gets/Sets the text of the
specified window. Usually the window text is displayed in its
caption. Specific windows (such as edit boxes, labels and so
on) display their window text otherwise - as content, as label
and so on. |
SystemColor |
object.SystemColor(lColor)
= colorValue
var = object.SystemColor(lColor) |
Gets/Sets a system wide color
constant specified by lColor. Note that this changes the color
for all the applications! The different OS versions support
some common Windows color values and some specific to the
particular OS. Lookup GetSysColor in MSDN for more
information. Some of the most common color constants are:
COLOR_SCROLLBAR 0
COLOR_BACKGROUND 1
COLOR_ACTIVECAPTION 2
COLOR_INACTIVECAPTION 3
COLOR_MENU 4
COLOR_WINDOW 5
COLOR_WINDOWFRAME 6
COLOR_MENUTEXT 7
COLOR_WINDOWTEXT 8
COLOR_CAPTIONTEXT 9
COLOR_ACTIVEBORDER 10
COLOR_INACTIVEBORDER 11
COLOR_APPWORKSPACE 12
COLOR_HIGHLIGHT 13
COLOR_HIGHLIGHTTEXT 14
COLOR_BTNFACE 15
COLOR_BTNSHADOW 16
COLOR_GRAYTEXT 17
COLOR_BTNTEXT 18
COLOR_INACTIVECAPTIONTEXT 19
COLOR_BTNHIGHLIGHT 20
The colorValue can be constructed this way:
B * &H10000 + G * &H100 + R
Where R, G and B are the Blue, Green and Red component
(0-255). |
TopMost |
object.TopMost = wnd |
Makes the specified window
"top most". |
GetWindow |
wnd = object.GetWindow(wnd,type) |
Retrieves a window that is in
the specified relation (type) to the given window (wnd). type
can be:
GW_HWNDFIRST 0
GW_HWNDLAST 1
GW_HWNDNEXT 2
GW_HWNDPREV 3
GW_OWNER 4
GW_CHILD 5 |
ClassName |
var =
object.ClassName(wnd) |
Returns the Window class name
of the specified window. |
ShowWindow |
object.ShowWindow(wnd,cmd) |
Changes the window presence.
For example hides or shows it. The cmd can be:
SW_HIDE 0
SW_SHOWNORMAL 1
SW_NORMAL 1
SW_SHOWMINIMIZED 2
SW_SHOWMAXIMIZED 3
SW_MAXIMIZE 3
SW_SHOWNOACTIVATE 4
SW_SHOW 5
SW_MINIMIZE 6
SW_SHOWMINNOACTIVE 7
SW_SHOWNA 8
SW_RESTORE 9
SW_SHOWDEFAULT 10
SW_FORCEMINIMIZE 11 |
GetAsyncKeyState |
state = object.GetAsyncKeyState(lKey) |
Retrieves the state of a
keyboard key. lKey specifies the keyboard key to query. While
the function can query wide variety of state information we
list here only some of the features. For more information see GetAsyncKeyState
in MSDN.
lKey codes for some keyboard keys:
VK_LSHIFT &HA0
VK_RSHIFT &HA1
VK_LCONTROL &HA2
VK_RCONTROL &HA3
VK_LMENU &HA4
VK_RMENU &HA5
VK_F1 &H70
continuous to
VK_F24 &H87
VK_SHIFT &H10 (shift any)
VK_CONTROL &H11 (control - any)
VK_MENU &H12 (alt - any)
VK_PAUSE &H13
VK_CAPITAL &H14 (caps lock)
The returned result can be used this way to determine if
the key is down or up.
If state >= &H80000000 Then
' Key is down
Else
' Key is up
End If
|
SendKeys |
object.SendKeys(strKeys
[,boolSilent]) |
Sends a keyboard stroke to
the window that has the focus. On Widnows CE If boolSilent is
True no clicking sounds are made. |
GetMemoryStatus |
var = object.GetMemoryStatus(type) |
Obtains information about the
system/program memory.
type can be:
0 - Total physical memory
1 - Available physical memory
2 - Total page file
3 - Available page file
4 - Total virtual memory (for the process)
5 - Available virtual memory (for the process)
6 - System memory load in percents (0 - 100)
In order to support both CE and desktop systems the function
uses different numeric types for the returned value. On
desktops it will most often return double precision floating
point value because the long integer values are not enough for
the modern machines. |
GetStorageStatus |
var = object.GetStorageStatus(info
[, path]) |
Obtains storage information.
info can be:
0 - Total size of the storage in bytes
1 - Free bytes on the storage
2 - Free bytes on the storage available to the user.
If the path argument is omitted the function returns:
On desktop: information about the volume containing the
current directory
On CE devices: Information about the internal object store.
If path is present it should be a string denoting a
path on the storage device/volume for which you want to obtain
information (it doesn't matter which directory is specified -
it is enough to be sure that it is on the device/volume of
interest).
Usually info = 2 will return the same information as 1, but on
systems where that have disk quoting enabled it will indicate
the space available to the current user. |
GetPowerStatus |
var = object.GetPowerStatus(param) |
Obtains information about the
system power status.
param can be:
0 - Is on AC power (0 -no, 1 - yes, 255 - unknown)
1 - Battery (1 - high, 2 - low, 4 - critical, 8 - charging,
128 - no battery, 255 - unknown)
2 - Battery life (0 - 100% or 255 if unknown)
3 - Battery life time (in seconds or -1 meaning unknown)
4 - Battery full life time in seconds or -1 if unknown.
Windows CE only:
5 - Backup battery flag - like 1
6 - Backup Battery life (0 - 100% or 255 if unknown)
7 - Backup Battery life time (in seconds or -1 meaning
unknown)
8 - Backup Battery full life time in seconds or -1 if unknown. |
SystemParameters |
object.SystemParameters(which)
= newVal
var = object.SystemParameters(which) |
Get set some system
parameters.
which can be:
0 - Work area returns/sets a rectangle
describing the work area
Windows CE only:
1 - Gets/Sets the idle timeout for which the device will stay
on after it has been waked up. Returns the timeout for the
current situation - no matter which is it.
2 - Gets/Sets the idle timeout for which the device will stay
on after it has been waked up when on external power.
3 - Gets/Sets the idle timeout for which the device will stay
on after it has been waked up when on battery power.
4 - Gets (only) - platform type as string
5 - Gets (only) - OEM information as string
To set the work area you must first get it than change the
returned object and assign it back. Example:
rect = api.SystemParameters(0)
rect.Left = rect.Left + 20
Set api.SystemParameters(0) = rect
This code shrinks the work area by 20 pixels on the left. The
best way to describe the work area is to say that it is the
screen area which is available to maximized windows. On the
different OS versions and devices this may have also some
additional effects. |
CreateShortcut |
object.CreateShortcut(spath,tpath) |
Creates shortcut named spath
pointing to the file/directory tpath. Note that you
should name the shortcut with .LNK file extension to make sure
it is correctly displayed and used by the shell. spath and
tpath must be full path names. |
AddToRecent |
object.AddToRecent(path) |
Adds the specified path/file
to the recent files/documents. |
GetSpecialFolder |
var = GetSpecialFolder(type) |
Obtains the full path to the
specified special folder. Note that the different OS versions
support quite a lot of specific special folders. The type
values listed below are only for the most common ones. Check
MSDN for the specific ones if you wish to use them. The
function will work with future versions of the OS - by
supplying the correct constant you will be able to obtain the
folder of interest even if it does not existed at the time
this library was built.
type can be:
0 - Desktop
2 - Programs (in the start menu)
5 - Personal/My Documents
6 - Favorites
7 - Startup
8 - Recent
9 - Send to
11 - Start menu
10 - desktop directory
14 - Fonts
15 - Templates
26 - Application data
Note that together with CreateShortcut you can find
appropriate location and create shortcut there. |
GetShortcutTarget |
var = object.GetShortcutTarget(spath) |
Obtains the target to which
the specified shortcut points. spath is the full path
name of the shortcut file. Note that the shell hides the
shortcut's file extension which is .LNK |
FindWindowByClass |
wnd = object.FindWindowByClass(strClass) |
Returns the first found top
level window of the given Window class. |
ClipText |
object.ClipText =
value
var = object.ClipText |
Sets/Gets the text to/from
the clipboard. When set the clipboard is cleared from any
previous content and the assigned text is placed in it. |
Version |
object.Version |
Returns the object version. |
CursorPos |
Set obj =
object.CursorPos |
Returns a point
object holding the screen coordinates of the mouse cursor. |
SystemVersion |
var =
object.SystemVersion |
Returns the OS version as
long integer.
Major version is var / &H10000
Minor version is var And &HFFFF |
WindowLong |
object.WindowLong(wnd,lLong)
= value
var = object.WindowLong(wnd,lLong) |
Sets/Gets a value associated
with the given window. The value is long integer (vbLong). Use
with extreme care!!! Some of the values associated with
the windows hold internal pointers to code that handles the
window and changing them may crash the application to which
the window belongs. Check carefully MSDN before using this
method - see GetWindowLong/SetWindowLong and the related
comments. |
Ticks |
var = object.Ticks |
Returns the ticks count since
the system start up. 1 - tick is 1 millisecond. |
SystemTime |
object.SystemTime =
value
var = object.SystemTime |
Sets/Gets the system time |
LocalTime |
object.LocalTime =
value
var = object.LocalTime |
Sets/Gets the local time |
WindowParent |
object.WindowParent(wnd)
= wndParent
wnd = object.WindowParent(wndToQuery) |
Gets/Sets the parent window
of an window. Use with extreme care !!! Changing the parent of
an window may lead to unpredictable results including
application crash. You should have good knowledge about the
behavior of the affected windows. |
OSType |
var = object.OSType |
Returns a string identifying
the OS type:
9x - The OS is Windows 95/98/ME
NT - The OS is NT4/Win2k/XP or later
CE - The OS is Windows CE.
Can be used when you are creating code that must work on
different platforms. Determining the OS Type your code will be
able to avoid or use features specific to a particular
platform. |
Hibernate |
Sub object_Hibernate() |
Fired when the system
resources are running low and the application should attempt
to free as much as possible. (Windows CE only) |
ColorChange |
Sub object_ColorChange() |
Fired when one or more of the
system colors are changed. |
FontChange |
Sub object_FontChange() |
Fired when a new font has
been added/changed/deleted from the system |
PaletteChange |
Sub object_PaletteChange() |
Fired only on systems using
graphics mode with palettes. Fires when the system palette
changes. |
SettingsChange |
Sub object_SettingsChange(which) |
Fired when a system setting
is changed. which contains the setting index. |