Check
Whether A File Exists
Also simple,
here is the code:
If
Dir(Filename) <> "" Then
- file
exists
where FileName
is the name of the file checked.
Stay
On Top
We'll need
SetWindowPos API function. Here is the declaration:
Declare
Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal
hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal
cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
and the code
for making the form stay on top is:
SetWindowPos
Me.Hwnd, -2, 0, 0, 0, 0, &H1 Or &H2
and to make
it back normal use:
SetWindowPos
Me.Hwnd, -1, 0, 0, 0, 0, &H1 Or &H2
replace Me
with another form name if you need.
Here is a description of the above values:
Value |
Constant |
Meaning |
-2 |
HWND_TOPMOST |
Form will
stay on top |
-1 |
HWND_NOTOPMOST
|
Form won't
stay on top |
&H1 |
SWP_NOSIZE
|
Do not
resize the form |
&H2 |
SWP_NOMOVE |
Do not
move the form |
0,0,0,0 |
|
X, Y,
Width, Height - ignored |
Run
URL
We
will use ShellExecute API function which is usually used
to run executables or other files associated with a given application
to connect to an internet site. Declaration:
Declare
Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile
As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long
and the code:
R&
= ShellExecute(Me.hwnd, "Open", "http://geocities.datacellar.net/SiliconValley/Lab/1632/",
"", App.Path, 1)
replace the
internet address with the one you want.
Value description:
Value |
Description |
R& |
error
code returned if error occured |
Me.Hwnd |
a
handle of a window to receive some kind of messages. You don't
really need them. |
"http
...." |
the
internet address |
""
|
null
string. Actually specifies any parameters if an EXE is run |
App.Path |
work
directory |
1
|
show
the application run |
Get
Disk Free Space
We use GetFreeSpace
API function.
Declaration:
Declare
Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA"
(ByVal lpRootPathName As String, lpSectorsPerCluster As Long,
lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters
As Long) As Long
and the code
looks something like that:
If
GetDiskFreeSpace("d:\", SecPCl&, BytPSec&, FreeCl&,
TotCl&) Then
MsgBox "Free Space - " & BytPSec& * SecPCl& * FreeCl&
MsgBox "Total Space - " & BytPSec& * SecPCl& * TotCl&
Else
MsgBox "Error"
End If
Value Descriptions:
Value |
Description |
"d:\" |
the
root directory of the disk. If NULL - the root of the current
directory is assumed |
SecPCl& |
sectors
per cluster |
BytPSec&
|
bytes
per sector
|
FreeCl& |
number
of free clusters |
TotCl&
|
total
number of clusters |
Check
For Another Instance Of Your App
It
is very simple, just check App.PrevInstance. If it is True,
then another instance is already running, else no other instances
are available.
Wait
Some Time
You have two
choices here - VB code or API.
VB Code:
x!
= Timer
Do Loop While Abs(Timer - x!) <= TimeInSeconds
or API:
Declaration:
Declare
Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As
Long)
to wait some
time call:
Sleep(TimeInMilliSeconds)
Getting
Windows And System Directories
There are two
API functions for doing it - GetWindowsDirectory and GetSystemDirectory.
Here are the declarations:
Declare
Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA"
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA"
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
and the code:
Windows Directory:
S$
= Space(260)
SLen& = GetWindowsDirectory(S$, 260)
MsgBox Left(S$, SLen&)
System Directory:
S$
= Space(260)
SLen& = GetSystemDirectory(S$, 260)
MsgBox Left(S$, SLen&)
So S$
is initialized to be a string of 260 spaces (260 is currently the
MAX length for a path). Then we pass it to the function and tell
her its length as well. The function returns the actual length and
we use it to clip the rest of the string (in fact the string we'll
be something like: C:\WIN95 ... - spaces till 260 len and if you
don't clip the rest after the NULL MsgBox S$ will display
the same result, but MsgBox S$ & "some text" won't.
|