Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
x | The x coordinate to move the cursor to. |
y | The y coordinate to move the cursor to. |
x = SetCursorPos(320, 240) 'Center of a 640x480 display
Declare Function SetFileAttributes Lib "kernel32.dll" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
lpFileName | The filename or directory, including its full path, you want to change the attributes of. |
dwFileAttributes | One or more of the file attribute flags. FILE_ATTRIBUTE_COMPRESSED and FILE_ATTRIBUTE_DIRECTORY cannot be set. |
'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.
Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
hWndChild | The handle of the control you wish to move. |
hWndNewParent | The handle of the control to be the new parent of the object. |
'Moves a button from Frame1 to Frame2
oldhwnd = SetParent(Command1.hWnd, Frame2.hWnd)
Form1.Print Frame1.hWnd; oldhwnd 'should be the same
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
lpRect | The RECT-type variable to set the values of. |
X1 | The value to set the .Left property as. |
Y1 | The value to set the .Top property as. |
X2 | The value to set the .Right property as. |
Y2 | The value to set the .Bottom property as. |
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)
Declare Function SetRectEmpty Lib "user32.dll" (lpRect As RECT) As Long
lpRect | The rectange to set as being empty. |
'Set rectangle r to an empty state
Dim r As RECT
x = SetRectEmpty(r) 'now r.Left = 0 etc.
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
hwnd | The handle of the window to move. |
hWndInsertAfter | Either 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. |
x | The x coordinate of the upper-left corner of the window (the window's .Left property). |
y | The y coordinate of the upper-left corner of the window (the window's .Top property). |
cx | The x coordinate of the lower-right corner of the window (the window's .Right property). |
cy | The y coordinate of the lower-right corner of the window (the window's .Bottom property). |
wFlags | Zero, one, or more of the SetWindowPos flags stating how to move the window. |
'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)
Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
hwnd | The handle of the window to change the .Caption property of. |
lpString | The text to set as the window's caption. |
'This changes the caption of button Command1
x = SetWindowText(Command1.hWnd, "&Push me!")
Declare Function ShowCursor Lib "user32.dll" (ByVal bShow As Long) As Long
bShow | If this is zero (False), decrement the counter by one. If non-zero (True), increment the counter by one. |
'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
Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
dwMilliseconds | How long to halt program execution in milliseconds (1000 milliseconds = 1 second). |
'Demonstrate Sleep
Debug.Print "The time is " & Time$
Sleep 2000 '2-second delay
Debug.Print "The time is " & Time$
Declare Function sndPlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
lpszSoundName | Either the path and filename of the .wav file, or the alias of the windows sound. |
uFlags | Zero or more of the sound flags. |
'Play the file and halt execution until it is finished.
x = sndPlaySound("c:\windows\chord.wav", SND_FILENAME + SND_SYNC)
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
hdc | The device context of the target object. |
x | The x coordinate to use as the upper-left corner of the graphic chunk in the target. |
y | The y coordinate to use as the upper-left corner of the graphic chunk in the target. |
nWidth | The width of the graphic chunk in pixels in the target object. |
nHeight | The height of the graphic chunk in pixels in the target object. |
hSrcDC | The device context of the source object. |
xSrc | The x coordinate of the upper-left corner of the graphic chunk in the source. |
ySrc | The y coordinate of the upper-left corner of the graphic chunk in the source. |
nSrcWidth | The width of the chunk in the source object. |
nSrcWidth | The height of the chunk in the source object. |
dwRop | A Blt flag telling how to transfer the image. |
'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
Declare Function SubtractRect Lib "user32.dll" lprcDst As RECT, lprcSrc1 As RECT, lprcSrc2 As RECT) As Long
lprcDst | The rectangle to be set as the subtraction of the small rectangle from the large one. |
lprcSrc1 | The large rectangle; that is, the rectangle subtracted from. |
lprcSrc2 | The small rectangle; that is, the rectangle subtracted. |
'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
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