- G -


GetClipCursor Function

Declare Function GetClipCursor Lib "user32.dll" (lprc As RECT) As Long

GetClipCursor finds the current confinement rectangle of the mouse cursor. The cursor is confined to move inside this rectangle. Even a SetCursorPos cannot remove the cursor. If there is no apparent confinement rectangle, it is actually the size of the screen. The rectangle is put into lprc. You can safely ignore the value returned.
lprcReceives the upper-left and lower-right corners of the confinement rectange.
Example:
  'Print the corners of the confinement rectangle.
  Dim r As RECT
  x = GetClipCursor(r)
  Form1.Print r.Left; r.Top 'upper-left (x,y) pair
  Form1.Print r.Right; r.Bottom 'lower-right (x,y) pair


Related Call: ClipCursor
Category: Mouse
Back to the index.


GetComputerName Function

Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

GetComputerName reads the name of the user's computer. I don't know how useful this is, because I haven't found any part of Windows where this value is actually used. But if you want to use it, this is the function. It returns an error code you can safely disregard.
lpBufferA fixed-length string large enough to hold the returned name. It recieves the computer name. The name is followed by vbNullChar.
nSizeThe length in characters of lpBuffer.
Example:
  'Read the computer's name
  Dim compname As String * 255, x As Long
  x = GetComputerName(compname, 255)
  compname = Trim(compname)
  compname = Left(compname, Len(compname) - 1)
  Debug.Print compname


Category: System Information
Back to the index.


GetCursorPos Function

Declare Function GetCursorPos Lib "user32.dll" (ByVal lpPoint As POINTAPI) As Long

GetCursorPos reads the position of the mouse cursor. The x and y coordinates of the mouse are returned inside of lpPoint, and the returned value can safely be ignored.
lpPointReceives the x and y coordinates of the mouse.
Example:
  'Display the coordinates of the mouse
  Dim coord As POINTAPI
  x = GetCursorPos(coord)
  Debug.Print coord.x; coord.y


Related Call: SetCursorPos
Category: Mouse
Back to the index.


GetDC Function

Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long

GetDC returns the device context (DC) of an object. The variable you give the result to will be linked to that object's device context, and will change with it. You can get the device context of many Visual Basic controls by accessing its .hDC property.
hWndThe handle of the object.
Example:
  'The two statements below will return the same value
  Debug.Print Form1.hDC
  x = GetDC(Form1.hWnd)
  Debug.Print x


Related Call: ReturnDC
Catgeory: Devices
Back to the index.


GetDesktopWindow Function

Declare Function GetDesktopWindow Lib "user32.dll" () As Long

GetDesktopWindow returns the handle (hWnd) of the desktop window. The desktop window is the image on your monitor, without the mouse cursor. Use this function to access the screen image. The variable that receives the result is linked with the desktop window's handle and changes with it.

Example:
  desktophWnd = GetDesktopWindow()

Category: System Information
Back to the index.


GetDiskFreeSpace Function

Declare Function GetDiskFreeSpace Lib "kernel32.dll" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long

GetDiskFreeSpace tells you both the free space and total space on a disk, and more! It puts four values into the numeric variables you pass to it. A cluster is the actual unit of storage on a disk drive. A cluster can hold no more than 1 file, but a file can occupy more than one cluster. A sector is a portion of a cluster. You can get the cluster size in bytes by lpSectorsPerCluster * lpBytesPerSector. You get the drive's free space by multiplying the cluster size by lpNumberOfFreeClusters, and the drive's total space by multiplying the cluster size by lpTotalNumberOfClusters. You can safely ignore the value returned.
lpRootPathNameThe root directory of the drive to get information on, such as c:\ or a:\.
lpSectorsPerClusterReceives the number of sectors in a cluster on the disk.
lpBytesPerSectorReceives the number of bytes in a sector on the disk.
lpNumberOfFreeClustersReceives the number of unused, empty clusters on the disk.
lpTotalNumberOfClustersReceives the total number of clusters, used and unused, on the disk.
Example:
  'Find the free space on the hard drive C:
  x = GetDriveFreeSpace("c:\", SectorsPerCluster, BytesPerSector, FreeClusters, TotalClusters)
  Form1.Print "Free space on C:"; SectorsPerCluster * BytesPerSector * FreeClusters; "bytes"


Category: File I/O
Back to the index.


GetDriveType Function

Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

GetDriveType reads the type of a disk drive. This could be a fixed (hard) drive, a floppy drive, a CD-ROM drive, etc. The return value is the drive type. 0 means that the drive type could not be determined for some reason. 1 means that the specified drive does not exist. Other return values are one of the drive type constants.
nDriveThe root directory of the drive to check, such as c:\.
Example:
  'Check to see what type of drive C: is
  x = GetDriveType("c:\")
  'x = DRIVE_FIXED, or hard drive


Category: File I/O
Back to the index.


GetFileAttributes Function

Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA& (ByVal lpFileName As String) As Long

GetFileAttributes returns the attributes of a file or directory. A file's attributes say if the file or directory is an archive (most files are), hidden, read-only, etc. If successful, the return value has one or more file attribute flags set. If a certain flag, for example read-only, is set, And-ing the return value and the constant flag value will result in a non-zero value if the flag is set and 0 if it is not (see the example for details). If the file cannot be found, -1 is returned.
lpFileNameThe full name of the directory or file to check the attributes of. This means that you must include the path.
Example:
  'Check the attributes of c:\windows\sol.exe (Solitaire)
  attribs = GetFileAttributes("C:\Windows\sol.exe")
  If (attribs And FILE_ATTRIBUTES_ARCHIVE) <> 0 Then Form1.Print "Archive "
  If (attribs And FILE_ATTRIBUTES_READONLY) <> 0 Then Form1.Print "Read-only "
  'and so on....


Related Call: SetFileAttributes
Category: File I/O
Back to the index.


GetLocalTime Sub

Declare Sub GetLocalTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)

GetLocalTime returns you system's time and date. It sort of combines the Date$, Time$, and Timer functions because both the date and the time (down to the milliseconds) is returned by this, already sorted within the passed variable! As far as Windows 95 is concerned, "local time" is your system's time.
lpSystemTimeReceives the computer's date and time in absolute format.
Example:
  'Print the date in mm-dd-yyyy format.
  Dim loctime As SYSTEMTIME
  GetLocalTime loctime
  Debug.Print loctime.wMonth; "-"; loctime.wDay; "-"; loctime.wYear


Related Call: GetSystemTime
Category: System Information
Back to the index.


GetOpenFileName Function

Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOPENFILENAME As OPENFILENAME) As Long

GetOpenFileName uses the standard Windows 95 Open File dialog box. While the Common Dialog custom control can be used to do this, using the API is quicker, and you don't need the 70 Kb custom control! You need to set a lot of the parts of pOPENFILENAME for the call to work. The function returns 0 if the user hit the Cancel button. Note that this does not open the file or do anything with it, but merely gives you the filename(s).
pOPENFILENAMEHolds the parameters needed to open the dialog box. Also holds the returned filename(s).
Example:
  'Call the Open File dialog box and read the filename
  Dim file As OPENFILENAME, x As Long, filename As String
  file.hwndOwner = Form1.hWnd 'Calling form's handle
  file.lpstrTitle = "Open File" 'Title bar
  'Set the File Type drop-box values
  file.lpstrFilter = "Text Files" & vbNullChar & "*.txt" & vbNullChar & vbNullChar
  file.lpstrFile = Space(255) 'Path and file buffer
  file.nMaxFile = 255 'Length of buffer
  file.lpstrFileTitle = Space(255) 'File name buffer
  file.nMaxFileTitle = 255 'Length of buffer
  'Only existing files, and hide read-only check box
  file.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
  file.lStructSize = Len(file) 'Variable's size
  x = GetOpenFileName(file)
  If x = 0 Then Exit Sub 'Abort if user hit Cancel
  'Extract the filename
  temp = Trim(file.lpstrFile)
  filename = Left(temp, Len(temp) - 1)


Related Call: GetSaveFileName
Category: Common Dialog
Back to the index.


GetParent Function

Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long

GetParent returns the handle of the parent control of an object. For example, the parent of a command button may be the frame control it is in. The parent of that frame might then be the form. If successful, the function returns the handle of the parent control. If it fails (for example, you try to find the parent of a form), it returns 0.
hwndThe handle of the object you want to find the parent of.
Example:
  'This will work if button Command1 sits "on" form Form1
  Form1.Print GetParent(Command1.hWnd)
  Form1.Print Form1.hWnd 'should be the same value


Related Call: SetParent
Category: Windows
Back to the index.


GetPrivateProfileInt Function

Declare Function GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

GetPrivateProfileInt reads an integer value from any INI file. The parameters you pass to the function specify which value to read. If successful, the function returns the value read. If the value you try to read does not exist or is a string (as opposed to a number), it returns the default value you pass to it.
lpApplicationNameThe header of the INI file section the value is in. The heading is the string in brackets at the top of a section of the file. Do not put the brackets into this string.
lpKeyNameThe name of the value to read. This is the string on the left side of the = sign in the INI file.
nDefaultIf the function fails to read a valid value, this is the value returned. Make it something that wouldn't be returned if successful, such as -1.
lpFileNameThe filename of the INI file to read from.
Example:
  'Read the value for "type" under the [keyboard] section of SYSTEM.INI
  '(This example assumes Windows is in the C:\Windows directory)
  returned = GetPrivateProfileInt("keyboard", "type", -1, "C:\Windows\system.ini")
  If returned = -1 Then
    Form1.Print "Function call failed."
  Else
    Form1.Print returned
  End If


Related Call: GetProfileInt
Category: INI Files
Back to the index.


GetPrivateProfileString Function

Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

GetPrivateProfileString reads a string value from any INI file. The parameters you pass to it specify which value in particular to read. The function always returns the length in characters of the data in the returned string lpReturnedString. If the function was successful, this data will be the string data read from the INI file. If it failed (because the specified file and/or section and/or value doesn't exist), the given default string is used.
lpApplicationNameThe header of the section that the value in the INI file is in. This is the name enclosed in brackets in the INI file. Do not include the brackets with this parameter.
lpKeyNameThe name of the value in the specified section of the INI file to read. This is the name on the left side of the = sign.
lpDefaultThe string to put into lpReturnedString if the function fails to find the specified value.
lpReturnedStringPass a fixed-length string as this. The function will put the returned value into it.
nSizeThe length in characters of lpReturnedString.
lpFileNameThe filename of the INI file to read from.
Example:
  'This example reads the "scrnsave.exe" value from the [boot] section of SYSTEM.INI.
  '(This example assumes the Windows directory is C:\Windows)
  Dim buffer As String * 255
  x = GetPrivateProfileString("boot", "scrnsave.exe", "(not found)", buffer, 255, "c:\windows\system.ini")
  If buffer = "(not found)" Then
    Form1.Print "Screen saver not found."
  Else
    Form1.Print "The screen saver is "; Left(buffer, x)
  End If


Related Calls: GetProfileString, WritePrivateProfileString
Category: INI Files
Back to the index.


GetProfileInt Function

Declare Function GetProfileInt Lib "kernel32.dll" Alias "GetProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Long) As Long

GetProfileInt reads an integer value from the WIN.INI file. The parameters you pass to the function specify which value to read. If successful, the function returns the value read. If the value you try to read does not exist or is a string (as opposed to a number), it returns the default value you pass to it. This is basically a watered-down version of GetPrivateProfileInt, because unlike that function, GetProfileInt only works with WIN.INI.
lpAppNameThe header of the WINDOWS.INI section the value is in. The heading is the string in brackets at the top of a section of the file. Do not put the brackets into this string.
lpKeyNameThe name of the value to read. This is the string on the left side of the = sign in WIN.INI.
nDefaultIf the function fails to read a valid value, this is the value returned. Make it something that wouldn't be returned if successful, such as -1.
Example:
  'Read the value for "WallpaperStyle" under the [Desktop] section of WIN.INI
  returned = GetProfileInt("Desktop", "WallpaperStyle", -1)
  If returned = -1 Then
    Form1.Print "Function call failed."
  Else
    Form1.Print returned
  End If


Related Call: GetPrivateProfileInt
Category: INI Files
Back to the index.


GetProfileString Function

Declare Function GetProfileString Lib "kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long

GetProfileString reads a string value from the WIN.INI file. The parameters you pass to it specify which value in particular to read. The function always returns the length in characters of the data in the returned string lpReturnedString. If the function was successful, this data will be the string data read from WIN.INI. If it failed (because the specified file and/or section and/or value doesn't exist), the given default string is used. This function is basically a watered-down version of GetPrivateProfileString becuae, unlike that function, GetProfileString only works with WIN.INI.
lpAppNameThe header of the section that the value in the INI file is in. This is the name enclosed in brackets in the INI file. Do not include the brackets with this parameter.
lpKeyNameThe name of the value in the specified section of the INI file to read. This is the name on the left side of the = sign.
lpDefaultThe string to put into lpReturnedString if the function fails to find the specified value.
lpReturnedStringPass a fixed-length string as this. The function will put the returned value into it.
nSizeThe length in characters of lpReturnedString.
Example:
  'This example reads the "Wallpaper" value from the [Desktop] section of WIN.INI.
  Dim buffer As String * 255
  x = GetProfileString("Desktop", "Wallpaper", "(not found)", buffer, 255)
  If buffer = "(not found)" Then
    Form1.Print "Wallpaper not found."
  Else
    Form1.Print "The wallpaper is "; Left(buffer, x)
  End If


Related Calls: GetPrivateProfileString, WriteProfileString
Category: INI Files
Back to the index.


GetSaveFileName Function

Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOPENFILENAME As OPENFILENAME) As Long

GetSaveFileName uses the standard Windows 95 Save File dialog box. While the Common Dialog custom control can be used to do this, using the API is quicker, and you don't need the 70 Kb custom control! You need to set a lot of the parts of pOPENFILENAME for the call to work. The function returns 0 if the user hit the Cancel button. Note that this does not save the file or do anything with it, but merely gives you the filename.
pOPENFILENAMEHolds the parameters needed to save the dialog box. Also holds the returned filename.
Example:
  'Call the Save File dialog box and read the filename
  Dim file As OPENFILENAME, x As Long, filename As String
  file.hwndOwner = Form1.hWnd 'Calling form's handle
  file.lpstrTitle = "Save File As" 'Title bar
  'Set the File Type drop-box values
  file.lpstrFilter = "Text Files" & vbNullChar & "*.txt" & vbNullChar & vbNullChar
  file.lpstrFile = Space(255) 'Path and file buffer
  file.nMaxFile = 255 'Length of buffer
  file.lpstrFileTitle = Space(255) 'File name buffer
  file.nMaxFileTitle = 255 'Length of buffer
  file.lpstrDefExt = "txt" 'Default file extension
  'Only existing paths, warn if already exists, and hide read-only check box
  file.flags = OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
  file.lStructSize = Len(file) 'Variable's size
  x = GetSaveFileName(file)
  If x = 0 Then Exit Sub 'Abort if user hit Cancel
  'Extract the filename
  temp = Trim(file.lpstrFile)
  filename = Left(temp, Len(temp) - 1)


Related Call: GetOpenFileName
Category: Common Dialog
Back to the index.


GetSystemDirectory Function

Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

GetSystemDirectory returns the path of Windows's System directory. This is where many important files for Windows are stored, including the API DLL's! Never assume this is "C:\Windows\System" because, while the default, it can be changed at installation. The function returns the length in characters of the result; the string itself is passed to lpBuffer. lpBuffer must be a fixed-length string.
lpBufferA fixed-length string which will receive the path. Make sure it is sufficiently long.
nSizeThe length in characters of lpBuffer.
Example:
  'Get the system directory and extract it to a variable
  Dim buffer As String * 255, syspath As String
  n = GetSystemDirectory(buffer, Len(buffer))
  syspath = Left(buffer, n)


Related Call: GetWindowsDirectory
Category: File I/O
Back to the index.


GetSystemTime Sub

Declare Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)

GetSystemTime returns you system's time and date, but with an unexpected twist -- it does so in Coordinated Universal Time (UTC, formerly Greenwich Mean Time (GMT))! It sort of combines the Date$, Time$, and Timer functions because both the date and the time (down to the milliseconds) is returned by this, already sorted within the passed variable! Basically, "system time" is the current time at the Prime Meridian (assuming your system's clock and time zone are properly set). This would be helpful if your program needs an absolute reference time.
lpSystemTimeReceives the computer's date and time in absolute format.
Example:
  'Print the date in mm-dd-yyyy format.
  '(Since this is UTC time, the date may be different!!!)
  Dim systime As SYSTEMTIME
  GetSystemTime systime
  Debug.Print systime.wMonth; "-"; systime.wDay; "-"; systime.wYear


Related Calls: GetLocalTime
Category: System Information
Back to the index.


GetTempFileName Function

Declare Function GetTempFileName Lib "kernel32.dll" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long

GetTempFileName generates a filename for a temporary file and (sort of) optionally creates it. Temporary files are used to temporarily store data to the hard drive. The full filename, including the path, is put into lpTempFileName. Yes, you actually don't need to pass the length of the string like you normally do! The format of the generated filename is path\xxxuuuu.TMP. path is the path specified. You should use the default Temp directory, gotten from the GetTempPath() API function. xxx is a specified three-character string. uuuu is a hexadecimal number that depends on wUnique. If wUnique is non-zero, uuuu is the rightmost four digits of that number in hexadecimal, and the file is not created. Note that this will work even if a file with that name already exists. If it is zero, Windows generates a hex-string for it guaranteed not to be already used. In this case, Windows also creates the file for you. The file always has a .TMP extension. The function returns the value used for uuuu, in decimal. The example demonstrates how to extract the data from lpTempFileName. One final note: please remember to delete the temporary file when your program is done using it. The Temp directory is always clogged with outdated files left behind by programs.
lpszPathThe path to put the file into. You should use the path gotten from GetTempPath().
lpPrefixStringThe first three characters of this string are used as the first three characters of the filename.
wUniqueIf nonzero, the last four characters of the filename are this number's hexadecimal representation, and the file is not created. If zero, the last four characters are generated by Windows, and the file is created.
lpTempFileNameA fixed-length string that receives the path and filename of the temporary file.
Example:
  'Display a randomly generated temporary filename
  Dim temppathx As String * 255, tempfilex As String * 255
  x = GetTempPath(255, temppath) 'get Windows's Temp directory
  temppath = Left(temppathx, x) 'extract useful data from it
  x = GetTempFileName(temppath, "API", 0, tempfilex
  '**The next line extracts the useful data from the string**
  tempfile = Left$(Trim$(tempfilex), Len(Trim$(tempfilex)) - 1)
  Form1.Print "Temporary filename is:"
  Form1.Print tempfile
  'Filename will be in format (path)\API????.TMP
  'This file also now exists in that path!


Related Call: GetTempPath
Category: File I/O
Back to the index.


GetTempPath Function

Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

GetTempPath finds Windows's default Temp directory. The Temp directory is where temporary files made by and used by Windows-based programs should put their temporary files. Usually this will be the \Temp subdirectory under your Windows directory, but not necessarily. The path of the Temp directory is put into the string passed to the function. The function returns the length of the information in the string.
nBufferLengthThe length in characters of lpBuffer.
lpBufferA fixed-length string that will receive the path of the Temp directory.
Example:
  'Display the Temp directory
  Dim tempdir As String * 255 'more than enough room!
  x = GetTempPath(255, tempdir) 'get the directory
  Form1.Print "The Temp directory is:"
  Form1.Print Left(tempdir, x) 'extract useful information


Related Call: GetTempFileName
Category: File I/O
Back to the index.


GetTimeZoneInformation Function

Declare Function GetTimeZoneInformation Lib "kernel32.dll" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

GetTimeZoneInformation reads the computer's current time zone settings. Since Windows 95 handles the system clock settings, there is usually no need for your programs to know this information. The function returns an error code which can safely be ignored.
lpTimeZoneInformationThe variable which receives the information about the time zone.
Example:
  'Read the name of the standard-time time zone's name
  Dim tzi As TIME_ZONE_INFORMATION, c As Integer, x As Long
  x = GetTimeZoneInformation(tzi)
  For c = 0 To 32
    If tzi.StandardName(c) = 0 Then Exit For
    Debug.Print Chr$(tzi.StandardName(c));
  Next c


Category: System Information
Back to the index.


GetVersionEx Function

Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

GetVersionEx reads information about the version of Windows running the program. This information includes the strict version number and the platform (3.x running Win32s, Windows 95, Windows NT). The actual information is put into the variable passed to the function. You can safely ignore the value returned.
lpVersionInformationReceives the version information. Set the .dwOSVersionInfoSize member to the length of the variable, or Len(lpVersionInformation).
Example:
  'Read the version number of Windows
  Dim os As OSVERSIONINFO
  os.dwOSVersionInfoSize = Len(os) 'Set size of variable
  x = GetVersionEx(os)
  Form1.Print os.dwMajorVersion; "."; os.dwMinorVersion
  'For Windows 95, may print 4 . 0


Category: System Information
Back to the index.


GetWindowRect Function

Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long

GetWindowRect returns the size and position of a window. This information is stored inside a RECT variable. The function puts the coordinates of the upper-left and lower-right corners of the window into the RECT variable. If part of the window is off the screen, those coordinates will be out of the normal range of the resolution (for example, if the left side of a window is off the screen, its Left property will be negative). The returned value can safely be ignored.
hwndThe handle of the window to read the position and width of.
lpRectA RECT variable that will receive the coordinates of the upper-left and lower-right corners of the window.
Example:
  'Find the width and height of Form1 using the GetWindowRect function
  Dim r As RECT
  x = GetWindowRect(Form1.hWnd, r)
  Form1.Print "Width ="; r.Right - r.Left
  Form1.Print "Height ="; r.Bottom - r.Top


Related Call: SetWindowPos
Category: Windows
Back to the index.


GetWindowsDirectory Function

Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

GetWindowsDirectory returns the path of the Windows directory. This is where Windows 95 itself is stored, along with the little applets that come with it. Never assume this is "C:\Windows" because, while the default, it can be changed at installation. The function returns the length in characters of the result; the string itself is passed to lpBuffer. lpBuffer must be a fixed-length string.
lpBufferA fixed-length string which will receive the path. Make sure it is sufficiently long.
nSizeThe length in characters of lpBuffer.
Example:
  'Get the Windows directory and extract it to a variable
  Dim buffer As String * 255, winpath As String
  n = GetWindowsDirectory(buffer, Len(buffer))
  winpath = Left(buffer, n)


Related Call: GetSystemDirectory
Category: File I/O
Back to the index.


GetWindowText Function

Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

GetWindowText reads the .Caption property of a window. While you can easily do this with any objects in your code just by looking at the .Caption property, this function works with any window! If you know the handle of any window, even one in another program, you can read its caption! The function returns the number of meaningful characters in lpString.
hwndThe handle of the window to read the .Caption property of.
lpStringA fixed-length string that will receive the .Caption property value.
cchThe length in characters of lpString.
Example:
  'Read the number of characters in the .Caption of Form1
  n = GetWindowTextLength(Form1.hWnd)
  'Create a string of n+1, to allow for the vbNullChar at the end
  buffer = Space$(n + 1)
  'Read and display the .Caption property
  x = GetWindowText(Form1.hWnd, buffer, n + 1)
  Form1.Print Left$(buffer, x)


Related Calls: GetWindowTextLength, SetWindowText
Category: Windows
Back to the index.


GetWindowTextLength Function

Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

GetWindowTextLength finds the length in characters of a window's .Caption property. This works with any window, not just ones in your program! This function is used in conjunction with GetWindowsText. GetWindowsTextLength returns a number greater than or equal to the length of a window's .Caption property. When you use it, be sure to add 1 to the result because GetWindowText adds a vbNullChar to the end of the returned string.
hwndThe handle of the window to read the length of the .Caption property of.
Example:
  'Read the number of characters in the .Caption of Form1
  n = GetWindowTextLength(Form1.hWnd)
  'Create a string of n+1, to allow for the vbNullChar at the end
  buffer = Space$(n + 1)
  'Read and display the .Caption property
  x = GetWindowText(Form1.hWnd, buffer, n + 1)
  Form1.Print Left$(buffer, x)


Related Call: GetWindowText
Category: Windows
Back to the index.


Home
Paul Kuliniewicz
E-mail: Borg953@aol.com
All material presented on these pages is Copyright © Paul Kuliniewicz, except for other copyrighted material.
http://members.aol.com/Borg953/api/g.html