- S -


SetCursorPos Function

Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long

SetCursorPos moves the position of the mouse cursor. The coordinates are measured in pixels. If you try to put the mouse outside of the screen area (for example, 700,40 on a 640x480 display), it will simply go to the edge of the screen. You can safely ignore the returned value.
xThe x coordinate to move the cursor to.
yThe y coordinate to move the cursor to.
Example:
  x = SetCursorPos(320, 240) 'Center of a 640x480 display

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


SetFileAttributes

Declare Function SetFileAttributes Lib "kernel32.dll" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long

SetFileAttributes changes the attributes of a file or directory. The file attributes you can change are archive, read-only, hidden, and system (other attributes are fixed, such as compressed). Each of these four attributes can be turned on or off. You can safely ignore the error code returned.
lpFileNameThe filename or directory, including its full path, you want to change the attributes of.
dwFileAttributesOne or more of the file attribute flags. FILE_ATTRIBUTE_COMPRESSED and FILE_ATTRIBUTE_DIRECTORY cannot be set.
Example:
  'Hide file c:\apps\data.dat from the user
  x = SetFileAttributes("C:\Apps\data.dat", FILE_ATTRIBUTE_ARCHIVE Or FILE_ATTRIBUTE_HIDDEN)
  'Keep it an archive file to retain its normal access status.


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


SetParent Function

Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

SetParent moves a control from one parent object to another. That's right -- the object itself moves from its original parent to another one. Its relative position is the same (if it was 40 pixels to the right and 50 down from the upper-left corner in the original control, it will be 40 pixels right and 50 down from the upper-left corner in the new control). If successful, the function returns the handle of the parent control from which the control was moved.
hWndChildThe handle of the control you wish to move.
hWndNewParentThe handle of the control to be the new parent of the object.
Example:
  'Moves a button from Frame1 to Frame2
  oldhwnd = SetParent(Command1.hWnd, Frame2.hWnd)
  Form1.Print Frame1.hWnd; oldhwnd 'should be the same


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


SetRect Function

Declare Function SetRect Lib "user32.dll" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

SetRect sets the four member values of a RECT-type variable. This has the same effect as manually setting the .Left, .Top, .Right, and .Bottom settings equal to what you want, but the function takes one line instead of four to do so. You can safely ignore the value returned.
lpRectThe RECT-type variable to set the values of.
X1The value to set the .Left property as.
Y1The value to set the .Top property as.
X2The value to set the .Right property as.
Y2The value to set the .Bottom property as.
Example:
  Dim r As RECT   'How to set a RECT-type variable without SetRect:
  r.Left = 50
  r.Top = 20
  r.Right = 100
  r.Bottom = 70
  'How to do the same using the function
  x = SetRect(r, 50, 20, 100, 70)


Related Call: SetRectEmpty
Category: RECT Manipulation
Back to the index.


SetRectEmpty Function

Declare Function SetRectEmpty Lib "user32.dll" (lpRect As RECT) As Long

SetRectEmpty sets a RECT-type variable to an empty state. This function sets all of the member values of a rectangle to 0. This type of rectangle is considered empty because it has no width nor height. You can safely ignore the value returned.
lpRectThe rectange to set as being empty.
Example:
  'Set rectangle r to an empty state
  Dim r As RECT
  x = SetRectEmpty(r) 'now r.Left = 0 etc.


Related Calls: IsRectEmpty, SetRect
Category: RECT Manipulation
Back to the index.


SetWindowPos Function

Declare Function SetWindowPos Lib "user32.dll" (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

SetWindowPos moves a window to a new location in all three dimensions. You can change its coordinate position as well as its Z-order position (the Z-order says which windows are on top of others). You can also resize the window. This is similar, but much more powerful, to setting a window's .Left, .Top, .Right, .Bottom, and other properties manually. You can safely ignore the value returned.
hwndThe handle of the window to move.
hWndInsertAfterEither the handle of the window to position this window behind, or one of the insert after flags stating where in the Z-order to put the window.
xThe x coordinate of the upper-left corner of the window (the window's .Left property).
yThe y coordinate of the upper-left corner of the window (the window's .Top property).
cxThe x coordinate of the lower-right corner of the window (the window's .Right property).
cyThe y coordinate of the lower-right corner of the window (the window's .Bottom property).
wFlagsZero, one, or more of the SetWindowPos flags stating how to move the window.
Example:
  'Move Form1 to the upper-left corner of the screen, above any other windows.
  flags = SWP_NOSIZE Or SWP_DRAWFRAME 'Do not resize window
  x = SetWindowPos(Form1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, flags)


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


SetWindowText Function

Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

SetWindowText alters the .Caption property of a window. While you could easily do this with objects in your programs, this is also able to change captions in other programs' windows! Obviously with its potential, this function should be used with care so you don't mess up another program. This function returns an error code which can safely be ignored.
hwndThe handle of the window to change the .Caption property of.
lpStringThe text to set as the window's caption.
Example:
  'This changes the caption of button Command1
  x = SetWindowText(Command1.hWnd, "&Push me!")


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


ShowCursor Function

Declare Function ShowCursor Lib "user32.dll" (ByVal bShow As Long) As Long

ShowCursor enables you to show and hide the cursor. This is not done directly, but through incrementing or decrementing a counter. Each function call raises or lowers the counter by 1. If the counter is negative, the cursor is invisible. If it is non-negative (0 or greater), it is visible. Even if the cursor is invisible, it is still able to click buttons and such. The function returns the status of the counter after changing it.
bShowIf this is zero (False), decrement the counter by one. If non-zero (True), increment the counter by one.
Example:
  'This code hides the cursor
  Do
    x = ShowCursor(False) 'False = 0 (VB constant)
  Loop Until x < 0 'if cursor is hidden
  'This code shows the cursor
  Do
    x = ShowCursor(True) 'True = -1 (VB constant)
  Loop Until x >= 0 'if cursor is visible


Category: Mouse
Back to the index.


Sleep Sub

Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Sleep halts program execution for a certain amount of time. This is smaller, more precise, and easier to use than checking Timer through a Do/Loop construct.
dwMillisecondsHow long to halt program execution in milliseconds (1000 milliseconds = 1 second).
Example:
  'Demonstrate Sleep
  Debug.Print "The time is " & Time$
  Sleep 2000 '2-second delay
  Debug.Print "The time is " & Time$


Category: Miscellaneous/Uncategorized
Back to the index.


sndPlaySound Function

Declare Function sndPlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

sndPlaySound plays a .wav file without using the MMControl custom control. If you use the SND_ALIAS flag, it instead plays a Windows sound (chord, system start, etc.). If you use the NO_DEFAULT flag, the function returns 0 if the .wav file is not found and 1 if it is. If you omit it, it always returns 1 and plays the default sound if the .wav file is not found.
lpszSoundNameEither the path and filename of the .wav file, or the alias of the windows sound.
uFlagsZero or more of the sound flags.
Example:
  'Play the file and halt execution until it is finished.
  x = sndPlaySound("c:\windows\chord.wav", SND_FILENAME + SND_SYNC)


Category: Audio
Back to the index.


StretchBlt Function

Declare Function StretchBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

StretchBlt transfers a piece of a graphic image from one object to another. You can resize the dimensions as well as change the size of the chunk. You have to do a manual refresh of the target object (using the object.Refresh method) for the changed image to appear on the screen. You can safely ignore the value returned.
hdcThe device context of the target object.
xThe x coordinate to use as the upper-left corner of the graphic chunk in the target.
yThe y coordinate to use as the upper-left corner of the graphic chunk in the target.
nWidthThe width of the graphic chunk in pixels in the target object.
nHeightThe height of the graphic chunk in pixels in the target object.
hSrcDCThe device context of the source object.
xSrcThe x coordinate of the upper-left corner of the graphic chunk in the source.
ySrcThe y coordinate of the upper-left corner of the graphic chunk in the source.
nSrcWidthThe width of the chunk in the source object.
nSrcWidthThe height of the chunk in the source object.
dwRopA Blt flag telling how to transfer the image.
Example:
  'Copy part of picSource to picTarget, doubling both width and height
  x = StretchBlt(picTarget.hdc, 0, 0, 64, 64, picSource.hdc, 0, 0, 32, 32, SRCCOPY)
  picTarget.Refresh


Related Call: BitBlt
Category: Graphics
Back to the index.


SubtractRect Function

Declare Function SubtractRect Lib "user32.dll" lprcDst As RECT, lprcSrc1 As RECT, lprcSrc2 As RECT) As Long


SubtractRect subtracts a smaller rectangle from a larger one. This is kind of difficult to visualize. The large and small rectangles must intersect completely along one entire side, and neither may extend farther along this side. In other words, they share a common side. Now you see that all of the large rectangle not part of the small rectangle is also a rectangle. This is the rectangle that is defined as the subtraction of the small from the large. If the small rectangle fails to meet these criteria, the subtracted rectangle is set equal to the large rectangle and the function returns 0. If the subtraction is possible, the function returns 1.
lprcDstThe rectangle to be set as the subtraction of the small rectangle from the large one.
lprcSrc1The large rectangle; that is, the rectangle subtracted from.
lprcSrc2The small rectangle; that is, the rectangle subtracted.
Example:
  'big.Left = 50, .Top = 50, .Right = 150, .Bottom = 100
  'small.Left = 50, .Top = 50, .Right = 100, .Bottom = 100
  Dim target As RECT, big As RECT, small As RECT
  x = SetRect(big, 50, 50, 150, 100)
  x = SetRect(small, 50, 50, 100, 100)
  x = SubtractRect(target, big, small) 'target = big - small
  'target.Left = 100, .Top = 50, .Right = 150, .Bottom = 100


Related Calls: IntersectRect, UnionRect
Category: RECT Manipulation
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/s.html