You are on page 1of 1705

Windows API Guide

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbshop.com |

Windows API Guide
Last Updated: July 7, 2002
Welcome to the Windows API Guide! Here, you will discover a wealth of information to help you implement calls to the Windows API directly from your Visual Basic programs. This site is sort of a work in progress; it falls short of encompassing the entire Windows API. Nevertheless, new information about functions and the like is added every two or three weeks. Check back often to see what's new!

The New Guru Is Here!
Hello fellow programmers! I'm Chris Pietschmann, and I will be updating this site from now on. There isn't anything new yet, but I'm working on a new format for the site. All the old stuff will remain in the old look, and Only new stuff will have the new look. But I will still update the old stuff.

Reference
The Reference section contains documentation on hundreds of Windows API functions. Besides the functions, information on the related structures and other items also appears for reference. Each function page includes a well-commented example illustrating common usage of the function.

Articles
The Articles section contains articles about API-related topics. These multi-page articles go in-depth about a specific issue in the API and offer a more well-rounded approach to learning about API functions without much technical information. Of course, the reference information for each function is only a click away. Still can't find what you're looking for anywhere on the site? Then try browsing the VB-World.net web site. Along with their sizable collection of Visual Basic programming information, they also have an API programming section filled with helpful articles, some of which cover ideas not currently discussed on this web site.
http://216.26.168.92/vbapi/index.html (1 of 2) [9/1/2002 5:00:02 PM]

Windows API Guide

Still unable to find what you're looking for? You might want to e-mail me about what you're looking for. If I can't give you the information, I might be able to point you in the right direction anyway. Awards the Windows API Guide has won:

Last Modified: March 7, 2002 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/index.html

http://216.26.168.92/vbapi/index.html (2 of 2) [9/1/2002 5:00:02 PM]

Windows API Guide: Reference

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

Windows API Reference
Last Update: March 2, 2001 Important Message
I, Paul Kuliniewicz, am no longer able to continue maintaining this web site. There will be no more updates to this site unless some other party takes over operation. Please read my farewell message for all the details and other information for loyal visitors.

Welcome to the Reference section of the Windows API Guide. Here, you will find documentation on hundreds of API functions and the structures that go along with them. Each API function page includes an example in Visual Basic 5.0 which demonstrates proper usage. The information in the reference section is organized according to what it describes. Please click on a link below. Interested in what has been added or edited since the last update of the Windows API Guide? Take a look at the Revision History of the Reference section! January 21, 2001: A smaller update than usual. The examples on all the Winsock functions have been fixed. The old code could hang if the remote server would stop responding. That bug has been corrected via the ioctlsocket function. Some list box messages have also been added, a function or two that work with screen resolutions, and a number of various error fixes. Sadly, problems with the server prevented me from getting the new search engine ready for this update. It should be up and running next time. Speaking of which, there will be some revisions in the overall layout of the site, which will hopefully aid navigation. Be warned: any bookmarks that point to anything that isn't http://www.vbapi.com/ will probably break, so be prepared.
q

q

q

Function Information: (357 functions listed, 4 newly added) r Alphabetical Listing r Categorical Listing Structure Information: (83 structures listed) r Alphabetical Listing Message Information: (66 messages listed, 6 newly added)

http://216.26.168.92/vbapi/ref/index.html (1 of 2) [9/1/2002 5:00:11 PM]

Windows API Guide: Reference

q

q

q q

Alphabetical Listing r Categorical Listing Callback Function Information: (15 callback functions listed) r Alphabetical Listing Macro Information: (15 macros listed) r Alphabetical Listing Other Reference Information API Glossary
r

Go back to the Windows API Guide home page.

Last Modified: March 2, 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/index.html

http://216.26.168.92/vbapi/ref/index.html (2 of 2) [9/1/2002 5:00:11 PM]

Windows API Guide: Reference: Revision History

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

Windows API Reference: Revision History
The following list identifies which pages have been added or significantly changed in each update of the Windows API Guide's Reference section since February 13, 2000. Added or edited pages are listed according to date and general description (i.e., function pages are grouped together, etc.). Any page that was added in the update is flagged with NEW. Any page that was edited significantly (such as a correction or a layout change) appears in normal text.

January 21, 2001 Update
January 21, 2001: A smaller update than usual. The examples on all the Winsock functions have been fixed. The old code could hang if the remote server would stop responding. That bug has been corrected via the ioctlsocket function. Some list box messages have also been added, a function or two that work with screen resolutions, and a number of various error fixes. Sadly, problems with the server prevented me from getting the new search engine ready for this update. It should be up and running next time. Speaking of which, there will be some revisions in the overall layout of the site, which will hopefully aid navigation. Be warned: any bookmarks that point to anything that isn't http://www.vbapi.com/ will probably break, so be prepared.
q

Functions: r ChangeDisplaySettings NEW r ClosePrinter r closesocket r connect r EnumDisplaySettings NEW r GetProfileInt r htons r ioctlsocket NEW r OpenPrinter r PrinterProperties NEW r recv

http://216.26.168.92/vbapi/ref/history.html (1 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

RegQueryValueEx r send r SetFilePointer r SHGetSpecialFolderLocation r socket Structures: r DEVMODE Messages: r LB_GETCURSEL NEW r LB_GETSEL NEW r LB_GETSELCOUNT NEW r LB_GETSELITEMS NEW r LB_SETCURSEL NEW r LB_SETSEL NEW Other: r Extended Window Styles
r

December 17, 2000 Update
December 17, 2000: Some more Winsock functions have been added, along with a few list box messages. I've also corrected a few minor mistakes on some pages, but I haven't yet been able to fix all the mistakes I've been notified of yet. Hopefully those will be done in time for the next update. Finally, I'm still working on the search engine for the site. Most of it is done, but it still needs some more testing and security checking before I add it to the site.
q

Functions: r closesocket NEW r connect NEW r DestroyWindow r FindWindow r FindWindowEx r GetFocus NEW r GetSaveFileName r htonl r htons NEW r KillTimer r LockWorkStation NEW r recv NEW r RemoveMenu NEW

http://216.26.168.92/vbapi/ref/history.html (2 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

send NEW r SetFocus NEW r SetTimer r SHFileOperation r socket NEW Structures: r HOSTENT r SOCKADDR NEW Messages: r EM_GETPASSWORDCHAR r LB_ADDSTRING NEW r LB_DELETESTRING NEW r LB_GETCOUNT NEW r LB_GETTEXT NEW r LB_GETTEXTLEN NEW r LB_INSERTSTRING NEW r LB_RESETCONTENT NEW r WM_CLOSE NEW r WM_TIMER
r

October 29, 2000 Update
October 29, 2000: I've finally added a few Winsock API functions, at popular request. Also making an appearance are the CreateWindowEx function and information about the IP Address control. Finally, I've moved window class information into its own small section.
q

Functions: r CreateWindowEx NEW r DestroyWindow NEW r GetClassLong r gethostbyaddr NEW r gethostbyname NEW r gethostname NEW r GetWindowLong r htonl NEW r inet_addr NEW r inet_ntoa NEW r InitCommonControlsEx NEW

http://216.26.168.92/vbapi/ref/history.html (3 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

q

q

SendInput r SetWindowLong r WSACleanup NEW r WSAGetLastError NEW r WSAStartup NEW Structures: r ENUMLOGFONTEX r HOSTENT NEW r INITCOMMONCONTROLSEX_TYPE NEW r WSADATA NEW Messages: r BM_CLICK r IPM_CLEARADDRESS NEW r IPM_GETADDRESS NEW r IPM_ISBLANK NEW r IPM_SETADDRESS NEW r IPM_SETFOCUS NEW r IPM_SETRANGE NEW Macros: r FIRST_IPADDRESS NEW r FOURTH_IPADDRESS NEW r HIBYTE NEW r LOBYTE NEW r MAKEIPRANGE NEW r MAKELANGID r MAKEWORD NEW r SECOND_IPADDRESS NEW r THIRD_IPADDRESS NEW Window Classes: r Base Window Styles NEW r Button Control Window Class NEW r Combo Box Control Window Class NEW r Edit Control Window Class NEW r Extended Window Styles NEW r IP Address Control Window Class NEW r List Box Control Window Class NEW r Scroll Bar Control Window Class NEW r Static Control Window Class NEW Other:
r

http://216.26.168.92/vbapi/ref/history.html (4 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History
r

Winsock error codes NEW

September 24, 2000 Update
September 24, 2000: Starting today, I'm going to write a short message like this in each update. For all of you who've asked me about how to get a list of the currently running processes on the system, your prayers have been answered. At least, the prayers about getting a list of processes on the system.... Anyway, you'll want to look at CreateToolhelp32Snapshot for that. I also added, among other things, SetWindowRgn, needed to make nonrectangular-looking windows. For the complete list of new goodies, go to the history page.
q

q

q

q

Functions: r CreateToolhelp32Snapshot NEW r GetDiskFreeSpaceEx r GetOpenFileName r GetSaveFileName r GetSysColor NEW r GetWindowRgn NEW r Process32First NEW r Process32Next NEW r RegDeleteKey r RegEnumValue r SetSysColors NEW r SetWindowRgn NEW Structures: r OPENFILENAME r PROCESSENTRY32 NEW Messages: r CB_ADDSTRING NEW r CB_DELETESTRING NEW r CB_INSERTSTRING NEW r CB_RESETCONTENT NEW Callback Functions: r OFNHookProc NEW r OFNHookProcOldStyle NEW

August 26, 2000 Update
http://216.26.168.92/vbapi/ref/history.html (5 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History
q

q

q

q

Functions: r GetCapture r GetEnvironmentVariable NEW r mouse_event r QueryPerformanceCounter NEW r QueryPerformanceFrequency NEW r SendInput r SetEnvironmentVariable NEW r ShellExecute r ShellExecuteEx NEW r WaitForSingleObject NEW Structures: r ITEMIDLIST r JOB_INFO_1 r LARGE_INTEGER NEW r LOGFONT r SHELLEXECUTEINFO NEW Messages: r EM_CANUNDO NEW r EM_GETFIRSTVISIBLELINE NEW r EM_GETLINE NEW r EM_LINEINDEX NEW r EM_LINELENGTH NEW r EM_UNDO NEW MCI Commands: r open

July 30, 2000 Update
q

Functions: r EqualRgn r GetAsyncKeyState r GetFileVersionInfo NEW r GetFileVersionInfoSize NEW r GetKeyState r RegCloseKey r RegCreateKeyEx r RegisterClassEx

http://216.26.168.92/vbapi/ref/history.html (6 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

RegQueryValueEx r SetTimer r VerQueryValue NEW Structures: r VS_FIXEDFILEINFO NEW Messages: r BM_CLICK NEW r BM_GETCHECK NEW r BM_GETSTATE NEW r BM_SETCHECK NEW r BM_SETSTATE NEW Macros: r GET_X_LPARAM r GET_Y_LPARAM r HIWORD r LOWORD
r

July 4, 2000 Update
q

q

q

Functions: r ExitWindowsDialog NEW r GetShortPathName r mciGetErrorString NEW r mciSendString NEW r RestartDialog NEW Messages: r MM_MCINOTIFY NEW MCI Command Strings: r close NEW r open NEW r pause NEW r play NEW r stop NEW

June 4, 2000 Update
q

Functions: r CreatePopupMenu NEW

http://216.26.168.92/vbapi/ref/history.html (7 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

DestroyMenu NEW r GetMenu NEW r GetMenuItemCount NEW r GetMenuItemInfo NEW r GetSystemMenu NEW r GetVolumeInformation r InsertMenuItem NEW r PickIconDlg NEW r SetMenuItemInfo NEW r TrackPopupMenu NEW r TrackPopupMenuEx NEW Structures: r MENUITEMINFO NEW r RECT r TPMPARAMS NEW Messages: r WM_COMMAND NEW r WM_INITMENU NEW r WM_SYSCOMMAND NEW Macros: r HIWORD NEW r LOWORD NEW
r

May 21, 2000 Update
q

q

Functions: r GetCapture NEW r KillTimer NEW r RegEnumValue r ReleaseCapture NEW r SetCapture NEW r SetTimer NEW r SHFileOperation Messages: r EM_GETPASSWORDCHAR NEW r EM_GETSEL NEW r EM_REPLACESEL NEW r EM_SETPASSWORDCHAR NEW

http://216.26.168.92/vbapi/ref/history.html (8 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

EM_SETSEL NEW r WM_TIMER NEW Callback Functions: r TimerProc NEW Macros: r MAKELANGID
r

April 16, 2000 Update
q

q

q

q

Functions: r GetCurrencyFormat NEW r GetNumberFormat NEW r GetVolumeInformation NEW r RoundRect r SetVolumeLabel NEW r SHFileOperation NEW r SHFreeNameMappings NEW Structures: r CURRENCYFMT NEW r MEMORYSTATUSEX r NUMBERFMT NEW r SHFILEOPSTRUCT NEW r SHNAMEMAPPING NEW Messages: r CB_GETCOUNT NEW r CB_GETCURSEL NEW r CB_GETDROPPEDSTATE NEW r CB_GETLBTEXT NEW r CB_GETLBTEXTLEN NEW r CB_SETCURSEL NEW r CB_SHOWDROPDOWN NEW Macros: r MAKELCID NEW

March 19, 2000 Update
q

Functions: r CreateDirectory

http://216.26.168.92/vbapi/ref/history.html (9 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

q

CreateDirectoryEx r GetAsyncKeyState r GetDiskFreeSpaceEx r GetTickCount NEW r GlobalMemoryStatus NEW r GlobalMemoryStatusEx NEW r RegEnumKeyEx r SendInput r Shell_NotifyIcon NEW Structures: r MEMORYSTATUS NEW r MEMORYSTATUSEX NEW r NOTIFYICONDATA NEW r POINT_TYPE r ULARGE_INTEGER Messages: r WM_LBUTTONDBLCLK NEW r WM_LBUTTONDOWN NEW r WM_LBUTTONUP NEW r WM_MBUTTONDBLCLK NEW r WM_MBUTTONDOWN NEW r WM_MBUTTONUP NEW r WM_MOUSEMOVE NEW r WM_RBUTTONDBLCLK NEW r WM_RBUTTONDOWN NEW r WM_RBUTTONUP NEW Macros: r GET_X_LPARAM NEW r GET_Y_LPARAM NEW r MAKELANGID r MAKEPOINTS NEW Other: r Error Codes
r

February 13, 2000 Update
q

Functions: r GetWindowText

http://216.26.168.92/vbapi/ref/history.html (10 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Revision History

q

q

q

q

GetWindowTextLength r MessageBox NEW r MessageBoxEx NEW r MessageBoxIndirect NEW r SetWindowText Structures: r HELPINFO NEW r MSGBOXPARAMS NEW Messages: r WM_GETTEXT NEW r WM_GETTEXTLENGTH NEW r WM_HELP NEW r WM_SETTEXT NEW Callback Functions: r MsgBoxCallback NEW Macros: r MAKELANGID NEW
r

Go back to the Reference section index.

Last Modified: January 21, 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/history.html

http://216.26.168.92/vbapi/ref/history.html (11 of 11) [9/1/2002 5:00:21 PM]

Windows API Guide: Reference: Functions

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

Windows API Reference: Functions
Last Update: January 21, 2001 Number of Functions Listed: 357 (4 added)
Below is an alphabetical list of the API functions currently documented on this web site. Please keep in mind that this site does not encompass the entire API yet, so unfortunately may not find what you are looking for. To suggest any additions you would like to see made, please contact the author with your request. All pages added since the last update of this site are clearly marked with NEW. Jump to: A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

q

A
r r r r r r r

AngleArc Arc ArcTo auxGetDevCaps auxGetNumDevs auxGetVolume auxSetVolume Beep BitBlt BringWindowToTop CallWindowProc ChangeDisplaySettings NEW CharLower CharUpper ChooseColor ChooseFont

q

B
r r r

q

C
r r r r r r

http://216.26.168.92/vbapi/ref/funca.html (1 of 11) [9/1/2002 5:00:52 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r q

Chord ClipCursor CloseHandle ClosePrinter closesocket CombineRgn CommDlgExtendedError CompareFileTime CompareString connect CopyFile CopyMemory CopyRect CoTaskMemFree CreateCursor CreateDC CreateDirectory CreateDirectoryEx CreateEllipticRgn CreateEllipticRgnIndirect CreateFile CreateFont CreateFontIndirect CreateHatchBrush CreatePen CreatePenIndirect CreatePolygonRgn CreatePolyPolygonRgn CreatePopupMenu CreateRectRgn CreateRectRgnIndirect CreateRoundRectRgn CreateSolidBrush CreateToolhelp32Snapshot CreateWindowEx DefWindowProc DeleteDC DeleteFile

D
r r r

http://216.26.168.92/vbapi/ref/funca.html (2 of 11) [9/1/2002 5:00:52 PM]

Windows API Guide: Reference: Functions
r r r r r r r q

DeleteObject DestroyCursor DestroyIcon DestroyMenu DestroyWindow DrawIcon DrawIconEx Ellipse EnableWindow EndDoc EndPage EnumChildWindows EnumDisplaySettings NEW EnumFontFamilies EnumFontFamiliesEx EnumJobs EnumPrinters EnumPropsEx EnumThreadWindows EnumWindows EqualRect EqualRgn ExitWindowsDialog ExitWindowsEx ExtFloodFill ExtractIcon ExtractIconEx FileTimeToLocalFileTime FileTimeToSystemTime FillMemory FillRect FillRgn FindClose FindFirstFile FindNextFile FindWindow FindWindowEx

E
r r r r r r r r r r r r r r r r r r r r

q

F
r r r r r r r r r r

http://216.26.168.92/vbapi/ref/funca.html (3 of 11) [9/1/2002 5:00:52 PM]

Windows API Guide: Reference: Functions
r r r q

FlashWindow FrameRect FrameRgn GetActiveWindow GetArcDirection GetAsyncKeyState GetBrushOrgEx GetCapture GetClassInfo GetClassInfoEx GetClassLong GetClassName GetClipCursor GetComputerName GetCurrencyFormat GetCursor GetCursorPos GetDateFormat GetDC GetDesktopWindow GetDiskFreeSpace GetDiskFreeSpaceEx GetDoubleClickTime GetDriveType GetEnvironmentVariable GetFileAttributes GetFileInformationByHandle GetFileSize GetFileTime GetFileVersionInfo GetFileVersionInfoSize GetFocus GetForegroundWindow GetFullPathName gethostbyaddr gethostbyname gethostname GetKeyboardState

G
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r

http://216.26.168.92/vbapi/ref/funca.html (4 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r

GetKeyState GetLastError GetLocalTime GetLogicalDrives GetLogicalDriveStrings GetMenu GetMenuItemCount GetMenuItemInfo GetNumberFormat GetOpenFileName GetParent GetPixel GetPolyFillMode GetPrivateProfileInt GetPrivateProfileString GetProfileInt GetProfileString GetProp GetRgnBox GetSaveFileName GetShortPathName GetStockObject GetSysColor GetSystemDirectory GetSystemMenu GetSystemMetrics GetSystemTime GetSystemTimeAsFileTime GetTempFileName GetTempPath GetTextAlign GetThreadLocale GetTickCount GetTimeFormat GetTimeZoneInformation GetTopWindow GetUserName GetVersionEx

http://216.26.168.92/vbapi/ref/funca.html (5 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r r r r r q

GetVolumeInformation GetWindow GetWindowLong GetWindowRect GetWindowsDirectory GetWindowRgn GetWindowText GetWindowTextLength GetWindowThreadProcessId GlobalAlloc GlobalFree GlobalLock GlobalMemoryStatus GlobalMemoryStatusEx GlobalUnlock htonl htons inet_addr inet_ntoa InflateRect InitCommonControlsEx InsertMenuItem IntersectRect InvertRect InvertRgn ioctlsocket NEW IsChild IsIconic IsRectEmpty IsWindow IsWindowEnabled IsZoomed joyGetDevCaps joyGetNumDevs joyGetPos

H
r r

q

I
r r r r r r r r r r r r r r r

q

J
r r r

q

K

http://216.26.168.92/vbapi/ref/funca.html (6 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r q

keybd_event KillTimer LineTo LoadCursor LoadCursorFromFile LocalFileTimeToFileTime LockWorkStation lstrcmp lstrcmpi lstrcpy lstrcpyn lstrlen mciGetErrorString mciSendString MessageBeep MessageBox MessageBoxEx MessageBoxIndirect mouse_event MoveFile MoveMemory MoveToEx MoveWindow MulDiv

L
r r r r r r r r r r

q

M
r r r r r r r r r r r r

q q

N O
r r r

OffsetRect OffsetRgn OpenPrinter PickIconDlg Pie PlaySound PolyBezier PolyBezierTo Polygon Polyline

q

P
r r r r r r r

http://216.26.168.92/vbapi/ref/funca.html (7 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r q

PolylineTo PolyPolygon PolyPolyline PrintDlg PrinterProperties NEW Process32First Process32Next PtInRect PtInRegion QueryPerformanceCounter QueryPerformanceFrequency ReadFile Rectangle RectInRegion recv RegCloseKey RegCreateKeyEx RegDeleteKey RegDeleteValue RegEnumKeyEx RegEnumValue RegisterClass RegisterClassEx RegOpenKeyEx RegQueryValueEx RegSetValueEx ReleaseCapture ReleaseDC RemoveDirectory RemoveMenu RemoveProp RestartDialog RoundRect SelectObject send SendInput

Q
r r

q

R
r r r r r r r r r r r r r r r r r r r r r r

q

S
r r r

http://216.26.168.92/vbapi/ref/funca.html (8 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r

SendMessage SetActiveWindow SetArcDirection SetBrushOrgEx SetCapture SetClassLong SetCursor SetCursorPos SetDoubleClickTime SetEnvironmentVariable SetFileAttributes SetFilePointer SetFileTime SetFocus SetForegroundWindow SetKeyboardState SetLastError SetLastErrorEx SetMenuItemInfo SetParent SetPixel SetPixelV SetPolyFillMode SetProp SetRect SetRectEmpty SetSysColors SetSystemCursor SetSystemTime SetTextAlign SetThreadLocale SetTimer SetVolumeLabel SetWindowLong SetWindowPos SetWindowRgn SetWindowText SHAddToRecentDocs

http://216.26.168.92/vbapi/ref/funca.html (9 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r r r r r r r r r r r r r r r r r q

SHBrowseForFolder Shell_NotifyIcon ShellExecute ShellExecuteEx SHEmptyRecycleBin SHFileOperation SHFreeNameMappings SHGetFileInfo SHGetFolderLocation SHGetFolderPath SHGetPathFromIDList SHGetSpecialFolderLocation SHGetSpecialFolderPath ShowCursor ShowWindow SHQueryRecycleBin SHUpdateRecycleBinIcon Sleep sndPlaySound socket StartDoc StartPage StretchBlt SubtractRect SwapMouseButton SystemParametersInfo SystemTimeToFileTime TextOut TrackPopupMenu TrackPopupMenuEx UnionRect UnregisterClass VerQueryValue WaitForSingleObject waveOutGetDevCaps

T
r r r

q

U
r r

q

V
r

q

W
r r

http://216.26.168.92/vbapi/ref/funca.html (10 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: Reference: Functions
r r r r r r r r r r r q q q

waveOutGetNumDevs waveOutGetVolume waveOutSetVolume WindowFromPoint WinHelp WriteFile WritePrivateProfileString WriteProfileString WSACleanup WSAGetLastError WSAStartup

X Y Z
r

ZeroMemory

Go back to the Reference section index.

Last Modified: January 21, 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/funca.html

http://216.26.168.92/vbapi/ref/funca.html (11 of 11) [9/1/2002 5:00:53 PM]

Windows API Guide: AngleArc Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

AngleArc Function
Declare Function AngleArc Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single, ByVal eSweepAngle As Single) As Long

Platforms
q q q q q

Windows 95: Not Supported Windows 98: Not Supported Windows NT: Requires Windows NT 3.1 or greater Windows 2000: Supported Windows CE: Not Supported

Description & Usage
AngleArc draws a circular arc on a device using the device's current pen. The circle which the arc lies on is determined by its center and radius. The start and end points of the arc are determined by angle measures in degrees, measured counterclockwise from the line parallel to the positive x-axis (i.e., from due right). The arc itself is drawn either clockwise or counterclockwise to connect the points, depending on the device's settings. AngleArc also draws a line connecting the device's current point to the beginning of the arc.

Return Value
If an error occurs, the function returns 0 (call GetLastError to get the error code). If the function succeeds, the function returns a non-zero value.

Visual Basic-Specific Issues
None

Parameters
hdc A handle to a device context of the device to draw the arc on. x The x coordinate of the center of the circle. y The y coordinate of the center of the circle.
http://216.26.168.92/vbapi/ref/a/anglearc.html (1 of 3) [9/1/2002 5:03:05 PM]

Windows API Guide: AngleArc Function

dwRadius The radius of the circle. eStartAngle The angle (in degrees) identifying the starting point of the arc. eSweepAngle The angle (in degrees) identifying the ending point of the arc.

Example
' This code is licensed according to the terms and conditions listed here. ' Draw an arc formed by the upper half of a circle (from 0 to 180 ' degrees counterclockwise). The circle is centered at (100, 150) and has a radius ' of 50. The arc is drawn using the solid black stock pen. Dim hpen As Long ' handle to the black stock pen Dim holdpen As Long ' handle to Form1's previously selected pen Dim retval As Long ' return value ' Get the solid black stock pen and select it for use in Form1. hpen = GetStockObject(BLACK_PEN) ' get the pen's handle holdpen = SelectObject(Form1.hDC, hpen) ' select the pen ' Make retval ' Draw retval sure arcs are drawn going counterclockwise = SetArcDirection(Form1.hDC, AD_COUNTERCLOCKWISE) the arc = AngleArc(Form1.hDC, 100, 150, 50, 0, 180)

' Select Form1's previous pen to restore the "defaults". retval = SelectObject(Form1.hDC, holdpen) ' select the old pen

See Also
Arc, ArcTo, Ellipse, GetArcDirection, SetArcDirection

Category
Lines & Curves Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 27, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail
http://216.26.168.92/vbapi/ref/a/anglearc.html (2 of 3) [9/1/2002 5:03:05 PM]

Windows API Guide: AngleArc Function

This page is at http://www.vbapi.com/ref/a/anglearc.html

http://216.26.168.92/vbapi/ref/a/anglearc.html (3 of 3) [9/1/2002 5:03:05 PM]

Windows API Guide: Arc Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

Arc Function
Declare Function Arc Lib "gdi32.dll" (ByVal hdc As Long, ByVal nLeftRect As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, ByVal nBottomRect As Long, ByVal nXStartArc As Long, ByVal nYStartArc As Long, ByVal nXEndArc As Long, ByVal nYEndArc As Long) As Long

Platforms
q q q q q

Windows 95: Supported Windows 98: Supported Windows NT: Requires Windows NT 3.1 or later Windows 2000: Supported Windows CE: Not Supported

Description & Usage
Arc draws an elliptical arc on a device using the device's current pen. The ellipse which the arc lies on is inscribed within the bounding rectangle coordinates passed to the function. The start and end points are determined by two radials. The radials begin at the center of the ellipse and extend through the given radial point (either the start or end one); where they intersect the ellipse is where the start and end points of the arc are. Windows 95/98: The arc is always drawn counterclockwise from the start point to the end point. Windows NT/2000: The direction the arc is drawn in depends on the device's current setting.

Return Value
If an error occured while attempting to draw the arc, the function returns 0 (Win NT/2000: call GetLastError to get the errror code). If the function completed successfully, it returns a non-zero value.

Visual Basic-Specific Issues
None.

Parameters
hdc A handle to a device context of the device to draw the arc on. nLeftRect The x coordinate of the upper-left point of the ellipse's bounding rectangle. nTopRect The y coordinate of the upper-left point of the ellipse's bounding rectangle.
http://216.26.168.92/vbapi/ref/a/arc.html (1 of 3) [9/1/2002 5:03:24 PM]

Windows API Guide: Arc Function

nRightRect The x coordinate of the lower-right point of the ellipse's bounding rectangle. nBottomRect The y coordinate of the lower-right point of the ellipse's bounding rectangle. nXStartArc The x coordinate of the radial point that determines the arc's starting point. nYStartArc The y coordinate of the radial point that determines the arc's starting point. nXEndArc The x coordinate of the radial point that determines the arc's ending point. nYEndArc The y coordinate of the radial point that determines the arc's ending point.

Example
' This code is licensed according to the terms and conditions listed here. ' Draw the arc that forms the top half of an ellipse. The ellipse ' is centered at (100, 100), has a width of 200, and has a height of 100. drawn ' on window Form1 using the black solid stock pen. Dim hpen As Long ' handle to the black solid pen Dim holdpen As Long ' handle to window Form1's previously selected pen Dim retval As Long ' return value ' Get a handle to the solid black pen and set it as Form1's drawing pen. hpen = GetStockObject(BLACK_PEN) ' get a handle to the pen holdpen = SelectObject(Form1.hDC, hpen) ' set it as Form1's current pen ' The ellipse is determined by the bounding rectangle (0,50)-(200,150). ' The radial to (200, 100) is due right; the radial to (0, 100) is due left. retval = Arc(Form1.hDC, 0, 50, 200, 150, 200, 100, 0, 100) ' Restore Form1's previous pen selection. retval = SelectObject(Form1.hDC, holdpen)

The arc is

' set the old pen back

See Also
AngleArc, ArcTo, Ellipse, GetArcDirection, SetArcDirection

Category
Lines & Curves Go back to the alphabetical Function listing. Go back to the Reference section index.

http://216.26.168.92/vbapi/ref/a/arc.html (2 of 3) [9/1/2002 5:03:24 PM]

Windows API Guide: Arc Function

Last Modified: July 27, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/a/arc.html

http://216.26.168.92/vbapi/ref/a/arc.html (3 of 3) [9/1/2002 5:03:24 PM]

Windows API Guide: ArcTo Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

ArcTo Function
Declare Function ArcTo Lib "gdi32.dll" (ByVal hdc As Long, ByVal nLeftRect As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, ByVal nBottomRect As Long, ByVal nXRadial1 As Long, ByVal nYRadial1 As Long, ByVal nXRadial2 As Long, ByVal nYRadial2 As Long) As Long

Platforms
q q q q q

Windows 95: Not Supported Windows 98: Not Supported Windows NT: Requires Windows NT 3.1 or later Windows 2000: Supported Windows CE: Not Supported

Description & Usage
ArcTo draws an elliptical arc on a device using the device's current pen. After drawing the arc, the device's current point is set to the end point of the arc. The ellipse which the arc lies on is inscribed within the bounding rectangle coordinates passed to the function. The start and end points are determined by two radials. The radials begin at the center of the ellipse and extend through the given radial point (either the start or end one); where they intersect the ellipse is where the start and end points of the arc are. The direction the arc is drawn in depends on the device's current setting.

Return Value
If an error occured while attempting to draw the arc, the function returns 0 (call GetLastError to get the error code). If the function completed successfully, it returns a non-zero value.

Visual Basic-Specific Issues
None.

Parameters
hdc A handle to a device context of the device to draw the arc on. nLeftRect The x coordinate of the upper-left point of the ellipse's bounding rectangle. nTopRect The y coordinate of the upper-left point of the ellipse's bounding rectangle.
http://216.26.168.92/vbapi/ref/a/arcto.html (1 of 3) [9/1/2002 5:03:31 PM]

Windows API Guide: ArcTo Function

nRightRect The x coordinate of the lower-right point of the ellipse's bounding rectangle. nBottomRect The y coordinate of the lower-right point of the ellipse's bounding rectangle. nXRadial1 The x coordinate of the radial point that determines the arc's starting point. nYRadial1 The y coordinate of the radial point that determines the arc's starting point. nXRadial2 The x coordinate of the radial point that determines the arc's ending point. nYRadial2 The y coordinate of the radial point that determines the arc's ending point.

Example
' This code is licensed according to the terms and conditions listed here. ' Draw the arc that forms the top half of an ellipse. The ellipse ' is centered at (100, 100), has a width of 200, and has a height of 100. drawn ' on window Form1 using the black solid stock pen. Dim hpen As Long ' handle to the black solid pen Dim holdpen As Long ' handle to window Form1's previously selected pen Dim retval As Long ' return value ' Get a handle to the solid black pen and set it as Form1's drawing pen. hpen = GetStockObject(BLACK_PEN) ' get a handle to the pen holdpen = SelectObject(Form1.hDC, hpen) ' set it as Form1's current pen ' The ellipse is determined by the bounding rectangle (0,50)-(200,150). ' The radial to (200, 100) is due right; the radial to (0, 100) is due left. retval = ArcTo(Form1.hDC, 0, 50, 200, 150, 200, 100, 0, 100) ' Restore Form1's previous pen selection. retval = SelectObject(Form1.hDC, holdpen)

The arc is

' set the old pen back

See Also
AngleArc, Arc, Ellipse, GetArcDirection, SetArcDirection

Category
Lines & Curves Go back to the alphabetical Function listing. Go back to the Reference section index.

http://216.26.168.92/vbapi/ref/a/arcto.html (2 of 3) [9/1/2002 5:03:31 PM]

26. 2000 Go back to the Windows API Guide home page. 1999 This page is copyright © 1999 Paul Kuliniewicz.168.vbapi.com Send Encrypted E-Mail This page is at http://www.html http://216. E-mail: vbapi@vbapi.com/ref/a/arcto.92/vbapi/ref/a/arcto. Copyright Information Revised October 29.Windows API Guide: ArcTo Function Last Modified: July 27.html (3 of 3) [9/1/2002 5:03:31 PM] .

com | auxGetDevCaps Function Declare Function auxGetDevCaps Lib "winmm. if one exists. Windows CE: Not Supported. Description & Usage auxGetDevCaps retrieves information about the capabilities of an auxiliary audio device.vbapi. lpCaps As AUXCAPS.part of the VB-World Network | www.dll" Alias "auxGetDevCapsA" (ByVal uDeviceID As Long.com . ByVal cbCaps As Long) As Long Platforms q q q q q Windows 95: Supported.vbsquare. lpCaps http://216. Valid IDs range from 0 to the total number of auxiliary audio devices minus one.vbworld.vb-shop.com | www.1 or later. Windows NT: Requires Windows NT 3.Windows API Guide: auxGetDevCaps Function vbapi.html (1 of 3) [9/1/2002 5:03:35 PM] . If successful. This function can also retrieve capabilities information about the auxiliary audio mapper.com | www. the function returns 0. Parameters uDeviceID The device ID of the auxiliary audio device.com | www. Windows 98: Supported. Visual Basic-Specific Issues None.92/vbapi/ref/a/auxgetdevcaps. the function returns a non-zero error code.26. This could also be the following flag: AUX_MAPPER Retrieve information about the capabilities of the auxiliary audio mapper.com | www.168. Return Value If an error occured.vbforums. Windows 2000: Supported.

Len(auxinfo)) If retval = 0 Then Debug.Print "** AUXILIARY AUDIO DEVICE".html (2 of 3) [9/1/2002 5:03:35 PM] . ". ' Loop through each auxiliary audio device installed on the system ' and display its name and version number. majver. c. "**" ' Extract and display the name of the device.Windows API Guide: auxGetDevCaps Function Receives information about the device's capabilities.Print "Version Number:". c.1) Debug.vDriverVersion And &HFF ' minor version Debug.szPname. minver As Integer ' major and minor version numbers Dim c As Long ' counter variable Dim retval As Long ' return value ' Find out how many auxiliary audio devices are installed.26.Print "Could not get information about device". InStr(auxinfo. devname ' Extract and display the version number of the device. Dim auxinfo As AUXCAPS ' receives info about each device Dim numdevs As Long ' number of auxiliary audio devices installed Dim devname As String ' name of device Dim majver As Integer.szPname." End If Next c Category http://216. ".". Constant Definitions Const AUX_MAPPER = -1 Example ' This code is licensed according to the terms and conditions listed here. numdevs = auxGetNumDevs() ' Loop through each one. cbCaps The size in bytes of the structure passed as lpCaps. minver Else Debug. devname = Left(auxinfo. retval = auxGetDevCaps(c.vDriverVersion And &HFF00) / &H100 ' major version minver = auxinfo. For c = 0 To numdevs .168.Print "Name: ". displaying its name and version number.1 ' remember that device IDs are zero-based! ' Get the capabilities of this device. auxinfo.92/vbapi/ref/a/auxgetdevcaps. majver = (auxinfo. vbNullChar) .

Windows API Guide: auxGetDevCaps Function

Audio Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: September 6, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/a/auxgetdevcaps.html

http://216.26.168.92/vbapi/ref/a/auxgetdevcaps.html (3 of 3) [9/1/2002 5:03:35 PM]

Windows API Guide: auxGetNumDevs Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

auxGetNumDevs Function
Declare Function auxGetNumDevs Lib "winmm.dll" () As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
auxGetNumDevs determines how many auxiliary audio devices are installed on the computer. This could be less than the number of devices actually present on the computer, since it is possible for a device to be installed yet not be connected or functioning.

Return Value
The function returns the number of auxiliary audio devices installed on the system.

Visual Basic-Specific Issues
None.

Parameters
None.

Example
' This code is licensed according to the terms and conditions listed here.
http://216.26.168.92/vbapi/ref/a/auxgetnumdevs.html (1 of 3) [9/1/2002 5:03:41 PM]

Windows API Guide: auxGetNumDevs Function

' Loop through each auxiliary audio device installed on the system ' and display its name and version number. Dim auxinfo As AUXCAPS ' receives info about each device Dim numdevs As Long ' number of auxiliary audio devices installed Dim devname As String ' name of device Dim majver As Integer, minver As Integer ' major and minor version numbers Dim c As Long ' counter variable Dim retval As Long ' return value ' Find out how many auxiliary audio devices are installed. numdevs = auxGetNumDevs() ' Loop through each one, displaying its name and version number. For c = 0 To numdevs - 1 ' remember that device IDs are zero-based! ' Get the capabilities of this device. retval = auxGetDevCaps(c, auxinfo, Len(auxinfo)) If retval = 0 Then Debug.Print "** AUXILIARY AUDIO DEVICE"; c; "**" ' Extract and display the name of the device. devname = Left(auxinfo.szPname, InStr(auxinfo.szPname, vbNullChar) - 1) Debug.Print "Name: "; devname ' Extract and display the version number of the device. majver = (auxinfo.vDriverVersion And &HFF00) / &H100 ' major version minver = auxinfo.vDriverVersion And &HFF ' minor version Debug.Print "Version Number:"; majver; "."; minver Else Debug.Print "Could not get information about device"; c; "." End If Next c

Category
Audio Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: September 6, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail
http://216.26.168.92/vbapi/ref/a/auxgetnumdevs.html (2 of 3) [9/1/2002 5:03:41 PM]

Windows API Guide: auxGetNumDevs Function

This page is at http://www.vbapi.com/ref/a/auxgetnumdevs.html

http://216.26.168.92/vbapi/ref/a/auxgetnumdevs.html (3 of 3) [9/1/2002 5:03:41 PM]

Windows API Guide: auxGetVolume Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

auxGetVolume Function
Declare Function auxGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
auxGetVolume retrieves the current volume setting for an auxiliary audio device. This function will retreive the volume whether the device supports dual-channel volume control or not.

Return Value
If an error occured, the function returns a non-zero error code. If successful, the function returns 0.

Visual Basic-Specific Issues
None.

Parameters
uDeviceID The device ID of the auxiliary audio device to retrieve the volume of. Valid values range from 0 to the number of auxiliary audio devices minus one. lpdwVolume Receives the volume settings of the device. If the device supports separate left and right channel

http://216.26.168.92/vbapi/ref/a/auxgetvolume.html (1 of 3) [9/1/2002 5:03:45 PM]

Windows API Guide: auxGetVolume Function

volumes, the low-order word contains the left channel volume and the high-order word contains the right channel volume. If the device does not support separate volumes, the low-order word contains the overall volume. Valid volume settings range from &H0 or &HFFFF.

Example
' This code is licensed according to the terms and conditions listed here. ' Display the current volume setting of whatever device happens ' to be auxiliary audio device 0. This example identifies whether the ' device has dual-channel volumes or not. Dim auxinfo As AUXCAPS ' receives information about the device Dim numvols As Long ' identifies number of volumes on the device Dim lrvol As Long ' volumes of both channels (or just the overall volume) Dim lvol As Integer, rvol As Integer ' volumes of left and right channels Dim retval As Long ' return value ' Figure out whether the device has one or two volume settings. retval = auxGetDevCaps(0, auxinfo, Len(auxinfo)) If retval <> 0 Then ' error Debug.Print "Could not access auxiliary audio device 0 -- aborting." End ' give up End If If (auxinfo.dwSupport And AUXCAPS_LRVOLUME) = AUXCAPS_LRVOLUME Then numvols = 2 ' separate left and right volumes Else numvols = 1 ' only one overall volume End If ' Determine the device's current volume. retval = auxGetVolume(0, lrvol) ' Display the current volume setting for the device. If numvols = 2 Then ' Separate the left and right channel volumes. The next two lines look ' like an excessively complicated way of doing it, but because of a ' quirk in Visual Basic, the "obvious" way doesn't work properly. lvol = Val("&H" & Hex(lrvol And (Not &HFFFF0000))) rvol = (lrvol And &HFFFF0000) / &H10000 ' Display the results in hexadecimal. Debug.Print "Left Channel volume: "; Hex(lvol) Debug.Print "Right Channel volume: "; Hex(rvol) Else ' Extract the useful information as above, although we only want ' the low-order word (placed into lvol).

http://216.26.168.92/vbapi/ref/a/auxgetvolume.html (2 of 3) [9/1/2002 5:03:45 PM]

Windows API Guide: auxGetVolume Function

lvol = Val("&H" & Hex(lrvol And (Not &HFFFF0000))) ' Display the results in hexadecimal. Debug.Print "Volume: "; hex(lvol) ' here, lvol is the overall volume End If

See Also
auxSetVolume

Category
Audio Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: September 10, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/a/auxgetvolume.html

http://216.26.168.92/vbapi/ref/a/auxgetvolume.html (3 of 3) [9/1/2002 5:03:45 PM]

Windows API Guide: auxSetVolume Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

auxSetVolume Function
Declare Function auxSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
auxSetVolume sets the current volume of an auxiliary audio device. This function works whether the device supports separate left and right channel volumes or not.

Return Value
If an error occured, the function returns a non-zero error code. If successful, the function returns 0.

Visual Basic-Specific Issues
None.

Parameters
uDeviceID The device ID of the auxiliary audio device to set the volume of. Valid values range from zero to the number of auxiliary audio devices minus one. dwVolume The new volume setting of the device. If the device supports separate left and right channel volumes,

http://216.26.168.92/vbapi/ref/a/auxsetvolume.html (1 of 2) [9/1/2002 5:03:51 PM]

Windows API Guide: auxSetVolume Function

the low-order word contains the left channel volume and the high-order word contains the right channel volume. If the device supports only one overall volume, the low-order word is the volume. Valid volumes range from &H0 to &HFFFF.

Example
' This code is licensed according to the terms and conditions listed here. ' Set the volume of auxiliary audio device 0 to 50%. Here, ' we don't care whether the device supports separate volumes or ' not, since the code works either way. Dim retval As Long ' return value ' Set the volume of both channels (if a second exists) to 50% (&H8000). retval = auxSetVolume(0, &H80008000) ' both words are set

See Also
auxGetVolume

Category
Audio Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: September 10, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/a/auxsetvolume.html

http://216.26.168.92/vbapi/ref/a/auxsetvolume.html (2 of 2) [9/1/2002 5:03:51 PM]

Windows API Guide: Beep Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

Beep Function
Declare Function Beep Lib "kernel32.dll" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
Beep plays a sound, but its exact behavior varies between platforms. Windows 95/98: The function always plays the SystemDefault system sound, regardless of the values passed to the function. Windows NT/2000: The function plays a tone through the computer's internal speaker at the desired frequency for a specified duration.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues
None

Parameters
dwFreq Windows NT/2000: The frequency, in hertz (Hz), of the tone to play. Windows 95/98: Ignored. dwDuration Windows NT/2000: The duration, in milliseconds, to play the desired tone. Windows 95/98: Ignored.

Example
http://216.26.168.92/vbapi/ref/b/beep.html (1 of 2) [9/1/2002 5:03:57 PM]

Windows API Guide: Beep Function

' This code is licensed according to the terms and conditions listed here. ' Attempt to play a note at 800 Hz for 2 seconds. This will only ' behave this way on Windows NT/2000; users of Windows 95/98 will only hear the ' default sound. Dim retval As Long ' return value retval = Beep(800, 2000) ' ideally, an 800 Hz tone for 2 seconds

See Also
MessageBeep

Category
Errors Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 26, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/b/beep.html

http://216.26.168.92/vbapi/ref/b/beep.html (2 of 2) [9/1/2002 5:03:57 PM]

Windows API Guide: BitBlt Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

BitBlt Function
Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal dwRop As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
BitBlt performs a bit-block transfer of a rectangular portion of an image from one device to another. The dimensions of the transfered rectangle are perfectly preserved. The function can perform a variety of raster operations to transfer the block from the source device to the target device.

Return Value
If an error occured, the function returns 0 (Windows NT, 2000: use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues
None.

Parameters
hdcDest A handle to the device context of the device which receives the transfered image block.

http://216.26.168.92/vbapi/ref/b/bitblt.html (1 of 4) [9/1/2002 5:04:01 PM]

Windows API Guide: BitBlt Function

nXDest The x-coordinate of the point to position the upper-left corner of the transfered image block. nYDest The y-coordinate of the point to position the upper-left corner of the transfered image block. nWidth The width in pixels of the image block. nHeight The height in pixels of the image block. hdcSrc A handle to the device context of the device which contains the image block to transfer. nXSrc The x-coordinate of the upper-left corner of the image block to transfer. nYSrc The y-coordinate of the upper-left corner of the image block to transfer. dwRop One of the following flags identifying the raster operation to use to transfer the image block. Each raster operation uses the RGB color value of the source and/or target pixel to determine the new color of the target pixel. BLACKNESS Fill the destination rectangle with the color whose index is 0 in the physical palette (which is black by default). CAPTUREBLT Windows 98, 2000: Include any windows layered on top of the window being used in the resulting image. DSTINVERT Invert the colors in the destination rectangle. MERGECOPY Merge the colors of the source rectangle with the specified pattern using the bitwise AND operator. MERGEPAINT Merge the colors of the inverted source rectangle with the colors of the destination rectangle using the bitwise OR operator. NOMIRRORBITMAP Windows 98, 2000: Prevent the bitmap from being mirrored. NOTSRCCOPY Copy the inverted source rectangle to the destination rectangle. NOTSRCERASE Combine the colors of the source and destination rectangles using the bitwise OR operator and then invert the resulting color. PATCOPY Copy the specified pattern into the destination bitmap. PATINVERT Combine the colors of the specified pattern with the colors of the destination rectangle using the bitwise XOR operator. PATPAINT Combine the colors of the specified pattern with the colors of the inverted source rectangle using the bitwise OR operator. Combine the result of that operation with the colors of the destination rectangle using the bitwise OR operator.
http://216.26.168.92/vbapi/ref/b/bitblt.html (2 of 4) [9/1/2002 5:04:01 PM]

Windows API Guide: BitBlt Function

SRCAND Combine the colors of the source and destination rectangles using the bitwise AND operator. SRCCOPY Copy the source rectangle directly into the destination rectangle. SRCERASE Combine the inverted colors of the destination rectangle with the colors of the source rectange using the bitwise AND operator. SRCINVERT Combine the colors of the source and destination rectangles using the bitwise XOR operator. SRCPAINT Combine the colors of the source and destination rectangles using the bitwise OR operator. WHITENESS Fill the destination rectangle with the color whose index is 1 in the physical palette (which is white by default).

Constant Definitions
Const BLACKNESS = &H42 ' Const CAPTUREBLT = ??? Const DSTINVERT = &H550009 Const MERGECOPY = &HC000CA Const MERGEPAINT = &HBB0226 ' Const NOMIRRORBITMAP = ??? Const NOTSRCCOPY = &H330008 Const NOTSRCERASE = &H1100A6 Const PATCOPY = &HF00021 Const PATINVERT = &H5A0049 Const PATPAINT = &HFB0A09 Const SRCAND = &H8800C6 Const SRCCOPY = &HCC0020 Const SRCERASE = &H440328 Const SRCINVERT = &H660046 Const SRCPAINT = &HEE0086 Const WHITENESS = &HFF0062

Example
' This code is licensed according to the terms and conditions listed here. ' Copy a rectanglular image from window Form1 to window Form2 ' exactly (using SRCCOPY). The rectangle has a width of 100 and a height of ' 50. The upper-left corner of the source block is (350, 250); the block ' is placed at (0,0) in Form2. Dim retval As Long ' return value

http://216.26.168.92/vbapi/ref/b/bitblt.html (3 of 4) [9/1/2002 5:04:01 PM]

Windows API Guide: BitBlt Function

' Transfer the image exactly as described above. retval = BitBlt(Form2.hDC, 0, 0, 100, 50, Form1.hDC, 350, 250, SRCCOPY)

See Also
StretchBlt

Category
Bitmaps Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: August 13, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/b/bitblt.html

http://216.26.168.92/vbapi/ref/b/bitblt.html (4 of 4) [9/1/2002 5:04:01 PM]

Windows API Guide: BringWindowToTop Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

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

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
BringWindowToTop brings a specified window to the top of the Z-order, placing it above any windows previously on top of it. This function has the same effect as using SetWindowPos to place the window at the top of the Z-order.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues
None

Parameters
hwnd A handle to the window to bring to the top of the Z-order.

Example
' This code is licensed according to the terms and conditions listed here.

http://216.26.168.92/vbapi/ref/b/bringwindowtotop.html (1 of 2) [9/1/2002 5:05:56 PM]

Windows API Guide: BringWindowToTop Function

' Bring the window Form1 to the top of the Z-order. Dim retval As Long ' return value ' Obviously, this will only do something if other windows are already on top of Form1. retval = BringWindowToTop(Form1.hWnd)

See Also
SetWindowPos

Category:
Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 28, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/b/bringwindowtotop.html

http://216.26.168.92/vbapi/ref/b/bringwindowtotop.html (2 of 2) [9/1/2002 5:05:56 PM]

Windows API Guide: CallWindowProc Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

CallWindowProc Function
Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
CallWindowProc explicitly calls the hook function acting as a window's procedure to process a message. This allows a message for a window to be processed by a window procedure which is not necessarily the one normally called by the window.

Return Value
The function returns the return value generated after processing the message sent.

Visual Basic-Specific Issues
None.

Parameters
lpPrevWndFunc A pointer to the window procedure function to call explicitly. This is the function which will process the message. hWnd A handle to the window to process the message for. Msg The message to process. wParam Additional information about the message. lParam
http://216.26.168.92/vbapi/ref/c/callwindowproc.html (1 of 3) [9/1/2002 5:06:02 PM]

Windows API Guide: CallWindowProc Function

Additional information about the message.

Example
' This code is licensed according to the terms and conditions listed here. ' ' ' ' ' Have window Form1 play the SystemAsterisk sound whenever it gets or loses the focus. Do this by specifying a new window procedure which plays the sound whenever the WM_ACTIVATE message is received. To process all other messages (and do whatever else WM_ACTIVATE should do), the procedure then calls the previous window procedure. a module. *** ' identifier of the message is accessible to all code in this example. ' pointer to the previous window function

' *** Place this code in Const WM_ACTIVATE = &H6 ' The following variable Public pOldProc As Long

' Define the new window procedure. Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim retval As Long ' If the message is WM_ACTIVATE (we don't care about the parameters), ' play the SystemAsterisk sound. If uMsg = WM_ACTIVATE Then retval = PlaySound("SystemAsterisk", 0, SND_ALIAS Or SND_ASYNC) End If ' No matter what happened, use the old window procedure to ' finish processing the message. retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam) ' Have this function return whatever the function above returned. WindowProc = retval End Function ' *** Place the following code wherever you wish. *** Dim retval As Long ' return value ' Set the new window procedure for Form1, saving a pointer to the old one. pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc) ' Now WindowProc processes Form1's messages, playing the sound ' whenever Form1 is activated or loses activated status.

See Also
DefWindowProc

Category
Window Procedures
http://216.26.168.92/vbapi/ref/c/callwindowproc.html (2 of 3) [9/1/2002 5:06:02 PM]

Windows API Guide: CallWindowProc Function

Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: August 23, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/c/callwindowproc.html

http://216.26.168.92/vbapi/ref/c/callwindowproc.html (3 of 3) [9/1/2002 5:06:02 PM]

Windows API Guide: ChangeDisplaySettings Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

ChangeDisplaySettings Function
Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.5 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
ChangeDisplaySettings changes the current display settings. This function can change the current screen resolution and color depth, among other things. Typically, a call to EnumDisplaySettings should preceed this function, in order to adjust only the desired settings.

Return Value
The function returns one of the following flags: DISP_CHANGE_SUCCESSFUL The display settings were successfully changed. DISP_CHANGE_RESTART The computer must be restarted for the display changes to take effect. DISP_CHANGE_BADFLAGS An invalid set of flags was specified. DISP_CHANGE_BADPARAM An invalid parameter was specified. DISP_CHANGE_FAILED The display driver failed the specified graphics mode. DISP_CHANGE_BADMODE The specified graphics mode is not supported. DISP_CHANGE_NOTUPDATED Windows NT/2000: The settings could not be written to the registry.

Visual Basic-Specific Issues
http://216.26.168.92/vbapi/ref/c/changedisplaysettings.html (1 of 5) [9/1/2002 5:06:28 PM]

Windows API Guide: ChangeDisplaySettings Function

When specifying zero for lpDevMode, use the expression ByVal CLng(0).

Parameters
lpDevMode A DEVMODE structure that holds the new display settings. Only the dmBitsPerPixel, dmPelsWidth, dmPelsHeight, dmDisplayFlags, and dmDisplayFrequency members are used. (Windows 98, NT/2000: The dmPosition member can also be used.) To restore the settings saved in the registry, set this parameter and dwFlags to zero. dwFlags A combination of the following flags specifying how to change the display mode. If no flags are set (i.e., zero is specified), the graphics mode is changed dynamically. CDS_UPDATEREGISTRY Save the new settings to the registry and also change the settings dynamically. CDS_TEST Test to see if the new settings are supported by the hardware, without actually changing the settings. The function's return value will indicate any problems that may have occured. CDS_FULLSCREEN Go into full-screen mode. This setting cannot be saved. CDS_GLOBAL Save the new settings for all users. The CDS_UPDATEREGISTRY flag must also be specified. CDS_SET_PRIMARY Make this device the primary display device. CDS_RESET Change the settings even if they are the same as the current settings. CDS_NORESET Save the settings to the registry, but do not make them take effect yet. The CDS_UPDATEREGISTRY flag must also be specified.

Constant Definitions
Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const CDS_UPDATEREGISTRY = &H1 CDS_TEST = &H2 CDS_FULLSCREEN = &H4 CDS_GLOBAL = &H8 CDS_SET_PRIMARY = &H10 CDS_RESET = &H40000000 CDS_SETRECT = &H20000000 CDS_NORESET = &H10000000 DISP_CHANGE_SUCCESSFUL = 0 DISP_CHANGE_RESTART = 1 DISP_CHANGE_FAILED = -1 DISP_CHANGE_BADMODE = -2 DISP_CHANGE_NOTUPDATED = -3 DISP_CHANGE_BADFLAGS = -4 DISP_CHANGE_BADPARAM = -5

http://216.26.168.92/vbapi/ref/c/changedisplaysettings.html (2 of 5) [9/1/2002 5:06:28 PM]

Windows API Guide: ChangeDisplaySettings Function

Example
Change the current screen resolution to 800x600 without changing the color depth and save the changes to the registry. First test to make sure that the hardware supports the new resolution. If a reboot is necessary, inform the user. To use this example, place a command button named Command1 of a form window. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Type DEVMODE dmDeviceName As String * 32 dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * 32 dmUnusedPadding As Integer dmBitsPerPixel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long ' The following only appear in Windows 95, 98, 2000 dmICMMethod As Long dmICMIntent As Long dmMediaType As Long dmDitherType As Long dmReserved1 As Long dmReserved2 As Long ' The following only appear in Windows 2000 dmPanningWidth As Long dmPanningHeight As Long End Type Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias
http://216.26.168.92/vbapi/ref/c/changedisplaysettings.html (3 of 5) [9/1/2002 5:06:28 PM]

Windows API Guide: ChangeDisplaySettings Function

"EnumDisplaySettingsA" (ByVal lpszDeviceName As String, _ ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long Public Const ENUM_CURRENT_SETTINGS = -1 Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags _ As Long) As Long Public Const CDS_UPDATEREGISTRY = &H1 Public Const CDS_TEST = &H2 Public Const DISP_CHANGE_SUCCESSFUL = 0 Public Const DISP_CHANGE_RESTART = 1 ' *** Place the following code inside the form window. Private Sub Command1_Click() Dim dm As DEVMODE ' display settings Dim retval As Long ' return value ' Initialize the structure that will hold the settings. dm.dmSize = Len(dm) ' Get the current display settings. retval = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm) ' Change the resolution settings to 800x600. dm.dmPelsWidth = 800 dm.dmPelsHeight = 600 ' Test to make sure the changes are possible. retval = ChangeDisplaySettings(dm, CDS_TEST) If retval <> DISP_CHANGE_SUCCESSFUL Then Debug.Print "Cannot change to that resolution!" Else ' Change and save to the new settings. retval = ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY) Select Case retval Case DISP_CHANGE_SUCCESSFUL Debug.Print "Resolution successfully changed!" Case DISP_CHANGE_RESTART Debug.Print "A reboot is necessary before the changes will take effect." Case Else Debug.Print "Unable to change resolution!" End Select End If End Sub

See Also
EnumDisplaySettings

Category
http://216.26.168.92/vbapi/ref/c/changedisplaysettings.html (4 of 5) [9/1/2002 5:06:28 PM]

Windows API Guide: ChangeDisplaySettings Function

Devices Back to the Function list. Back to the Reference section.

Last Modified: January 21, 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/c/changedisplaysettings.html

http://216.26.168.92/vbapi/ref/c/changedisplaysettings.html (5 of 5) [9/1/2002 5:06:28 PM]

Windows API Guide: CharLower Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

CharLower Function
Declare Function CharLower Lib "user32.dll" Alias "CharLowerA" (ByVal lpsz As String) As String

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
CharLower converts all of the upper-case letters in a string into lower-case. The function also sets the string passed to the function to the returned string; in reality they become the same thing.

Return Value
The function returns the string, with all upper-case letters converted to lower-case.

Visual Basic-Specific Issues
None.

Parameters
lpsz The string to convert to lower-case.

Example
http://216.26.168.92/vbapi/ref/c/charlower.html (1 of 2) [9/1/2002 5:06:36 PM]

Windows API Guide: CharLower Function

' This code is licensed according to the terms and conditions listed here. ' Convert the string "Hello, World!" into lower-case. Dim target As String ' target string

target = CharLower("Hello, World!") ' Convert to lower-case Debug.Print target ' Output should be "hello, world!"

See Also
CharUpper

Category
Strings Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 30, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/c/charlower.html

http://216.26.168.92/vbapi/ref/c/charlower.html (2 of 2) [9/1/2002 5:06:36 PM]

Windows API Guide: CharUpper Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

CharUpper Function
Declare Function CharUpper Lib "user32.dll" Alias "CharUpperA" (ByVal lpsz As String) As String

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
CharUpper converts all of the lower-case letters in a string into upper-case. The function also sets the string passed to the function to the returned string; in reality they become the same thing.

Return Value
The function returns the string, with all lower-case letters converted to upper-case.

Visual Basic-Specific Issues
None.

Parameters
lpsz The string to convert to upper-case.

Example
http://216.26.168.92/vbapi/ref/c/charupper.html (1 of 2) [9/1/2002 5:06:43 PM]

Windows API Guide: CharUpper Function

' This code is licensed according to the terms and conditions listed here. ' Convert the string "Hello, World!" into upper-case. Dim target As String ' target string

target = CharUpper("Hello, World!") ' Convert to upper-case Debug.Print target ' Output should be "HELLO, WORLD!"

See Also
CharLower

Category
Strings Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 30, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/c/charupper.html

http://216.26.168.92/vbapi/ref/c/charupper.html (2 of 2) [9/1/2002 5:06:43 PM]

Windows API Guide: ChooseColor Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

ChooseColor Function
Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As CHOOSECOLOR_TYPE) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 2.0 or later.

Description & Usage
ChooseColor opens a Choose Color common dialog box. All the information needed to create the dialog box, as well as the data returned from it, is stored in the structure passed as lpcc.

Return Value
If an error occured or the user pressed the Cancel button, the function returns 0 (use CommDlgExtendedError to get the error code). If the user successfully selected a color, the function returns a non-zero value.

Visual Basic-Specific Issues
None.

Parameters
lpcc All the information needed to create the Choose Color common dialog box. If successful, the function then stores the user's color selection and list of custom colors into this structure as well.

Example
' This code is licensed according to the terms and conditions listed here. ' Display a Choose Color common dialog box. The background

http://216.26.168.92/vbapi/ref/c/choosecolor.html (1 of 3) [9/1/2002 5:07:31 PM]

Windows API Guide: ChooseColor Function

' color of Form1 will be set to the color the user selects. Although the entire ' list of custom colors is initialized to black, this example stores the ' colors into an array which can be used again to save the user's custom ' color selections. Dim cc As CHOOSECOLOR_TYPE ' structure to pass data Dim hMem As Long ' handle to the memory block to store the custom color list Dim pMem As Long ' pointer to the memory block to store the custom color list Dim custcols(0 To 15) As Long ' holds list of the 16 custom colors Dim c As Integer ' counter variable Dim retval As Long ' return value ' Initialize the list of custom colors to black. For c = 0 To 15 ' loop through each element custcols(c) = 0 ' set each element to RGB color 0 (black) Next c ' Create a memory block and get a pointer to it. hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, 64) ' allocate sufficient memory block pMem = GlobalLock(hMem) ' get a pointer to the block ' Copy the data inside the array into the memory block. CopyMemory ByVal pMem, custcols(0), 64 ' 16 elements * 4 bytes ' Store the initial settings of the Choose Color box. cc.lStructSize = Len(cc) ' size of the structure cc.hwndOwner = Form1.hWnd ' Form1 is opening the Choose Color box cc.hInstance = 0 ' not needed cc.rgbResult = Form1.BackColor ' set default selected color to Form1's background color cc.lpCustColors = pMem ' pointer to list of custom colors cc.Flags = CC_ANYCOLOR Or CC_RGBINIT ' allow any color, use rgbResult as default selection cc.lCustData = 0 ' not needed cc.lpfnHook = 0 ' not needed cc.lpTemplateName = "" ' not needed ' Open the Choose Color box. If the user chooses a color, set Form1's ' background color to that color. retval = ChooseColor(cc) If retval <> 0 Then ' success ' Copy the possibly altered contents of the custom color list ' back into the array. CopyMemory custcols(0), ByVal pMem, 64 ' Set Form1's background color. Form1.BackColor = cc.rgbResult End If ' Deallocate the memory blocks to free up resources. retval = GlobalUnlock(hMem) retval = GlobalFree(pMem)

http://216.26.168.92/vbapi/ref/c/choosecolor.html (2 of 3) [9/1/2002 5:07:31 PM]

Windows API Guide: ChooseColor Function

Category
Common Dialog Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: August 14, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/c/choosecolor.html

http://216.26.168.92/vbapi/ref/c/choosecolor.html (3 of 3) [9/1/2002 5:07:31 PM]

Windows API Guide: ChooseFont Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

ChooseFont Function
Declare Function ChooseFont Lib "comdlg32.dll" Alias "ChooseFontA" (lpcf As CHOOSEFONT_TYPE) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
ChooseFont opens the Choose Font common dialog box. All of the necessary information needed to create the dialog box, as well as all of the information returned from it, is stored in the structure passed as pChooseFont. The logical font information is mostly stored in a LOGFONT structure, which can be used to access that font.

Return Value
If an error occured or the user pressed Cancel, the function returns 0 (use CommDlgExtendedError to get the error code). If the user successfully selected a font, the function returns a non-zero value.

Visual Basic-Specific Issues
None.

Parameters
lpcf Passes information to and from the Choose Font dialog box. Initialize this before calling the function, and read the necessary information from it afterwards.

Example
' This code is licensed according to the terms and conditions listed here.

http://216.26.168.92/vbapi/ref/c/choosefont.html (1 of 3) [9/1/2002 5:07:39 PM]

Windows API Guide: ChooseFont Function

' Display a Choose Font dialog box. Print out the typeface name, point size, ' and style of the selected font. More detail about topics in this example can be found in ' the pages for CHOOSEFONT_TYPE and LOGFONT. Dim cf As CHOOSEFONT_TYPE ' data structure needed for function Dim lfont As LOGFONT ' receives information about the chosen font Dim hMem As Long, pMem As Long ' handle and pointer to memory buffer Dim fontname As String ' receives name of font selected Dim retval As Long ' return value ' Initialize the default selected font: Times New Roman, regular, black, 12 point. ' (Note that some of that information is in the CHOOSEFONT_TYPE structure instead.) lfont.lfHeight = 0 ' determine default height lfont.lfWidth = 0 ' determine default width lfont.lfEscapement = 0 ' angle between baseline and escapement vector lfont.lfOrientation = 0 ' angle between baseline and orientation vector lfont.lfWeight = FW_NORMAL ' normal weight i.e. not bold lfont.lfItalic = 0 ' not italic lfont.lfUnderline = 0 ' not underline lfont.lfStrikeOut = 0 ' not strikeout lfont.lfCharSet = DEFAULT_CHARSET ' use default character set lfont.lfOutPrecision = OUT_DEFAULT_PRECIS ' default precision mapping lfont.lfClipPrecision = CLIP_DEFAULT_PRECIS ' default clipping precision lfont.lfQuality = DEFAULT_QUALITY ' default quality setting lfont.lfPitchAndFamily = DEFAULT_PITCH Or FF_ROMAN ' default pitch, proportional with serifs lfont.lfFaceName = "Times New Roman" & vbNullChar ' string must be null-terminated ' Create the memory block which will act as the LOGFONT structure buffer. hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(lfont)) pMem = GlobalLock(hMem) ' lock and get pointer CopyMemory ByVal pMem, lfont, Len(lfont) ' copy structure's contents into block ' Initialize dialog box: Screen and printer fonts, point size between 10 and 72. cf.lStructSize = Len(cf) ' size of structure cf.hwndOwner = Form1.hWnd ' window Form1 is opening this dialog box cf.hdc = Printer.hDC ' device context of default printer (using VB's mechanism) cf.lfLogFont = pMem ' pointer to LOGFONT memory block buffer cf.iPointSize = 120 ' 12 point font (in units of 1/10 point) cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE cf.rgbColors = RGB(0, 0, 0) ' black cf.lCustData = 0 ' we don't use this here... cf.lpfnHook = 0 ' ...or this... cf.lpTemplateName = "" ' ...or this... cf.hInstance = 0 ' ...or this... cf.lpszStyle = "" ' ...or this cf.nFontType = REGULAR_FONTTYPE ' regular font type i.e. not bold or anything cf.nSizeMin = 10 ' minimum point size cf.nSizeMax = 72 ' maximum point size
http://216.26.168.92/vbapi/ref/c/choosefont.html (2 of 3) [9/1/2002 5:07:39 PM]

ByVal pMem.Print ' end the line End If ' Deallocate the memory block we created earlier. call the function. Go back to the Reference section index.1) ' Display font name and a few attributes. Last Modified: August 19.lfFaceName.Print "FONT NAME: ".html http://216.lfFaceName. Note that this must ' be done whether the function succeeded or not. Copyright Information Revised October 29. If lfont.Print "Italic ".Print "Strikeout". retval = ChooseFont(cf) ' open the dialog box If retval <> 0 Then ' success CopyMemory lfont.168. retval = GlobalUnlock(hMem) ' destroy pointer. vbNullChar) . Debug.lfStrikeOut <> 0 Then Debug.com/ref/c/choosefont. 1999 This page is copyright © 1999 Paul Kuliniewicz.lfItalic <> 0 Then Debug. Len(lfont) ' copy memory back ' Now make the fixed-length string holding the font name into a "normal" string. fontname = Left(lfont.92/vbapi/ref/c/choosefont. fontname Debug.iPointSize / 10 ' in units of 1/10 point! Debug.lfWeight >= FW_BOLD Then Debug.com Send Encrypted E-Mail This page is at http://www. If lfont. cf. If successful.26. E-mail: vbapi@vbapi. If lfont.Windows API Guide: ChooseFont Function ' Now.vbapi.lfUnderline <> 0 Then Debug.Print "Underline ". If lfont.Print "FONT SIZE (points):". 2000 Go back to the Windows API Guide home page. Debug.Print "FONT STYLE(S): ".html (3 of 3) [9/1/2002 5:07:39 PM] . InStr(lfont. unlock block retval = GlobalFree(hMem) ' free the allocated memory Category Common Dialog Go back to the alphabetical Function listing. copy the LOGFONT structure back into the structure ' and then print out the attributes we mentioned earlier that the user selected.Print "Bold ".

Windows NT: Requires Windows NT 3. If successful. The start and end points of the chord's elliptical arc are determined by two radials (drawn from the ellipse's center out to a point). the function returns 0 (Windows NT. ByVal nYRadial2 As Long) As Long Platforms q q q q q Windows 95: Supported. ByVal nRightRect As Long. ByVal nBottomRect As Long. ByVal nXRadial1 As Long.168.com . ByVal nYRadial1 As Long.com | www.1 or later. The chord consists of a line segment connecting two points along an ellipse. the area between the chord and the ellipse's edge is filled (going counterclockwise around the ellipse).com | www.vbworld.vbsquare.92/vbapi/ref/c/chord.html (1 of 3) [9/1/2002 5:07:46 PM] .vbapi.vbforums. Visual Basic-Specific Issues None.Windows API Guide: Chord Function vbapi. Return Value If an error occured.vbshop.26. Windows CE: Not Supported.com | www. The chord is drawn using the device's currently selected pen and is filled using its currently selected brush. The point where a radial and the ellipse intersect is the start or end point of the chord's arc. Windows 2000: Supported.dll" (ByVal hdc As Long. ByVal nTopRect As Long. Parameters hdc A handle to a device context to the device to draw the chord on. Description & Usage Chord draws an elliptical chord on a device.part of the VB-World Network | www. ByVal nLeftRect As Long.com | www. Windows 98: Supported. the function returns a non-zero value. ByVal nXRadial2 As Long. nLeftRect http://216. 2000: use GetLastError to get the error code).com | Chord Function Declare Function Chord Lib "gdi32.

92/vbapi/ref/c/chord. 2000 Go back to the Windows API Guide home page.i. 210. retval = Chord(Form1. 210. Go back to the Reference section index. Example ' This code is licensed according to the terms and conditions listed here. Copyright Information Revised October 29.e.html (2 of 3) [9/1/2002 5:07:46 PM] . 110.26. 70. nBottomRect The y-coordinate of the lower-right corner of the ellipse's bounding rectangle. The ellipse has a bounding rectangle ' of (10.120). nXRadial1 The x-coordinate of the point along the radial determining the starting point of the chord. The chord will have endpoints on the ellipse of (210.. Last Modified: September 10. ' Draw a chord on window Form1. 20. Pie Category Filled Shapes Go back to the alphabetical Function listing.20) -. 20) See Also Ellipse. nYRadial2 The y-coordinate of the point along the radial determining the ending point of the chord. 1999 This page is copyright © 1999 Paul Kuliniewicz. nRightRect The x-coordinate of the lower-right corner of the ellipse's bounding rectangle. 120.168. the "upper-right" portion of the ellipse.70) ' and (110.hDC. Draw the chord using ' Form1's current brush and pen. nXRadial2 The x-coordinate of the point along the radial determining the ending point of the chord. Dim retval As Long ' return value ' Draw the chord as specified above. nYRadial1 The y-coordinate of the point along the radial determining the starting point of the chord.20)-(210.Windows API Guide: Chord Function The x-coordinate of the upper-left corner of the ellipse's bounding rectangle. nTopRect The y-coordinate of the upper-left corner of the ellipse's bounding rectangle. 10. http://216.

html http://216.com/ref/c/chord.com Send Encrypted E-Mail This page is at http://www.vbapi.168.26.92/vbapi/ref/c/chord.Windows API Guide: Chord Function E-mail: vbapi@vbapi.html (3 of 3) [9/1/2002 5:07:46 PM] .

Windows 2000: Supported. the function returns zero (call GetLastError to get the error code).com | www.com | www. and will remain even if the program that confined the cursor closes! The only way to "release" the cursor is to "confine" it to the entire screen (see example). the function returns a non-zero value.com | www. Visual Basic-Specific Issues None. since the user expects to move the cursor anywhere (not to mention the disasterous effect if your program quit before releasing the cursor!).1 or later. Parameters http://216.dll" (lpRect As RECT) As Long Platforms q q q q q Windows 95: Supported.com | ClipCursor Function Declare Function ClipCursor Lib "user32. This bounding effect will last in whatever program you switch to. Return Value If an error occured. Windows CE: Not Supported.Windows API Guide: ClipCursor Function vbapi.vbapi. If the user tries to move the cursor outside of this bounding region or a call to SetCursorPos tells it to go outside the box. the cursor will immediately returned to the area.vbworld. Windows 98: Supported.com | www.vbsquare.part of the VB-World Network | www.168.vb-shop.com .vbforums.26. Windows NT: Requires Windows NT 3.92/vbapi/ref/c/clipcursor.html (1 of 3) [9/1/2002 5:07:52 PM] . There is no way to get it out. It isn't usually a good idea to confine the cursor. Description & Usage ClipCursor confines the mouse cursor to a rectangular area of the screen. If successful.

Last-Modified: September 10. 1999 This page is copyright © 1999 Paul Kuliniewicz. E-mail: vbapi@vbapi.168. 2000 Go back to the Windows API Guide home page.92/vbapi/ref/c/clipcursor.26. r) ' put window's coordinates into r retval = ClipCursor(r) ' confine the cursor ' ** Place the following code where you want to release the cursor. Go back to the Reference section index. Example ' This code is licensed according to the terms and conditions listed here. r) ' put window's coordinates into r retval = ClipCursor(r) ' "confine" the cursor to the entire screen See Also GetClipCursor Category Cursor Go back to the alphabetical Function listing. ' Confine the cursor temporarily to inside of Form1 ' ** Place the following code where you want to confine the cursor.html (2 of 3) [9/1/2002 5:07:52 PM] .Windows API Guide: ClipCursor Function lpRect The rectangle (in screen coordinates) defining the confinement rectangle. ** Dim r As RECT.hWnd.com Send Encrypted E-Mail http://216. ** Dim r As RECT ' confinement rectangle Dim retval As Long ' return value retval = GetWindowRect(Form1. retval As Long Dim deskhWnd As Long ' the handle of the desktop window deskhWnd = GetDesktopWindow() ' get handle of the desktop window retval = GetWindowRect(deskhWnd. Copyright Information Revised October 29.

com/ref/c/clipcursor.vbapi.92/vbapi/ref/c/clipcursor.Windows API Guide: ClipCursor Function This page is at http://www.26.html http://216.html (3 of 3) [9/1/2002 5:07:52 PM] .168.

file mappings. mailslots. Dim hFile As Long ' handle to the opened file http://216.vbsquare.Windows API Guide: CloseHandle Function vbapi.0 or later.dll" (ByVal hObject As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns a non-zero value. jobs.vbshop. Windows NT: Requires Windows NT 3. mutexes.com | www. semaphores.com | www.vbforums. processes. console inputs. events. sockets.vbworld. Description & Usage CloseHandle closes a handle and the object associated with that handle. Windows 2000: Supported. Parameters hObject A handle to the object to close.vbapi. Windows 98: Supported. After being closed. Note how the time zone conversion is necessary.1 or later. If successful.txt was ' created. Visual Basic-Specific Issues None. console screen buffers.com .com | CloseHandle Function Declare Function CloseHandle Lib "kernel32.com | www.168. files. the handle is of course no longer valid. Example ' This code is licensed according to the terms and conditions listed here. communications devices. Windows CE: Requires Windows CE 1. named pipes.com | www. This function closes handles associated with access tokens.part of the VB-World Network | www. the function returns 0 (use GetLastError to get the error code).26. ' Display the date on which the file C:\MyApp\test. Return Value If an error occured.92/vbapi/ref/c/closehandle.html (1 of 2) [9/1/2002 5:08:17 PM] . and threads.

92/vbapi/ref/c/closehandle. thetime." End ' terminate the program End If ' Next.html (2 of 2) [9/1/2002 5:08:17 PM] .com Send Encrypted E-Mail This page is at http://www.Windows API Guide: CloseHandle Function Dim Dim Dim Dim Dim ctime As FILETIME ' receives time of creation atime As FILETIME ' receives time of last access mtime As FILETIME ' receives time of last modification thetime As SYSTEMTIME ' used to manipulate the time retval As Long ' return value ' First. GENERIC_READ.com/ref/c/closehandle. 0) If hFile = -1 Then Debug. atime.aborting. get the creation. Debug. thetime. retval = FileTimeToSystemTime(ctime. thetime) ' Display the date of creation of the file to the user. ByVal CLng(0). and last-modification times. 1999 This page is copyright © 1999 Paul Kuliniewicz. OPEN_EXISTING. mtime) ' Convert the creation time to the local time zone. Last Modified: October 1. E-mail: vbapi@vbapi. Go back to the Reference section index. "-".wYear ' Close the file to free up resources.26.html http://216. last-access. Note the ' expression necessary to pass 0 as lpSecurityAttributes. ctime. thetime. retval = CloseHandle(hFile) Category Handles Go back to the alphabetical Function listing.Print "The file was created on ". FILE_SHARE_READ. retval = GetFileTime(hFile.txt".168.txt for read-level access.wMonth. "-".vbapi. FILE_ATTRIBUTE_ARCHIVE. retval = FileTimeToLocalFileTime(ctime.Print "Could not open the file successfully -. Copyright Information Revised October 29. ctime) ' Convert the FILETIME format to the SYSTEMTIME format. open the file C:\MyApp\test.wDay. 2000 Go back to the Windows API Guide home page. hFile = CreateFile("C:\MyApp\test.

vbapi.vbworld. even if the function fails. Windows NT: Requires Windows NT 3.com . Windows CE: Not Supported. To use the example. Description & Usage ClosePrinter closes a printer which had been previously opened by OpenPrinter. first place a command button named cmdProperties on a form window.com | www. If an error occured.vbforums. Windows 98: Supported. Parameters hPrinter A handle to the open printer to close.vbshop. Return Value If successful.Windows API Guide: ClosePrinter Function vbapi.drv" (ByVal hPrinter As Long) As Long Platforms q q q q q Windows 95: Supported.com | ClosePrinter Function Declare Function ClosePrinter Lib "winspool. the function returns a non-zero value.com | www.part of the VB-World Network | www. After this function closes the printer.com | www. Windows 2000: Supported.vbsquare. ' Declarations and such needed for the example: http://216.1 or later.com | www.168. the handle to the printer obviously can no longer be used. Example Display the Properties dialog box for the system's default printer.html (1 of 3) [9/1/2002 5:08:32 PM] . Visual Basic-Specific Issues None. ' This code is licensed according to the terms and conditions listed here.26.92/vbapi/ref/c/closeprinter. the function returns zero (use GetLastError to get the error code). The dialog box is opened when the user clicks the button cmdProperties.

bytesNeeded.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. 1.Windows API Guide: ClosePrinter Function ' (Copy them to the (declarations) section of a module. _ ByVal lpString2 As Any) As Long Public Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function OpenPrinter Lib "winspool.drv" (ByVal hWnd As Long. ByVal hPrinter _ As Long) As Long Public Declare Function ClosePrinter Lib "winspool. vbNullString.html (2 of 3) [9/1/2002 5:08:32 PM] . ByVal 0.drv" (ByVal hPrinter As Long) As Long ' *** Place the following code inside a form window. pcReturned As Long) As Long Public Const PRINTER_ENUM_DEFAULT = &H1 Public Declare Function lstrcpy Lib "kernel32. pPrinterEnum As Long. vbNullString. 0.) Public Type PRINTER_INFO_1 flags As Long pDescription As String pName As String pComment As String End Type Public Declare Function EnumPrinters Lib "winspool.1) As Long ' Get information about the default printer. retval = EnumPrinters(PRINTER_ENUM_DEFAULT.drv" Alias "EnumPrintersA" (ByVal flags As Long. 1. ReDim buffer(0 To bytesNeeded / 4 .drv" Alias "OpenPrinterA" (ByVal pPrinterName _ As String. _ bytesNeeded." Exit Sub End If http://216. ByVal cdBuf As Long. ByVal Level As Long.168.Print "No default printer or some other error. _ ByVal name As String. pDefault As Any) As Long Public Declare Function PrinterProperties Lib "winspool. *** Private Sub Dim Dim Dim Dim Dim Dim Dim cmdProperties_Click() pi1 As PRINTER_INFO_1 bytesNeeded As Long numPrinters As Long buffer() As Long slength As Long hPrinter As Long retval As Long ' ' ' ' ' ' ' a little info about the printer size needed for buffer number of printers enumerated (should be 1) buffer for printer information length of string to copy handle to the printer generic return value ' Figure out how much space is needed to store the printer information. If retval = 0 Or numPrinters <> 1 Then Debug. buffer(0). bytesNeeded. numPrinters) ' Allocate that much space in the buffer array.26. phPrinter As Long. numPrinters) ' Make sure we were successful. _ pcbNeeded As Long.92/vbapi/ref/c/closeprinter.

ByVal CLng(0)) If retval <> 0 Then ' Display the properties dialog. hPrinter) ' Close the printer.Print "Unable to open printer!" End If End Sub See Also OpenPrinter Category Printers Go back to the Function listing.pName = Space(lstrlen(buffer(2))) retval = lstrcpy(.vbapi. buffer(3)) End With ' Open the printer.pDescription = Space(lstrlen(buffer(1))) retval = lstrcpy(.com Send Encrypted E-Mail This page is at http://www.26. .pName.html http://216. hPrinter. Last Modified: January 21. retval = OpenPrinter(pi1.flags = buffer(0) ' Strings require more work.com/ref/c/closeprinter.hWnd. With pi1 ' Copy numerical data directly. Go back to the Reference section index.pComment.168.92/vbapi/ref/c/closeprinter. .pName. Copyright Information Revised October 29.html (3 of 3) [9/1/2002 5:08:32 PM] . retval = PrinterProperties(Me.pDescription. buffer(2)) . since the buffer holds pointers to them. 2001 This page is copyright © 2001 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page.pComment = Space(lstrlen(buffer(3))) retval = lstrcpy(. E-mail: vbapi@vbapi.Windows API Guide: ClosePrinter Function ' Copy the data into the structure. retval = ClosePrinter(hPrinter) Else Debug. buffer(1)) .

Windows 98: Supported. Windows NT: Requires Windows NT 3.com . Parameters s A descriptor of the socket to close. in order to free unneeded socket descriptors. This example supports a very crude implementation of http://216.com | www. Description & Usage closesocket closes a socket that had previously been created by a call to socket.1 or later. Constant Definitions Const INVALID_SOCKET = &HFFFFFFFF Example Download the main page of this web site (http://www.com | www.0 or later.part of the VB-World Network | www.26.dll" (ByVal s As Long) As Long Platforms q q q q q Windows 95: Supported.vbshop.vbapi.vbsquare. Windows 2000: Supported. Windows CE: Requires Windows CE 1.vbforums.com | closesocket Function Declare Function closesocket Lib "wsock32.Windows API Guide: closesocket Function vbapi.com | www.com).html (1 of 5) [9/1/2002 5:08:45 PM] . Visual Basic-Specific Issues None.com | www.vbapi. Your program should call this function when it is finished using a socket.92/vbapi/ref/c/closesocket.vbworld.168. Return Value If successful. the function returns INVALID_SOCKET (use WSAGetLastError to get the error code). the function returns zero. If an error occured.

html (2 of 5) [9/1/2002 5:08:45 PM] .92/vbapi/ref/c/closesocket. _ ByVal protocol As Long) As Long Public Type sockaddr sin_family As Integer sin_port As Integer sin_addr As Long sin_zero As String * 8 End Type Public Declare Function connect Lib "wsock32. place a command button named cmdDownload on a form window.Windows API Guide: closesocket Function HyperText Transport Protocol (HTTP). The document downloaded. and WSACleanup must be called at the end no matter what happens. To prevent the program from appearing to lock up in the event of a momentary interruption in the transfer. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. I would use that instead of GoTo. with HTTP headers removed. Note the careful use of GoTo in this example. the GoTo statements skip down to the end if an unrecoverable error occurs. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. is output to the Debug window.168.dll" (ByVal hostshort As Integer) As Integer Public Declare Function socket Lib "wsock32.dll" (ByVal af As Long. To use this example. ByVal namelen _ As Long) As Long http://216. a nonblocking socket is used.26.dll" () As Long Public Const AF_INET = 2 Public Const SOCK_STREAM = 1 Public Declare Function gethostbyname Lib "wsock32. ByVal prototype As Long. sending a request to the server and receiving the document. ' This code is licensed according to the terms and conditions listed here.dll" (ByVal s As Long. Since there are lots of things that can go wrong.dll" (ByVal name As String) As Long Public Type hostent h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Declare Function htons Lib "wsock32. name As sockaddr.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequested As Integer. If VB had better exception handling.

ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh).dll" (ByVal s As Long. 2). 2)) End Function ' *** Place the following code inside the form window. Public Function MAKEWORD(ByVal bLow As Byte.h_addrtype <> AF_INET Then Debug. retval Exit Sub End If ' Get information about the server to connect to.Print "Unable to resolve host!" GoTo Cleanup End If ' Copy information about the server into the structure.vbapi. argp As Long) As Long Public Const FIONBIO = &H8004667E Public Declare Function send Lib "wsock32. buf As Any.dll" (ByVal s As Long. buf As Any. ByVal length As Long. *** Private Sub Dim Dim Dim Dim Dim Dim Dim Dim Dim Dim cmdDownload_Click() wsockinfo As WSADATA sock As Long pHostinfo As Long hostinfo As hostent pIPAddress As Long ipAddress As Long sockinfo As sockaddr buffer As String reply As String retval As Long ' ' ' ' ' ' ' ' ' ' info about Winsock the socket descriptor pointer to info about the host computer info about the host computer pointer to host's IP address host's IP address settings for the socket buffer for sending and receiving data accumulates server's reply generic return value ' Begin a Winsock session.com!" http://216.com") If pHostinfo = 0 Then Debug. _ ByVal flags As Long) As Long Public Declare Function recv Lib "wsock32.26.168.Windows API Guide: closesocket Function Declare Function ioctlsocket Lib "wsock32. ByVal pHostinfo. retval = WSAStartup(MAKEWORD(2. ByVal cmd As Long.html (3 of 5) [9/1/2002 5:08:45 PM] . pHostinfo = gethostbyname("www.Print "Unable to initialize Winsock! --". ByVal Length As Long) Public Const SOCKET_ERROR = -1 ' Define a useful macro.dll" (ByVal s As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. Len(hostinfo) If hostinfo. wsockinfo) If retval <> 0 Then Debug. Source _ As Any.Print "Couldn't get IP address of www. _ ByVal flags As Long) As Long Public Declare Function closesocket Lib "wsock32. ByVal length As Long. 2) & Right("00" & Hex(bLow).dll" Alias "RtlMoveMemory" (Destination As Any.vbapi.92/vbapi/ref/c/closesocket.dll" (ByVal s As Long. CopyMemory hostinfo.

sin_zero = String(8. so calls to recv don't halt the program waiting for input. sock = socket(AF_INET..Print "Unable to connect!" GoTo Cleanup End If ' Send an HTTP/GET request for the /index. if the connection is ' lost).. 0) If sock = SOCKET_ERROR Then Debug. ByVal hostinfo. 0) If retval <> 0 And retval <> SOCKET_ERROR Then reply = reply & Left(buffer." ' Make the socket non-blocking.h_addr_list. Len(buffer). FIONBIO. Len(sockinfo)) If retval <> 0 Then Debug. retval = ioctlsocket(sock.vbapi. ByVal buffer. 0) Debug.sin_addr = ipAddress ' Padding characters. retval) End If http://216.168.com:80 (where the web server listens).com" & vbCrLf & _ "User-Agent: HTTP-Test-Program" & vbCrLf & vbCrLf retval = send(sock.Print "Unable to create socket!" GoTo Cleanup End If ' Make a connection to www. A more sophisticated program ' would watch to see if the connection ever times out (i.sin_port = htons(80) ' Connect to this IP address.html file. Waiting for reply. . CopyMemory pIPAddress.html (4 of 5) [9/1/2002 5:08:45 PM] . 4 ' Create a socket.sin_family = AF_INET ' Connect to port 80. With sockinfo ' Use Internet Protocol (IP) . such code is omitted here.Print "Attempting to connect.. vbNullChar) End With Debug.92/vbapi/ref/c/closesocket.e.Print "Sent request. buffer = "GET / HTTP/1. sockinfo. SOCK_STREAM.Windows API Guide: closesocket Function GoTo Cleanup End If ' Get the server's IP address out of the structure. . ByVal pIPAddress. Len(buffer).1" & vbCrLf & _ "Host: www.." retval = connect(sock. . Do buffer = Space(4096) retval = recv(sock..26. 1) ' Read the response from the other system. ByVal buffer..vbapi. For brevity. 4 CopyMemory ipAddress.

Debug. Copyright Information Revised October 29.vbapi. Back to the Reference section. Last Modified: January 21.html http://216. E-mail: vbapi@vbapi.html (5 of 5) [9/1/2002 5:08:45 PM] .Print reply ' Perform the necessary cleanup at the end.168.com Send Encrypted E-Mail This page is at http://www.Print "Document Retrieved:" Debug. DoEvents Loop Until retval = 0 ' Print the response from the server.26. Cleanup: retval = closesocket(sock) retval = WSACleanup() End Sub See Also socket Category Winsock Back to the Function list.com/ref/c/closesocket. 2000 Go back to the Windows API Guide home page.92/vbapi/ref/c/closesocket.Windows API Guide: closesocket Function ' Process background events so the program doesn't appear to freeze. 2001 This page is copyright © 2001 Paul Kuliniewicz.

vbforums. Return Value The function returns one of the following flags specifying the result of the region combination operation: ERROR An error occured while trying to combine the regions. Windows NT: Requires Windows NT 3. Windows 2000: Supported.part of the VB-World Network | www. ByVal nCombineMode As Long) As Long Platforms q q q q q Windows 95: Supported.e.Windows API Guide: CombineRgn Function vbapi.html (1 of 3) [9/1/2002 5:09:00 PM] .com | www.1 or later.com | www.vbshop. Note that the region that receives the combined regions must already be a region -. NULLREGION The combined region is empty. SIMPLEREGION The combined region forms a rectangle.vbworld. Description & Usage CombineRgn combines two regions to form a third region.com | www.168. The two regions can be combined using a variety of logical operators. Parameters hDestRgn A handle to the region to be set to the combination of the two source regions.vbapi. Windows CE: Requires Windows CE 1. ByVal hSrcRgn2 As Long.92/vbapi/ref/c/combinergn.0 or later. COMPLEXREGION The combined region is not empty but is also not a rectangle.dll" (ByVal hDestRgn As Long.com .com | CombineRgn Function Declare Function CombineRgn Lib "gdi32.vbsquare.com | www. null. Visual Basic-Specific Issues None. Windows 98: Supported. i..the function cannot create a new one but can change an existing one. This region must already have been http://216. ByVal hSrcRgn1 As Long.26.

RGN_XOR The combined region is all of the area contained in either of the two source regions. RGN_DIFF The combined region is all the area of the first source region except for the portion also included in the second source region. 0. RGN_OR The combined region is all the area contained in either of the two source regions. RGN_COPY The combined region is identical to the first source region.html (2 of 3) [9/1/2002 5:09:00 PM] . 0. hRgn2 As Long ' elliptical and rectangular source regions. hDarkBrush As Long ' handles to light gray and dark gray brushes Dim retval As Long ' return value ' Create the four regions. 75. 50. hAndRgn As Long ' regions set to the non-intersection and intersection Dim hLightBrush As Long. create overlapping elliptical and rectangular regions. fill the nonoverlapping areas with ' a light gray brush.50)-(200. 200) ' rectangle (150. Dim hRgn1 As Long.92/vbapi/ref/c/combinergn. nCombineMode One of the following flags specifying the logical operation to use to combine the two regions: RGN_AND The combined region is the overlapping area of the two source regions. 300. hRgn1 = CreateEllipticRgn(100. excluding any overlap.200) hXorRgn = CreateRectRgn(0. ' On window Form1. The initial settings of hXorRgn and hAndRgn are irrelevant. hSrcRgn1 The first of the two source regions. including any overlap. hSrcRgn2 The second of the two source regions. 100) ' bounding rect (100.100) hRgn2 = CreateRectRgn(150.26. The second source region is ignored.75)-(300. Dim hXorRgn As Long. 0) ' meaningless initialization http://216. ' Fill the overlapped area with a dark gray brush. Constant Definitions Const Const Const Const Const Const Const Const Const ERROR = 0 NULLREGION = 1 SIMPLEREGION = 2 COMPLEXREGION = 3 RGN_AND = 1 RGN_OR = 2 RGN_XOR = 3 RGN_DIFF = 4 RGN_COPY = 5 Example ' This code is licensed according to the terms and conditions listed here. although its contents when passed to the function is irrelevant. 200.168.Windows API Guide: CombineRgn Function created.

hDarkBrush) ' fill intersection ' Delete retval = retval = retval = retval = the four regions to free up resources. RGN_AND) ' intersection ' Now get the necessary stock brushes and fill in the two combined regions.92/vbapi/ref/c/combinergn. hLightBrush = GetStockObject(LTGRAY_BRUSH) ' light gray solid brush hDarkBrush = GetStockObject(DKGRAY_BRUSH) ' dark gray solid brush retval = FillRgn(Form1. hRgn1.html (3 of 3) [9/1/2002 5:09:00 PM] . Go back to the Reference section index.Windows API Guide: CombineRgn Function hAndRgn = CreateRectRgn(0. 2000 Go back to the Windows API Guide home page. hLightBrush) ' fill non-intersection retval = FillRgn(Form1. retval = CombineRgn(hXorRgn.26.com/ref/c/combinergn.html http://216. 0. 0.hDC.168. 1999 This page is copyright © 1999 Paul Kuliniewicz. 0) ' meaningless initialization ' Now set hAndRgn to the intersection of the two source regions and hXorRgn to ' the non-intersection of the two source regions. E-mail: vbapi@vbapi.hDC. hRgn2.com Send Encrypted E-Mail This page is at http://www.vbapi. DeleteObject(hRgn1) DeleteObject(hRgn2) DeleteObject(hXorRgn) DeleteObject(hAndRgn) Category Regions Go back to the alphabetical Function listing. hRgn1. Copyright Information Revised October 29. hRgn2. hXorRgn. RGN_XOR) ' non-intersection retval = CombineRgn(hAndRgn. Last Modified: December 22. hAndRgn.

CDERR_MEMALLOCFAILURE = &H9 The function failed to allocate sufficient memory.com | www.com . Win NT CommDlgExtendedError returns the error code from the last common dialog box function.92/vbapi/ref/c/commdlgextendederror. CFERR_CHOOSEFONTCODES = &H2000 The error involved the Choose Font common dialog box. CDERR_LOCKRESFAILURE = &H8 The function failed to lock the desired resource. CDERR_NOHINSTANCE = &H4 The function was not provided with a valid instance handle (if one was required).vbforums. CDERR_INITIALIZATION = &H2 The function failed during initialization (probably insufficient memory).Windows API Guide: CommDlgExtendedError Function vbapi. CDERR_LOADSTRFAILURE = &H5 The function failed to load the desired string.com | www. the return value is exactly one of the following common dialog error flags: CDERR_DIALOGFAILURE = &HFFFF The function could not open the dialog box. CDERR_GENERALCODES = &H0 The error involved a general common dialog box property.com | www. If an error with a common dialog function did occur. The function's return value is undefined if the last common dialog function call was successful.com | CommDlgExtendedError Function Declare Function CommDlgExtendedError Lib "comdlg32. CDERR_STRUCTSIZE = &H1 The function was provided with an invalid structure size. CFERR_NOFONTS = &H2001 http://216. Win 95/98. CFERR_MAXLESSTHANMIN = &H2002 The function was provided with a maximum font size value smaller than the provided minimum font size.html (1 of 3) [9/1/2002 5:09:19 PM] . use GetLastError instead. This function does not return error codes for any other API function.part of the VB-World Network | www. CDERR_NOTEMPLATE = &H3 The function was not provided with a valid template (if one was required). for that.168.vbapi.dll" () As Long Platforms: Win 32s.vbshop. CDERR_LOADRESFAILURE = &H7 The function failed to load the desired resource.vbworld. CDERR_NOHOOK = &HB The function was not provided with a valid hook function handle (if one was required).com | www.vbsquare. CDERR_FINDRESFAILURE = &H6 The function failed to find the desired resource.26. CDERR_MEMLOCKFAILURE = &HA The function failed to lock the desired memory. CDERR_REGISTERMSGFAIL = &HC The function failed to successfully register a window message.

PDERR_NODEFAULTPRN = &H1008 The function could not find a default printer.168. PDERR_SETUPFAILURE = &H1001 The function failed to load the desired resources. FNERR_BUFFERTOOSMALL = &H3003 The function was provided with a filename buffer which was too small. FNERR_INVALIDFILENAME = &H3002 The function was provided with or received an invalid filename. PDERR_NODEVICES = &H1007 The function could not find any printers. ' Then display the error code provided.92/vbapi/ref/c/commdlgextendederror. PDERR_RETDEFFAILURE = &H1003 The handles to the data structures provided were nonzero even though the function was asked to return information about the default printer.. PDERR_PARSEFAILURE = &H1002 The function failed to parse the printer-related strings in WIN. Dim filebox As OPENFILENAME ' structure that sets the dialog box Dim fname As String ' will receive selected file's name Dim retval As Long ' return value Dim errcode As long ' receives the error code http://216.e. PDERR_GETDEVMODEFAIL = &H1005 The printer driver failed to initialize the DEVMODE structure. FNERR_SUBCLASSFAILURE = &H3001 The function had insufficient memory to subclass the list box. but the default printer's actual settings were different. they hold conflicting information). PDERR_DNDMMISMATCH = &H1009 The data in the two data structures describe different printers (i.html (2 of 3) [9/1/2002 5:09:19 PM] .INI.Windows API Guide: CommDlgExtendedError Function The function could not find any existing fonts.INI about the requested printer. PDERR_DEFAULTDIFFERENT = &H100C The function was told that the information provided described the default printer.26. FNERR_FILENAMECODES = &H3000 The error involved the Open File or Save File common dialog box. PDERR_CREATEICFAILURE = &H100A The function failed to create an information context. Example: ' Give the Open File dialog box an insufficient buffer size. PDERR_INITFAILURE = &H1006 The function failed during initialization. FRERR_BUFFERLENGTHZERO = &H4001 The function was provided with an invalid buffer. FRERR_FINDREPLACECODES = &H4000 The error involved the Find or Replace common dialog box. PDERR_PRINTERNOTFOUND = &H100B The function could not find information in WIN. PDERR_PRINTERCODES = &H1000 The error involved the Print common dialog box. PDERR_LOADDRVFAILURE = &H1004 The function failed to load the desired device driver.

com/ref/c/commdlgextendederror.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY ' Execute the dialog box retval = GetOpenFileName(filebox) If retval = 0 Then ' some error occured." If errcode = FNERR_INVALIDFILENAME Then Debug.Windows API Guide: CommDlgExtendedError Function ' Configure how the dialog box will look filebox. End If End If See Also: GetLastError Category: Common Dialog Go back to the alphabetical Function listing.vbapi. E-mail: vbapi@vbapi." ' etc. Copyright Information.168.lpstrFileTitle = Space(255) ' initialize buffer that receives filename of file filebox. or Cancel was pressed errcode = CommDlgExtendedError() ' get the error code for GetOpenFileName If errcode = FNERR_BUFFERTOOSMALL Then Debug.hwndOwner = Form1.Print "An invalid filename was provided. Go back to the Reference section index.com Send Encrypted E-Mail This page is at http://www.html (3 of 3) [9/1/2002 5:09:19 PM] .hWnd ' handle of the form calling the function filebox.26.html http://216. This page is copyright © 2000 Paul Kuliniewicz.lStructSize = Len(filebox) ' the size of the structure filebox.lpstrFilter = "Text Files" & vbNullChar & "*.nMaxFileTitle = 255 ' length of filename buffer ' Allow only existing files and hide the read-only check box filebox.*" & vbNullChar & vbNullChar filebox. Go back to the Windows API Guide home page.nMaxFile = 0 ' length of file and pathname buffer filebox.Print "The buffer provided was too small to hold the filename.lpstrFile = "" ' ERROR: an empty buffer! filebox.txt" & vbNullChar & "All Files" & vbNullChar & "*.lpstrTitle = "Open File" ' text displayed in the box's title bar ' The next line sets up the file types drop-box filebox.92/vbapi/ref/c/commdlgextendederror.

lpFileTime2 As FILETIME) As Long Platforms: Win 32s.92/vbapi/ref/c/comparefiletime.wYear = 1999 jantime. Example: ' Determine if file C:\MyProgram\datafile.wMonth = 1: jantime.vb-shop.vbworld. lpFileTime1 The first of the two times to compare. if any.dll" (lpFileTime1 As FILETIME. the function returns -1. 1999 at midnight: jantime. the function returns 1. Win NT CompareFileTime compares two times stored in FILETIME format.26.txt was created before ' Jan 5.com | CompareFileTime Function Declare Function CompareFileTime Lib "kernel32. GENERIC_READ.com | www. Dim hfile As Long ' receives the handle to the file Dim ctime As FILETIME ' receives creation date and time of the file Dim atime As FILETIME ' receives last access date and time of the file Dim wtime As FILETIME ' receives last write-to date and time of the file Dim jantime As SYSTEMTIME ' will be set to Jan 5. 1999. the function returns 0. comes before the other chronologically.vbapi." End ' abort the program End If ' Get the various times and dates associated with the file: retval = GetFileTime(hfile. If the two times are equal. 1999 Dim janfiletime As FILETIME ' will receive analogous time as jantime Dim comptimes As Long ' receives comparison of ctime and janfiletime Dim retval As Long ' return value ' Get a handle to the file (note how the alternate declare is used): hfile = CreateFileNS("C:\MyProgram\datafile. Note how CreateFile's alternate declare must be used under Win 95/98 ' see that function's page for more information.wDay = 5: jantime.txt". ctime. lpFileTime2 The second of the two times to compare.com | www.com | www. atime.wMinute = 0: jantime.Print "Could not open the file C:\MyProgram\datafile. wtime) ' Load jantime with the date January 5.part of the VB-World Network | www.com . FILE_ATTRIBUTE_ARCHIVE. Win 95/98. The function determines which of the two times.vbsquare.vbforums.html (1 of 2) [9/1/2002 5:09:31 PM] . If the first time is earlier than the second time.168.com | www.txt. OPEN_EXISTING. 0) If hfile = -1 Then ' if the file could not be opened Debug. 0.wSecond = 0 http://216. If the first time is later than the second time.wHour = 0: jantime. FILE_SHARE_READ.Windows API Guide: CompareFileTime Function vbapi.

vbapi. This page is copyright © 2000 Paul Kuliniewicz. 1999.Windows API Guide: CompareFileTime Function ' Convert jantime into FILETIME format so it can be compared with ctime: retval = SystemTimeToFileTime(jantime." If comptimes = 0 Then Debug.Print "File was created after midnight. 1999.html (2 of 2) [9/1/2002 5:09:31 PM] . E-mail: vbapi@vbapi. janfiletime) ' Compare the two times and display the relation: comptimes = CompareFileTime(ctime. 1999." ' Close the file retval = CloseHandle(hfile) Category: Time Go back to the alphabetical Function listing. January 5.Print "File was created at midnight." If comptimes = 1 Then Debug.html http://216. January 5. January 5.com/ref/c/comparefiletime.com Send Encrypted E-Mail This page is at http://www.Print "File was created before midnight. Go back to the Windows API Guide home page.26. janfiletime) If comptimes = -1 Then Debug. Go back to the Reference section index.168.92/vbapi/ref/c/comparefiletime. Copyright Information.

ByVal lpString1 As String.0 or later.1 or later.vbsquare. CSTR_EQUAL The first string is equal to (but not necessarily identical to) the second string.e.com | www.com | www.vbworld. ByVal lpString2 As String.part of the VB-World Network | www. ByVal cchCount2 As Long) As Long Platforms q q q q q Windows 95: Supported.com | www. Description & Usage CompareString compares two strings and determines which one would come first in an alphabetic sort. Windows NT: Requires Windows NT 3. the first string comes before the second string in alphabetical order). until an unequal pair of characters is found.vbforums. Windows 2000: Supported. then their second characters. Parameters http://216. In a word sort. The function compares strings by first comparing their first characters.26. all symbols except hyphens and apostrophes come before the letter "a" (hyphens and apostrophes are treated differently)..168. ByVal dwCmpFlags As Long.vbapi.com | www. If successful. the function returns one of the following flags specifying the result of the comparison: CSTR_LESS_THAN The first string is less than the second string (i.com . Windows 98: Supported.com | CompareString Function Declare Function CompareString Lib "kernel32. Return Value If an error occured. Visual Basic-Specific Issues None.dll" Alias "CompareStringA" (ByVal Locale As Long. ByVal cchCount1 As Long.vbshop.Windows API Guide: CompareString Function vbapi. Although this function can use a number of different comparisons.92/vbapi/ref/c/comparestring. Windows CE: Requires Windows CE 1. the function returns 0 (use GetLastError to get the error code). by default it conducts a case-sensitive word sort.html (1 of 4) [9/1/2002 5:09:46 PM] . etc. CSTR_GREATER_THAN The first string is greater than the second string.

lpString2 The second string to compare. lpString1 must end in a terminating null character. including hyphens and apostrophes.92/vbapi/ref/c/comparestring. do not differentiate between Hiragana and Katakana characters. cchCount1 The length of lpString1. cchCount2 The length of lpString2. set this parameter to 0. NORM_IGNORESYMBOLS Ignore symbols. ' Use a case-senitive. Constant Definitions Const Const Const Const Const Const Const Const Const Const Const CSTR_LESS_THAN = 1 CSTR_EQUAL = 2 CSTR_GREATER_THAN = 3 LOCALE_SYSTEM_DEFAULT = &H400 LOCALE_USER_DEFAULT = &H800 NORM_IGNORECASE = &H1 NORM_IGNOREKANATYPE = &H10000 NORM_IGNORENONSPACE = &H2 NORM_IGNORESYMBOLS = &H4 NORM_IGNOREWIDTH = &H20000 SORT_STRINGSORT = &H1000 Example ' This code is licensed according to the terms and conditions listed here. come before the letter "a".26. This could also be one of the following flags: LOCALE_SYSTEM_DEFAULT The system's default locale. lpString1 The first string to compare. NORM_IGNORENONSPACE Ignore nonspacing characters. lpString2 must end in a terminating null character. NORM_IGNOREWIDTH Do not differentiate between equivalent single-byte and double-byte characters.168. In a string sort. SORT_STRINGSORT Use a string sort instead of a word sort. NORM_IGNORECASE Conduct a case-insensitive search.html (2 of 4) [9/1/2002 5:09:46 PM] . LOCALE_USER_DEFAULT The user's default locale. string sort comparison method to alphabetically http://216. all symbols. NORM_IGNOREKANATYPE For Japanese characters.Windows API Guide: CompareString Function Locale The locale identifier of the locale to use to compare the strings. If this is -1. To use the default comparison. If this is -1. dwCmpFlags A combination of the following flags specifying options for the comparison.

Windows API Guide: CompareString Function ' sort nine words.) Dim words(1 To 9) As String ' the words to sort Dim tempstr As String ' buffer used to swap strings Dim oc As Integer. Len(words(oc)).. compval = CompareString(threadlocale. ic As Integer ' counter variables Dim compval As Long ' result of comparison Dim threadlocale As Long ' locale ID of this thread ' Get the locale of this thread (i.Print words(oc) Next oc See Also lstrcmp.html (3 of 4) [9/1/2002 5:09:46 PM] . words(ic). For oc = 1 To 9 Debug. Len(words(ic))) ' If words(oc) is greater. "can't" "cant" "cannot" "pants" "co-op" "coop" "Denver" "denver" "denveR" ' Sort the strings. The sorting method simply compares each possible ' pair of words. swapping any pairs which are out of order. threadlocale = GetThreadLocale() ' Load the words(1) = words(2) = words(3) = words(4) = words(5) = words(6) = words(7) = words(8) = words(9) = nine strings into the array. For oc = 1 To 8 ' first string of the pair For ic = oc + 1 To 9 ' second string of the pair ' Compare the two strings. lstrcmpi Category Strings http://216. of this program).168.e. swap them. they are switched.26. SORT_STRINGSORT.92/vbapi/ref/c/comparestring. ' (Compare these results to those from using lstrcmp for the comparison. if a pair is out of alphabetical order. words(oc). If compval = CSTR_GREATER_THAN Then tempstr = words(oc) words(oc) = words(ic) words(ic) = tempstr End If Next ic Next oc ' Display the list of sorted words.

html (4 of 4) [9/1/2002 5:09:46 PM] .168. E-mail: vbapi@vbapi.26. 2000 Go back to the Windows API Guide home page.92/vbapi/ref/c/comparestring.com Send Encrypted E-Mail This page is at http://www. Last Modified: December 30. Copyright Information Revised October 29.html http://216. Go back to the Reference section index. 1999 This page is copyright © 1999 Paul Kuliniewicz.vbapi.Windows API Guide: CompareString Function Go back to the alphabetical Function listing.com/ref/c/comparestring.

which vary depending on the base protocols being used (e.g. Windows CE: Requires Windows CE 1.com | www.vbapi.0 or later.com | www..part of the VB-World Network | www. Return Value If successful.168.vbsquare. namelen The length of the structure passed as name.26. Constant Definitions http://216.Windows API Guide: connect Function vbapi. Description & Usage connect establishes a connection between a socket and a network host. Windows NT: Requires Windows NT 3. The descriptor is obtained by a previous call to socket.com | www. ByVal namelen As Long) As Long Platforms q q q q q Windows 95: Supported.com | connect Function Declare Function connect Lib "wsock32.html (1 of 5) [9/1/2002 5:09:56 PM] . UDP/IP).vbshop.1 or later. the function returns SOCKET_ERROR (use WSAGetLastError to get the error code). Windows 98: Supported.com | www. the function returns zero. Visual Basic-Specific Issues None. TCP/IP vs. name Information describing the network host to connect to. Once the connection is established. If an error occured. name As sockaddr.dll" (ByVal s As Long. The Winsock implementation automatically handles the details of the connection.com . data can be sent to and from the network host. Parameters s A descriptor of the socket to use to connect. Windows 2000: Supported.vbworld.92/vbapi/ref/c/connect.vbforums.

lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. This example supports a very crude implementation of HyperText Transport Protocol (HTTP). ByVal prototype As Long. the GoTo statements skip down to the end if an unrecoverable error occurs. is output to the Debug window.vbapi. I would use that instead of GoTo.html (2 of 5) [9/1/2002 5:09:56 PM] .dll" (ByVal wVersionRequested As Integer. To prevent the program from appearing to lock up in the event of a momentary interruption in the transfer.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32. a nonblocking socket is used. Note the careful use of GoTo in this example. _ ByVal protocol As Long) As Long Public Type sockaddr sin_family As Integer sin_port As Integer http://216.92/vbapi/ref/c/connect.com). Since there are lots of things that can go wrong.168.dll" () As Long Public Const AF_INET = 2 Public Const SOCK_STREAM = 1 Public Declare Function gethostbyname Lib "wsock32. and WSACleanup must be called at the end no matter what happens. with HTTP headers removed. The document downloaded.dll" (ByVal name As String) As Long Public Type hostent h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Declare Function htons Lib "wsock32. sending a request to the server and receiving the document. place a command button named cmdDownload on a form window. If VB had better exception handling.26.dll" (ByVal af As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.Windows API Guide: connect Function Const SOCKET_ERROR = -1 Example Download the main page of this web site (http://www. To use this example. ' This code is licensed according to the terms and conditions listed here.dll" (ByVal hostshort As Integer) As Integer Public Declare Function socket Lib "wsock32.

Public Function MAKEWORD(ByVal bLow As Byte. retval = WSAStartup(MAKEWORD(2.dll" Alias "RtlMoveMemory" (Destination As Any. 2) & Right("00" & Hex(bLow).dll" (ByVal s As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. argp As Long) As Long Public Const FIONBIO = &H8004667E Public Declare Function send Lib "wsock32. ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh). _ ByVal flags As Long) As Long Public Declare Function closesocket Lib "wsock32. name As sockaddr. _ ByVal flags As Long) As Long Public Declare Function recv Lib "wsock32. ByVal namelen _ As Long) As Long Declare Function ioctlsocket Lib "wsock32.26. ByVal length As Long. ByVal Length As Long) Public Const SOCKET_ERROR = -1 ' Define a useful macro.dll" (ByVal s As Long. buf As Any. Source _ As Any.168. ByVal cmd As Long.Windows API Guide: connect Function sin_addr As Long sin_zero As String * 8 End Type Public Declare Function connect Lib "wsock32. pHostinfo = gethostbyname("www.dll" (ByVal s As Long. retval Exit Sub End If ' Get information about the server to connect to.vbapi. ByVal length As Long.92/vbapi/ref/c/connect.Print "Unable to initialize Winsock! --".dll" (ByVal s As Long.com") If pHostinfo = 0 Then http://216. wsockinfo) If retval <> 0 Then Debug. buf As Any. 2). *** Private Sub Dim Dim Dim Dim Dim Dim Dim Dim Dim Dim cmdDownload_Click() wsockinfo As WSADATA sock As Long pHostinfo As Long hostinfo As hostent pIPAddress As Long ipAddress As Long sockinfo As sockaddr buffer As String reply As String retval As Long ' ' ' ' ' ' ' ' ' ' info about Winsock the socket descriptor pointer to info about the host computer info about the host computer pointer to host's IP address host's IP address settings for the socket buffer for sending and receiving data accumulates server's reply generic return value ' Begin a Winsock session. 2)) End Function ' *** Place the following code inside the form window.html (3 of 5) [9/1/2002 5:09:56 PM] .dll" (ByVal s As Long.

retval = ioctlsocket(sock.html file. sock = socket(AF_INET.com!" GoTo Cleanup End If ' Get the server's IP address out of the structure.sin_port = htons(80) ' Connect to this IP address.." ' Make the socket non-blocking. Waiting for reply. ByVal pIPAddress. CopyMemory hostinfo.168.h_addrtype <> AF_INET Then Debug.26.com" & vbCrLf & _ "User-Agent: HTTP-Test-Program" & vbCrLf & vbCrLf retval = send(sock.Print "Unable to create socket!" GoTo Cleanup End If ' Make a connection to www.92/vbapi/ref/c/connect. 4 CopyMemory ipAddress.sin_family = AF_INET ' Connect to port 80. sockinfo.com:80 (where the web server listens).html (4 of 5) [9/1/2002 5:09:56 PM] . buffer = "GET / HTTP/1. 0) Debug. ByVal buffer.vbapi.Print "Unable to connect!" GoTo Cleanup End If ' Send an HTTP/GET request for the /index. ByVal hostinfo. so calls to recv don't halt the program waiting for input.. A more sophisticated program ' would watch to see if the connection ever times out (i. CopyMemory pIPAddress. 4 ' Create a socket. Len(buffer).Print "Attempting to connect. 0) If sock = SOCKET_ERROR Then Debug.Windows API Guide: connect Function Debug. Len(sockinfo)) If retval <> 0 Then Debug.vbapi.sin_zero = String(8..sin_addr = ipAddress ' Padding characters.vbapi. FIONBIO. vbNullChar) End With Debug.Print "Sent request.e. SOCK_STREAM. if the connection is http://216. With sockinfo ' Use Internet Protocol (IP) .. Len(hostinfo) If hostinfo.Print "Couldn't get IP address of www... ByVal pHostinfo." retval = connect(sock. 1) ' Read the response from the other system.h_addr_list. .Print "Unable to resolve host!" GoTo Cleanup End If ' Copy information about the server into the structure. .1" & vbCrLf & _ "Host: www. .

0) If retval <> 0 And retval <> SOCKET_ERROR Then reply = reply & Left(buffer.168.92/vbapi/ref/c/connect. Back to the Reference section.Print reply ' Perform the necessary cleanup at the end.com/ref/c/connect.Print "Document Retrieved:" Debug. buffer = Space(4096) retval = recv(sock. retval) End If ' Process background events so the program doesn't appear to freeze.26.com Send Encrypted E-Mail This page is at http://www. 2000 Go back to the Windows API Guide home page. Len(buffer).html http://216.html (5 of 5) [9/1/2002 5:09:56 PM] .vbapi. Copyright Information Revised October 29. Last Modified: January 21. such code is omitted here. Debug. 2001 This page is copyright © 2001 Paul Kuliniewicz. ByVal buffer. Do For brevity. E-mail: vbapi@vbapi. DoEvents Loop Until retval = 0 ' Print the response from the server. Cleanup: retval = closesocket(sock) retval = WSACleanup() End Sub Category Winsock Back to the Function list.Windows API Guide: connect Function ' lost).

lpNewFileName The target file.vb-shop.part of the VB-World Network | www.. i. "C:\Junk\buffer.vbforums.vbworld.Windows API Guide: CopyFile Function vbapi. Win 95/98. just like copying a file in Windows Explorer or in some other way. Dim retval As Long ' return value ' copy the file retval = CopyFile("C:\MyStuff\temp.Print "Copy failed -. The function retuns 1 if successful. i.e.com | CopyFile Function Declare Function CopyFile Lib "kernel32. If non-zero.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String. the new file to create that will be the copy.txt. it will either overwrite the target file if it already exists.com | www. ' Do not overwrite C:\Junk\buffer. the function will overwrite lpNewFileName if it already exists.html (1 of 2) [9/1/2002 5:10:37 PM] . lpExistingFileName The source file.txt". Else ' success Debug..com | www.txt to C:\Junk\buffer. bFailIfExists If 0.168. Example: ' Copy the file C:\MyStuff\temp.e.txt already exists.92/vbapi/ref/c/copyfile. Depending on the value for bFailIfExists. 1) If retval = 0 Then ' failure Debug.vbsquare.txt if it already exists.26.com . the function will instead fail. or 0 if an error occured.com | www." End If See Also: MoveFile http://216. or will fail.Print "Copy succeeded. Win NT CopyFile copies a file from one location to another. ByVal bFailIfExists As Long) As Long Platforms: Win 32s.com | www.C:\Junk\buffer. the file to copy from.txt". ByVal lpNewFileName As String.vbapi.

com/ref/c/copyfile. Go back to the Reference section index.Windows API Guide: CopyFile Function Category: Files Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page.26. E-mail: vbapi@vbapi.html http://216.92/vbapi/ref/c/copyfile.168.com Send Encrypted E-Mail This page is at http://www. Copyright Information.html (2 of 2) [9/1/2002 5:10:37 PM] .vbapi.

is perfectly identical to the MoveMemory function. the ByVal keyword must preceed it.html (1 of 2) [9/1/2002 5:10:49 PM] . http://216.92/vbapi/ref/c/copymemory. they actually are the same function! CopyMemory moves the contents of a portion of memory from one location to another. Description & Usage CopyMemory.168.com | www.vbapi. Windows 2000: Supported.com | www. Visual Basic-Specific Issues A pointer to any variable can be automatically generated merely be passing that variable as either Destination or Source.com | www.26. After the copy.dll" Alias "RtlMoveMemory" (Destination As Any.vbshop. which receives the transfered data. which initially holds the data to be transfered.Windows API Guide: CopyMemory Function vbapi. the original contents in the source are set to zeros. Windows 98: Supported.vbworld. Length The number of bytes of data to copy from the source memory location to the target memory location.com . The two locations are identified by pointers to the memory addresses. However.1 or later.part of the VB-World Network | www. Windows CE: Not Supported. Windows NT: Requires Windows NT 3. ByVal Length As Long) Platforms q q q q q Windows 95: Supported. Parameters Destination A pointer to the memory address to use as the target. as far as the Windows API is concerned. Source A pointer to the memory address to use as the source.com | www.vbforums.com | CopyMemory Function Declare Sub CopyMemory Lib "kernel32. in fact. if either a String or a Long holding the desired memory address is passed.vbsquare. Source As Any. Return Value CopyMemory does not return a value.

source(0).92/vbapi/ref/c/copymemory.vbapi. ' the contents of the source array are set to 0. 1999 This page is copyright © 1999 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www. For c = 0 To 9 ' loop through each element source(c) = c ' set each element's value to its index Next c ' Transfer the data from the target array to the source array.Windows API Guide: CopyMemory Function Example ' This code is licensed according to the terms and conditions listed here. Dim source(0 To 9) As Byte ' source array of 10 bytes Dim target(0 To 9) As Byte ' similarly sized target array Dim c As Integer ' counter variable ' Fill the source array with some information.Print target(c). For c = 0 To 9 Debug. Copyright Information Go back to the Windows API Guide home page. 10 ' copy all 10 bytes Note how pointers ' Verify that the contents were transfered. ' this will now contain the information Next c See Also MoveMemory Category Memory Go back to the alphabetical Function listing.168. After the "copy". ' are implied merely by passing the arrays as usual. Go back to the Reference section index. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:10:49 PM] .html http://216.com/ref/c/copymemory. CopyMemory target(0). ' Transfer the contents of one byte array to another.26. Last Modified: July 28.

lpSourceRect The source rectangle. This is faster than setting all four values manually in your code.com | www.com | www.vb-shop.vbapi. lpDestRect The target rectangle to set. target As RECT ' source & target rectangles Dim retval As Long ' return value ' Get the rectangle of Form1 into source retval = GetWindowRect(Form1. This is done by duplicating all of the source rectangle's member values to the corresponding ones in the target rectangle.com | www.vbsquare. lpSourceRect As RECT) As Long Platforms: Win 32s.com | www.hWnd.92/vbapi/ref/c/copyrect. Example: ' Set the source and target rectangels equal to the rectangle ' of the window by copying the source to the target Dim source As RECT.Windows API Guide: CopyRect Function vbapi. source) ' Copy source into target retval = CopyRect(target. source) See Also: EqualRect Category: Rectangles Go back to the alphabetical Function listing. or 1 if successful.26.html (1 of 2) [9/1/2002 5:10:56 PM] . http://216.part of the VB-World Network | www. The function returns 0 if an error occured. Win NT CopyRect sets one rectangle equal to another.com .com | CopyRect Function Declare Function CopyRect Lib "user32.vbforums. Go back to the Reference section index.dll" (lpDestRect As RECT.vbworld. Win 95/98.168.

26.92/vbapi/ref/c/copyrect.vbapi.168.com/ref/c/copyrect.html http://216.Windows API Guide: CopyRect Function This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.html (2 of 2) [9/1/2002 5:10:56 PM] . Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.

Windows NT: Requires Windows NT 3.vbsquare.92/vbapi/ref/c/cotaskmemfree. Return Value CoTaskMemFree does not return a value.vbforums.com | www. http://216.com | CoTaskMemFree Function Declare Sub CoTaskMemFree Lib "ole32.vbapi. Any folder under My Computer ' may be selected.com | www.Windows API Guide: CoTaskMemFree Function vbapi.part of the VB-World Network | www.0 or later.k.a. Windows 2000: Supported.168.vbshop. ' Open the Browse for Folder dialog box and display both the display name and ' the actual name of the folder (if it is not a virtual folder).html (1 of 3) [9/1/2002 5:11:04 PM] . Visual Basic-Specific Issues None.dll" (ByVal pv As Long) Platforms q q q q q Windows 95: Supported.26.com .com | www.vbworld.com | www. This function will free the memory associated with a pointer to an ITEMIDLIST structure (a. Windows CE: Requires Windows CE 2. a PIDL) which was created by a Windows shell API function.1 or later. Windows 98: Supported. Description & Usage CoTaskMemFree frees some types of blocks of allocated memory. Parameters pv A pointer to the memory block to free. Example ' This code is licensed according to the terms and conditions listed here. This function must be used on such blocks of memory to free system resources.

ulFlags = 0 ' no flags are needed here bi.hWnd ' window Form1 is the owner of the dialog box ' Specify the My Computer virtual folder as the root retval = SHGetSpecialFolderLocation(Form1. physpath End If ' Free the pidl returned by the function. InStr(physpath.Print "Physical Location: (virtual folder)" Else ' Remove the empty space and display the result.lpszTitle = "Please choose a folder.Print "The user selected: ".26.lParam = 0 ' not needed bi.168." ' Message displayed to the user bi. free the PIDL which was used to ' identify the My Computer virtual folder. physpath = Space(260) ' make room in the buffer retval = SHGetPathFromIDList(pidl. Go back to the Reference section index.hwndOwner = Form1. vbNullChar) .pszDisplayName. CoTaskMemFree bi. bi. CoTaskMemFree pidl End If ' Whether successful or not. physpath) If retval = 0 Then Debug.pidlRoot) ' Make room in the buffer to get the [virtual] folder's display name bi.92/vbapi/ref/c/cotaskmemfree.Print "Physical Location: ". display its physical location.hWnd.pszDisplayName = Space(260) bi. bi.html (2 of 3) [9/1/2002 5:11:04 PM] .pidlRoot Category OLE Go back to the alphabetical Function listing.Windows API Guide: CoTaskMemFree Function Dim Dim Dim Dim bi As BROWSEINFO ' structure passed to the function pidl As Long ' PIDL to the user's selection physpath As String ' string used to temporarily hold the physical path retval As Long ' return value ' Initialize the structure to be passed to the function.pszDisplayName ' If the folder is not a virtual folder. CSIDL_DRIVES.1) Debug. vbNullChar) 1) Debug.pszDisplayName = Left(bi. display its display name ' and its physical location on the system. If pidl <> 0 Then ' Remove the empty space from the display name variable. pidl = SHBrowseForFolder(bi) ' If the user selected something. physpath = Left(physpath. http://216.lpfn = 0 ' no callback function is being used bi. bi.pszDisplayName.iImage = 0 ' this will be set by the function ' Open the Browse for Folder dialog box. InStr(bi. bi.

Windows API Guide: CoTaskMemFree Function Last Modified: September 26. 1999 This page is copyright © 1999 Paul Kuliniewicz.168.92/vbapi/ref/c/cotaskmemfree.html http://216.com Send Encrypted E-Mail This page is at http://www.vbapi. E-mail: vbapi@vbapi.26. Copyright Information Revised October 29.com/ref/c/cotaskmemfree. 2000 Go back to the Windows API Guide home page.html (3 of 3) [9/1/2002 5:11:04 PM] .

Note that it is usually a better idea to put cursors into some sort of resource or separate file and load them instead of hard-wiring the cursors into the application code via this function. nHeight The height in pixels of the cursor. ByVal nWidth As Long. nWidth The width in pixels of the cursor. nYhotspot The y-coordinate of the cursor's hotspot. the cursor size must be one supported by the system.com | www. Win 95/98.26.) Note how the masks are loaded into the arrays.) Of course. lpANDbitPlane An array holding the AND mask for the cursor's image.com | CreateCursor Function Declare Function CreateCursor Lib "user32.com . the exact pixel which is considered to be the location of the cursor (such as the exact tip of the arrow cursor). or a handle to the newly created cursor if successful. Example: ' Create a 32x32 color cursor shaped somewhat like a yin-yang symbol. The function returns 0 if an error occured.Windows API Guide: CreateCursor Function vbapi. The new ' cursor is then set to be the cursor for 10 seconds. lpANDbitPlane As Any.com | www. Win NT CreateCursor creates a new cursor. relative to the cursor's upper-left corner. ByVal nXhotspot As Long. nXhotspot The x-coordinate of the cursor's hotspot.vbshop.vbapi. just to ' give them their due credit.part of the VB-World Network | www. relative to the cursor's upper-left corner. such as a Byte array (as the example below uses). lpXORbitPlane As Any) As Long Platforms: Win 32s. ByVal nHeight As Long. Dim hnewcursor As Long ' newly created cursor Dim holdcursor As Long ' receives handle of default cursor http://216.html (1 of 3) [9/1/2002 5:11:21 PM] .dll" (ByVal hInstance As Long. hInstance The instance handle of the application which is calling the function. The function also specifies the cursor's hotspot. ByVal nYhotspot As Long. The AND and XOR masks can be provided using any numeric array.com | www. (This is because this function relies on creating a cursor compatible with the display device.92/vbapi/ref/c/createcursor. Its image is formed by using an AND mask and a XOR mask provided by the function.vbsquare.vbworld. ' (The bit masks come from Microsoft's documentation on the API cursors function. use GetSystemMetrics to check.168. instead of generating one from a file or resource which is. which are used to place the cursor's image wherever it appears. The cursor created by this function must later be destroyed by using DestroyCursor.vbforums. lpXORbitPlane An array holding the XOR mask for the cursor's image.com | www.

Go back to the Reference section index. 2 * c + 1) Next c ' Finally. hnewcursor = CreateCursor(App. http://216. andbits(0). For c = 0 To 127 andbits(c) = "&H" & Mid(andbuffer.26. 2.2) on the cursor. it's ugly. 32. retval = DestroyCursor(hnewcursor) See Also: DestroyCursor Category: Cursor Go back to the alphabetical Function listing. ' To load the AND and XOR masks.html (2 of 3) [9/1/2002 5:11:21 PM] .Windows API Guide: CreateCursor Function Dim Dim Dim Dim andbuffer As String. 19. we put the raw hex values into the string buffers ' and use a loop to convert the hex values into numeric values and load them into ' the elements of the array. andbuffer = "FFFC3FFF" & "FFC01FFF" & "FF003FFF" & "FE00FFFF" & _ "F701FFFF" & "F003FFFF" & "F003FFFF" & "E007FFFF" & _ "C007FFFF" & "C00FFFFF" & "800FFFFF" & "800FFFFF" & _ "8007FFFF" & "8007FFFF" & "0003FFFF" & "0000FFFF" & _ "00007FFF" & "00001FFF" & "00000FFF" & "80000FFF" & _ "800007FF" & "800007FF" & "C00007FF" & "C0000FFF" & _ "E0000FFF" & "F0001FFF" & "F0001FFF" & "F8003FFF" & _ "FE007FFF" & "FF00FFFF" & "FFC3FFFF" & "FFFFFFFF" xorbuffer = "00000000" & "0003C000" & "003F0000" & "00FE0000" & _ "0EFC0000" & "07F80000" & "07F80000" & "0FF00000" & _ "1FF00000" & "1FE00000" & "3FE00000" & "3FE00000" & _ "3FF00000" & "7FF00000" & "7FF80000" & "7FFC0000" & _ "7FFF0000" & "7FFF8000" & "7FFFE000" & "3FFFE000" & _ "3FC7F000" & "3F83F000" & "1F83F000" & "1F83E000" & _ "0FC7E000" & "07FFC000" & "07FFC000" & "01FF8000" & _ "00FF0000" & "003C0000" & "00000000" & "00000000" ' Now load these hex values into the proper arrays.92/vbapi/ref/c/createcursor. andbits(0 To 127) As xorbits(0 To 127) As c As Integer. create this cursor! The hotspot is at (19. 32. Yes. Note the ' use of the line-continuation character here. 2 * c + 1) xorbits(c) = "&H" & Mid(xorbuffer. xorbits(0)) ' Set the new cursor as the current cursor for 10 seconds and then switch back. retval xorbuffer As String ' Byte ' stores the AND Byte ' stores the XOR As Long ' counter and buffers for masks mask mask return value ' Unfortunately. holdcursor = SetCursor(hnewcursor) ' change cursor Sleep 10000 ' wait for 10 seconds retval = SetCursor(holdcursor) ' change cursor back ' Destroy the new cursor. but there's no better way. VB does not provide a nice way to load lots of information into an array.168. Each sequence of eight hex ' characters represents one line in the 32x32 cursor.hInstance.

html http://216. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi. Go back to the Windows API Guide home page.Windows API Guide: CreateCursor Function This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.26.168.92/vbapi/ref/c/createcursor.html (3 of 3) [9/1/2002 5:11:21 PM] .com/ref/c/createcursor.

To use the default http://216.vbsquare.com .1 or later.com | CreateDC Function Declare Function CreateDC Lib "gdi32. ByVal lpszDevice As String. The object is identified by its name. the function returns a handle to the newly created device context. If successful. the function returns 0 (Windows NT. Windows 2000: Supported.vbshop.com | www. Do not use ReleaseDC with device contexts created by this function! Return Value If an error occured. a DEVMODE structure holding device initialization information for the device.Windows API Guide: CreateDC Function vbapi.92/vbapi/ref/c/createdc.com | www.0 or later. When you are finished using the device context in your program.vbforums.part of the VB-World Network | www.html (1 of 3) [9/1/2002 5:11:29 PM] .168. use the DeleteDC function to destroy it. Windows 98: Supported. Windows CE: Requires Windows CE 2.com | www.dll" Alias "CreateDCA" (ByVal lpszDriver As String.set to 0.26. lpszOutput Reserved -. lpInitData As Any) As Long Platforms q q q q q Windows 95: Supported. Parameters lpszDriver This string should normally be empty. except for using "DISPLAY" to reference the display driver. 2000: use GetLastError to get the error code). Description & Usage CreateDC creates a device context to a given object. Visual Basic-Specific Issues When passing 0 for lpInitData. lpInitData If desired. Windows NT: Requires Windows NT 3. the expression ByVal CLng(0) must be used.vbworld.vbapi. ByVal lpszOutput As Long. lpszDevice The name of the device to create a device context for.com | www. Windows NT. 2000: This could also be "WINSPOOL" to reference the print spooler.

RGB(0. ' The following are special declarations needed to allow string ' manipulation functions to use pointers to strings. Example: ' Print out a page with an ellipse drawn with a thickened black ' pen on it. For a more detailed ' description of the semi-confusing code below. printret) If retval = 0 Then Debug. buffer(1)) pi2. 0.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long ' Variable declarations Dim hPrintDC As Long ' handle to the printer's device context Dim di As DOCINFO ' information about the document to print Dim hPen As Long ' handle to the pen to draw the ellipse with Dim hOldPen As Long ' handle to the printer's previously selected pen Dim buffer(0 To 3076 / 4) As Long ' 3076-byte buffer Dim pi2 As PRINTER_INFO_2 ' receives info about the default printer Dim printret As Long ' receives the number of printers returned from EnumPrinters Dim spaceneeded As Long ' receives space requires for EnumPrinters Dim retval As Long ' return value ' Get the device and driver names of the default printer.26.168. "". consult the ' EnumPrinters page. hPrintDC = CreateDC("". using its default initialization.cbSize = Len(di) ' size of structure di.pDriverName = Space(lstrlen(buffer(4))) retval = lstrcpy(pi2. pi2.lpszDocName = "Printer API Demonstration" ' name of document di. 3076. buffer(0). 5.Print "No default printer is configured. The page is printed on the computer's default printer. 2.pPrinterName.html (2 of 3) [9/1/2002 5:11:29 PM] . set this to 0. retval = EnumPrinters(PRINTER_ENUM_DEFAULT.92/vbapi/ref/c/createdc. pi2.Windows API Guide: CreateDC Function initialization.pDriverName. spaceneeded. Declare Function lstrcpy Lib "kernel32. hPen = CreatePen(PS_SOLID. 0. ByVal CLng(0)) ' Create a solid black brush with a thickness of 5.dll" Alias "lstrcpyA" (ByVal lpString1 As String. buffer(4)) ' Create a device context to the printer.lpszOutput = 0 ' do not print to a file di. 0)) ' Load information about the document to print into the structure.pPrinterName = Space(lstrlen(buffer(1))) retval = lstrcpy(pi2.lpszDatatype = "" ' data type of file doesn't apply http://216.pPrinterName. di." End ' abort the program End If ' Copy the device and driver names to the structure. All the ' other information retrieved is not needed and is omitted here. ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32.

1000. hOldPen = SelectObject(hPrintDC. Copyright Information Revised October 29. Go back to the Reference section index. retval = StartDoc(hPrintDC.3000) retval = Ellipse(hPrintDC.html (3 of 3) [9/1/2002 5:11:29 PM] . retval = EndDoc(hPrintDC) ' The printer will now begin printing the document. retval = SelectObject(hPrintDC. retval = StartPage(hPrintDC) ' Select the pen for use with the printer. E-mail: vbapi@vbapi. hOldPen) ' End information about the first and only page. Last Modified: November 6. 2000. 1999 This page is copyright © 1999 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page. 3000) ' Restore the printer's previously selected pen.vbapi.Windows API Guide: CreateDC Function di. retval = EndPage(hPrintDC) ' End information about the document. DeleteDC(hPrintDC) See Also DeleteDC Category Devices Go back to the alphabetical Function listing. 1500. di) ' Begin the first and only page to print.html http://216. ' Delete retval = ' Delete retval = the pen created for drawing.fwType = 0 ' no additional information ' Begin the print job.92/vbapi/ref/c/createdc.com Send Encrypted E-Mail This page is at http://www.com/ref/c/createdc.1500)-(2000.26. hPen) ' Draw an ellipse with bounding rectangle corners (1000. DeleteObject(hPen) the device context to the printer.168.

com | www. Windows NT: Requires Windows NT 3.vb-shop.part of the VB-World Network | www.html (1 of 2) [9/1/2002 5:11:37 PM] .0 or later. Visual Basic-Specific Issues None. lpSecurityAttributes http://216.26. the function returns 0 (use GetLastError to get the error code). If successful. if the operating system supports it.168.dll" Alias "CreateDirectoryA" (ByVal lpPathName As String.com .vbforums.1 or later.Windows API Guide: CreateDirectory Function vbapi.vbsquare. Return Value If an error occured. lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long Platforms q q q q q Windows 95: Supported.vbworld.com | www.com | www.92/vbapi/ref/c/createdirectory. It also allows you to specify the security attributes of the newly created directory. the function returns a non-zero value. Windows 98: Supported. Parameters lpPathName The name of the new directory to create.com | www. Windows CE: Requires Windows CE 1.vbapi. Windows 2000: Supported.com | CreateDirectory Function Declare Function CreateDirectory Lib "kernel32. Description & Usage CreateDirectory creates a new directory on a disk.

E-mail: vbapi@vbapi.nLength = Len(secattr) ' size of the structure secattr. retval = CreateDirectory("C:\Dummy\NewDir". Last Modified: March 19.lpSecurityDescriptor = 0 ' default (normal) level of security secattr.com/ref/c/createdirectory.92/vbapi/ref/c/createdirectory. 2000 This page is copyright © 1999 Paul Kuliniewicz. 2000: The security attributes to assign to the newly created directory.com Send Encrypted E-Mail This page is at http://www.26.vbapi. 2000 Go back to the Windows API Guide home page. Windows 95.html (2 of 2) [9/1/2002 5:11:37 PM] . Go back to the Reference section index. Example ' This code is licensed according to the terms and conditions listed here. Dim secattr As SECURITY_ATTRIBUTES ' security attributes structure Dim retval As Long ' return value ' Set the desired security attributes secattr. Copyright Information Revised October 29. 98.Windows API Guide: CreateDirectory Function Windows NT. secattr) See Also CreateDirectoryEx. ' Create the new directory C:\Dummy\NewDir and ' give it default security attributes.168.bInheritHandle = 1 ' this is the default setting ' Create the directory. RemoveDirectory Category Files Go back to the alphabetical Function listing.html http://216. CE: This parameter is ignored.

com | www. Description & Usage CreateDirectoryEx creates a new directory on a disk. Windows NT: Requires Windows NT 3. Windows CE: Not Supported.dll" Alias "CreateDirectoryExA" (ByVal lpTemplateDirectory As String.html (1 of 2) [9/1/2002 5:11:44 PM] .com .26. the function returns 0 (use GetLastError to get the error code).168.com | www. Windows 98: Supported. Parameters lpTemplateDirectory The name of the directory to use as an attribute template for creating the new directory.vbshop. Visual Basic-Specific Issues None.92/vbapi/ref/c/createdirectoryex. lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long Platforms q q q q q Windows 95: Supported. The newly created directory will inherit most of its attributes (except security) from a template directory specified by the function. if the operating system supports it. ByVal lpNewDirectory As String. the new directory will have the same file attributes as the template directory.vbapi. Return Value If an error occured. the function returns a non-zero value.Windows API Guide: CreateDirectoryEx Function vbapi.vbforums. Windows 2000: Supported. lpNewDirectory The name of the new directory to create. If successful.vbworld.com | CreateDirectoryEx Function Declare Function CreateDirectoryEx Lib "kernel32. http://216.com | www. For example. It also allows you to specify the security attributes of the newly created directory.part of the VB-World Network | www.com | www.vbsquare.5 or later.

Dim secattr As SECURITY_ATTRIBUTES ' security attributes structure Dim retval As Long ' return value ' Set the desired security attributes secattr. secattr) See Also CreateDirectory.168. ' Create the new directory C:\Dummy\NewDir and ' give it default security attributes. it will have the Hidden and System attributes. Copyright Information Revised October 29. Go back to the Reference section index. Last Modified: March 19.Windows API Guide: CreateDirectoryEx Function lpSecurityAttributes Windows NT.nLength = Len(secattr) ' size of the structure secattr. retval = CreateDirectoryEx("C:\Recycled". CE: This parameter is ignored. Windows 95. 2000 This page is copyright © 1999 Paul Kuliniewicz. using C:\Recycled as the template.lpSecurityDescriptor = 0 ' default (normal) level of security secattr. Example ' This code is licensed according to the terms and conditions listed here.com/ref/c/createdirectory.although this won't be another ' recycle bin. "C:\Dummy\NewDir".html (2 of 2) [9/1/2002 5:11:44 PM] .vbapi.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.bInheritHandle = 1 ' this is the default setting ' Create the directory.26.html http://216. 98.92/vbapi/ref/c/createdirectoryex. 2000 Go back to the Windows API Guide home page. RemoveDirectory Category Files Go back to the alphabetical Function listing. It will inherit its properties from the ' directory C:\Recycled (the "Recycle Bin") -. 2000: The security attributes to assign to the newly created directory.

30. The bounding rectangle is the smallest possible rectangle which can fit around the ellipse. retval = InvertRgn(Form1.com | CreateEllipticRgn Function Declare Function CreateEllipticRgn Lib "gdi32.com . X1 The x-coordinate of the upper-left corner of the ellipse's bounding rectangle.html (1 of 2) [9/1/2002 5:11:53 PM] .vbforums. The has a bounding rectangle of (20. Win 95/98. Y2 The y-coordinate of the lower-right corner of the ellipse's bounding rectangle.110) ' Invert that region in window Form1.150.92/vbapi/ref/c/createellipticrgn. or 0 if an error occured. The ellipse which forms the region is specified by the bounding rectangle defined by the coordinates passed to the function. The function returns a handle to the newly created region if successful. ByVal Y1 As Long.com | www.hDC. Example: ' Invert the pixels ' elliptical region Dim hrgn As Long ' Dim retval As Long within an elliptical region on window Form1.168.vbsquare. X2 The x-coordinate of the lower-right corner of the ellipse's bounding rectangle.Windows API Guide: CreateEllipticRgn Function vbapi.110) ' bounding rectangle (20.com | www. Y1 The y-coordinate of the upper-left corner of the ellipse's bounding rectangle.30)-(150. ByVal Y2 As Long) As Long Platforms: Win 32s.26. Win NT CreateEllipticRgn creates an elliptically-shaped region.vbworld. hrgn) ' Delete the region to free up resources.com | www.vbshop.part of the VB-World Network | www. ByVal X2 As Long.dll" (ByVal X1 As Long.vbapi. hrgn = CreateEllipticRgn(20. handle to the region to invert ' return value ' Create the elliptical region to invert and get a handle to it.110). retval = DeleteObject(hrgn) See Also: CreateEllipticRgnIndirect Category: Regions Go back to the alphabetical Function listing. http://216.30)-(150.com | www. Go back to the Reference section index.

Go back to the Windows API Guide home page.com/ref/c/createellipticrgn.html http://216.vbapi. Copyright Information.92/vbapi/ref/c/createellipticrgn.168.26.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: CreateEllipticRgn Function This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:11:53 PM] .

Windows API Guide: CreateEllipticRgnIndirect Function vbapi.110) Dim hrgn As Long ' handle to the elliptical region Dim bounding As RECT ' bounding rectangle Dim retval As Long ' return value The ' Load the coordinates of the bounding rectangle into the structure. retval = DeleteObject(hrgn) See Also: CreateEllipticRgn Category: Regions Go back to the alphabetical Function listing. The ellipse which forms the region is specified by the bounding rectangle defined by the rectangle structure passed to the function.110) ' Create the elliptical region from this bounding rectangle.com | www. The function returns a handle to the newly created region if successful.hDC.vb-shop.26. http://216.html (1 of 2) [9/1/2002 5:12:05 PM] .30)-(150.vbforums. or 0 if an error occured.com | www. retval = InvertRgn(Form1. Win 95/98. 110) ' bounding = (20. The bounding rectangle is the smallest possible rectangle which can fit around the ellipse. ' elliptical region has a bounding rectangle of (20. 30. 150.com | www. hrgn = CreateEllipticRgnIndirect(bounding) ' Invert the pixels on Form1 within the region. lpRect The bounding rectangle of the ellipse which forms the region.vbsquare.com | CreateEllipticRgnIndirect Function Declare Function CreateEllipticRgnIndirect Lib "gdi32. Example: ' Invert the pixels within an elliptical region within window Form1.30)-(150.dll" (lpRect As RECT) As Long Platforms: Win 32s.com . Win NT CreateEllipticRgn creates an elliptically-shaped region. Go back to the Reference section index.92/vbapi/ref/c/createellipticrgnindirect.part of the VB-World Network | www.vbapi. 20. retval = SetRect(bounding. hrgn) ' Delete the region to free up resources.com | www.vbworld.168.

html http://216. E-mail: vbapi@vbapi. Copyright Information.Windows API Guide: CreateEllipticRgnIndirect Function This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.vbapi.92/vbapi/ref/c/createellipticrgnindirect.26.com/ref/c/createellipticrgnindirect.168.html (2 of 2) [9/1/2002 5:12:05 PM] .

http://216. Windows 98: Supported. Windows 2000: Supported. the function returns -1 (use GetLastError to get the error code). 2000 only).vbsquare. ByVal dwFlagsAndAttributes As Long. Return Value If an error occured. files are the most common thing opened by the function. Description & Usage CreateFile creates or opens a console. lpSecurityAttributes As Any. and pipes. ByVal dwShareMode As Long. directory (can only open).com | CreateFile Function Declare Function CreateFile Lib "kernel32. ByVal dwCreationDisposition As Long. Visual Basic-Specific Issues When passing 0 as the lpSecurityAttributes parameter. mailslots. If successful.com | www.com .168.vbapi.dll" Alias "CreateFileA" (ByVal lpFileName As String.vbforums. Parameters lpFileName The name of the file or other allowed object to create or open. disk devices (Windows NT. as the access level allows.vbshop.26. Windows NT: Requires Windows NT 3.com | www. it must call CloseHandle to close the open object.com | www.1 or later. the expression ByVal CLng(0) must be used to pass the zero correctly.Windows API Guide: CreateFile Function vbapi. ByVal hTemplateFile As Long) As Long Platforms q q q q q Windows 95: Supported. Windows CE: Requires Windows CE 1.vbworld.92/vbapi/ref/c/createfile. files. dwDesiredAccess A combination of the following flags (if any) specifying the amounts of read/write access to the file or other object: GENERIC_READ Allow the program to read data from the file or other object. Obviously. the function returns a handle to the opened or created file or other object.com | www. communications resource. After your program is finished using the handle generated by the function. The object opened can then be read from or written to. See the example for a demonstration. ByVal dwDesiredAccess As Long.0 or later.part of the VB-World Network | www.html (1 of 4) [9/1/2002 5:12:18 PM] .

2000: A SECURITY_ATTRIBUTES structure specifying the security attributes to give the created or opened file or other object. OPEN_ALWAYS Open an existing file or other object. If used. the amounts of data accessed must be a whole number multiple of the disk's sector size. FILE_ATTRIBUTE_SYSTEM A system file. Windows 95. TRUNCATE_EXISTING Open an existing file or other object and delete its contents. the following things must be done: access to the file must begin at whole number multiples of the disk's sector size. and buffer addresses for I/O operations must be aligned on whole number multiples of the disk's sector size. If used.. dwCreationDisposition Exactly one of the following flags specifying how and when to create or open the file or other object depending if it already does or does not exist: CREATE_ALWAYS Create a new file or other object. CE: This parameter must be 0. OPEN_EXISTING Open an existing file or other object.168. FILE_ATTRIBUTE_ARCHIVE An archive file (which most files are). FILE_FLAG_NO_BUFFERING Do not use any buffers or caches. used exclusively by the operating system. CREATE_NEW Create a new file or other object. If the file or other object does not exist. it will be created. The function fails if the file or other object does not exist. not normally visible to the user.92/vbapi/ref/c/createfile. (Windows 95.Windows API Guide: CreateFile Function GENERIC_WRITE Allow the program to write data to the file or other object. FILE_FLAG_DELETE_ON_CLOSE Delete the file once it is closed. The function fails if the file or other object already exists.html (2 of 4) [9/1/2002 5:12:18 PM] . FILE_FLAG_OVERLAPPED Allow asynchronous I/O. FILE_ATTRIBUTE_NORMAL An attribute-less file (cannot be combined with other attributes).26. The function fails if the file or other object does not exist. although other overlapped objects are.e.) FILE_FLAG_POSIX_SEMANTICS http://216. Overwrite the file or other object (i. i.e.. 98. One flag specifying the file attributes must be included. 98. delete the old one first) if it already exists. functions that read and write to the file must specify the OVERLAPPED structure identifying the file pointer. allow the file to be read from and written to simultaneously. dwFlagsAndAttributes The combination of the following flags specifying both the file attributes of a newly created file and other options for creating or opening the file. FILE_ATTRIBUTE_HIDDEN A hidden file. dwShareMode A combination of the following flags (if any) specifying the amounts of read/write access to grant other programs attempting to access the file or other object while your program still has it open: FILE_SHARE_READ Allow other programs to read data from the file or other object. lpSecurityAppributes Windows NT. FILE_SHARE_WRITE Allow other programs to write data to the file or other object. FILE_ATTRIBUTE_READONLY A read-only file. CE: Overlapped files are not supported.

168. ByVal CLng(0). ' Display the date on which the file C:\MyApp\test. Dim hFile As Long ' handle to the opened file Dim ctime As FILETIME ' receives time of creation Dim atime As FILETIME ' receives time of last access Dim mtime As FILETIME ' receives time of last modification Dim thetime As SYSTEMTIME ' used to manipulate the time Dim retval As Long ' return value ' First. Constant Definitions Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const GENERIC_READ = &H80000000 GENERIC_WRITE = &H40000000 FILE_SHARE_READ = &H1 FILE_SHARE_WRITE = &H2 CREATE_ALWAYS = 2 CREATE_NEW = 1 OPEN_ALWAYS = 4 OPEN_EXISTING = 3 TRUNCATE_EXISTING = 5 FILE_ATTRIBUTE_ARCHIVE = &H20 FILE_ATTRIBUTE_HIDDEN = &H2 FILE_ATTRIBUTE_NORMAL = &H80 FILE_ATTRIBUTE_READONLY = &H1 FILE_ATTRIBUTE_SYSTEM = &H4 FILE_FLAG_DELETE_ON_CLOSE = &H4000000 FILE_FLAG_NO_BUFFERING = &H20000000 FILE_FLAG_OVERLAPPED = &H40000000 FILE_FLAG_POSIX_SEMANTICS = &H1000000 FILE_FLAG_RANDOM_ACCESS = &H10000000 FILE_FLAG_SEQUENTIAL_SCAN = &H8000000 FILE_FLAG_WRITE_THROUGH = &H80000000 Example ' This code is licensed according to the terms and conditions listed here. FILE_FLAG_SEQUENTIAL_SCAN Optimize the file cache for sequential access (starting at the beginning and continuing to the end of the file). GENERIC_READ.txt". or 0 to not copy the attributes of any open file.html (3 of 4) [9/1/2002 5:12:18 PM] .26. open the file C:\MyApp\test. FILE_FLAG_WRITE_THROUGH Bypass any disk cache and instead read and write directly to the file.Windows API Guide: CreateFile Function Allow file names to be case-sensitive.txt was ' created.txt for read-level access. hFile = CreateFile("C:\MyApp\test. FILE_FLAG_RANDOM_ACCESS Optimize the file cache for random access (skipping around to various parts of the file). Note how the time zone conversion is necessary.92/vbapi/ref/c/createfile. hTemplateFile A handle to an open file to copy the attributes of. http://216. Note the ' expression necessary to pass 0 as lpSecurityAttributes. FILE_SHARE_READ.

Debug.Print "Could not open the file successfully -.26.com Send Encrypted E-Mail This page is at http://www. retval = CloseHandle(hFile) Category Files Go back to the alphabetical Function listing. retval = FileTimeToSystemTime(ctime. 1999 This page is copyright © 1999 Paul Kuliniewicz.html (4 of 4) [9/1/2002 5:12:18 PM] . 0) If hFile = -1 Then Debug. Last Modified: September 30.com/ref/c/createfile.vbapi.html http://216. thetime) ' Display the date of creation of the file to the user. "-".Windows API Guide: CreateFile Function OPEN_EXISTING. retval = FileTimeToLocalFileTime(ctime. ctime. "-". get the creation. Go back to the Reference section index. mtime) ' Convert the creation time to the local time zone.wMonth. ctime) ' Convert the FILETIME format to the SYSTEMTIME format.aborting. thetime. Copyright Information Revised October 29.92/vbapi/ref/c/createfile. FILE_ATTRIBUTE_ARCHIVE. 2000 Go back to the Windows API Guide home page. retval = GetFileTime(hFile. atime.wYear ' Close the file to free up resources. E-mail: vbapi@vbapi." End ' terminate the program End If ' Next.wDay.168.Print "The file was created on ". and last-modification times. thetime. thetime. last-access.

Visual Basic-Specific Issues None.26. ByVal nWidth As Long. the function returns 0 (Windows NT. Windows NT: Requires Windows NT 3. ByVal fdwStrikeOut As Long. in logical units (also known as the em height). If successful. Windows 98: Supported.html (1 of 7) [9/1/2002 5:12:25 PM] . If positive. 2000: use GetLastError to get the error code).1 or later.com | www.92/vbapi/ref/c/createfont. ByVal fdwItalic As Long. the font mapper converts this value directly into device units and matches it with the cell height of the possible fonts. Parameters nHeight The height of the font's character cell.vbforums.vbapi.vbworld.vbshop. If 0. the font mapper uses a default character height. Windows 2000: Supported. http://216.com . ByVal fdwUnderline As Long. ByVal fdwQuality As Long. ByVal nEscapement As Long.com | www.com | www. Description & Usage CreateFont creates a font object. ByVal fnWeight As Long. it must be deleted by using DeleteObject.com | CreateFont Function Declare Function CreateFont Lib "gdi32. the function returns a handle to the font just created. the font mapper converts the absolute value into device units and matches it with the character height of the possible fonts. ByVal fdwPitchAndFamily As Long. The font created by the function is the one which most closely matches the attributes of the logical font information passed via the numerous parameters.Windows API Guide: CreateFont Function vbapi. After your program is finished using the font.dll" Alias "CreateFontA" (ByVal nHeight As Long.vbsquare. Return Value If an error occured. Windows CE: Not Supported.com | www. If negative. ByVal fdwOutputPrecision As Long.168. ByVal fdwClipPrecision As Long. ByVal lpszFace As String) As Long Platforms q q q q q Windows 95: Supported. ByVal nOrientation As Long.part of the VB-World Network | www. which allows a font with given attributes to be used to draw text on a device. ByVal fdwCharSet As Long.

ARABIC_CHARSET http://216. nEscapement The angle between the font's baseline and escapement vectors. FW_LIGHT Light weight.26. fdwUnderline A non-zero value if the font is underlined. 0 if not. FW_DEMIBOLD Same As FW_SEMIBOLD. 0 if not. FW_ULTRABOLD Same as FW_EXTRABOLD. If 0. FW_THIN Thin weight. FW_REGULAR Same as FW_NORMAL. 98: This must be equal to lfEscapement. fdwCharSet Exactly one of the following flags specifying the character set of the font: ANSI_CHARSET ANSI character set. in units of 1/10 degrees.html (2 of 7) [9/1/2002 5:12:25 PM] . FW_BLACK Same as FW_HEAVY.168. fdwStrikeOut A non-zero value if the font is striked out. FW_MEDIUM Medium weight. FW_BOLD Bold weight. FW_ULTRALIGHT Same as FW_EXTRALIGHT. FW_EXTRABOLD Extra-bold weight. nOrientation The angle between the font's baseline and the device's x-axis.Windows API Guide: CreateFont Function nWidth The average width of the font's characters. 0 if not. fnWeight One of the following flags specifying the boldness (weight) of the font: FW_DONTCARE Default weight. 98: This must be equal to lfOrientation. Windows 95. the font mapper tries to determine the best value.92/vbapi/ref/c/createfont. fdwItalic A non-zero value if the font is italicized. FW_SEMIBOLD Semi-bold weight. FW_NORMAL Normal weight. in units of 1/10 degrees. Windows 95. FW_HEAVY Heavy weight. FW_EXTRALIGHT Extra-light weight.

CHINESEBIG5_CHARSET Chinese Big 5 character set. 2000: Choose a TrueType or other outline-based font. OUT_RASTER_PRECIS Choose a raster font if there are multiple fonts in the system with the same name. JOHAB_CHARSET Windows 95. SYMBOL_CHARSET Symbol character set. OUT_DEVICE_PRECIS Choose a device font if there are multiple fonts in the system with the same name. OUT_DEFAULT_PRECIS The default font mapping behavior.168. outline-based. 98: Johab character set.92/vbapi/ref/c/createfont. 2000: TrueType. MAC_CHARSET Windows 95. 98: Vector font (used for enumeration only). EASTEUROPE_CHARSET Windows 95. GREEK_CHARSET Windows 95. TURKISH_CHARSET Windows 95. 98: Turkish character set. 98: Russian character set. or vector font (used for enumeration only). GB2312_CHARSET GB2312 character set. 2000: Hebrew character set. OUT_TT_ONLY_PRECIS http://216. BALTIC_CHARSET Windows 95. SHIFTJIS_CHARSET ShiftJis character set.Windows API Guide: CreateFont Function Windows NT. This value is used by the font mapper to produce the logical font. THAI_CHARSET Windows NT. OEM_CHARSET Original equipment manufacturer (OEM) character set. 98: Baltic character set. OUT_STROKE_PRECIS Windows 95. 98: Mac character set. 2000: Thai character set. HEBREW_CHARSET Windows NT. OUT_STRING_PRECIS Raster font (used for enumeration only). DEFAULT_CHARSET Default character set. fdwOutPrecision Exactly one of the following flags specifying the desired precision (closeness of the match) between the logical font ideally described by the structure and the actual logical font. RUSSIAN_CHARSET Windows 95. 2000: Arabic character set. 98: Eastern European character set.html (3 of 7) [9/1/2002 5:12:25 PM] .26. OUT_OUTLINE_PRECIS Windows NT. 98: Greek character set. Windows NT. HANGEUL_CHARSET HANDEUL character set.

VARIABLE_PITCH Variable pitch. fdwQuality Exactly one of the following flags specifying the output quality of the logical font as compared to the ideal font: ANTIALIASED_QUALITY Windows 95. DRAFT_QUALITY The appearance of the font is less important then in PROOF_QUALITY. 98.0 or later.html (4 of 7) [9/1/2002 5:12:25 PM] . sans serif font). FF_SCRIPT Script font face which imitates script handwriting. CLIP_LH_ANGLES The direction of any rotations is determined by the coordinate system (or else all rotations are counterclockwise). OUT_TT_PRECIS Choose a TrueType font if there are multiple fonts in the system with the same name. CLIP_EMBEDDED This flag must be set for an embedded read-only font. 2000: The font is never antialiased. FF_ROMAN Roman font face (proportional-width. or TrueType font (used for enumeration only). FF_DONTCARE Do not care about the font face. 98. serif font). decorative font face. Constant Definitions http://216.92/vbapi/ref/c/createfont. 2000: The font is always antialiased if possible.26. NONANTIALIASED_QUALITY Windows 95. FIXED_PITCH Fixed pitch.Windows API Guide: CreateFont Function Choose only a TrueType font.168. FF_MODERN Modern font face (monospaced. NT 4. vector. PROOF_QUALITY The quality of the appearance of the font is more important than exactly matching the specified font attributes. fdwClipPrecision Exactly one of the following flags specifying the clipping precision to use when the font's characters must be clipped: CLIP_DEFAULT_PRECIS The default clipping behavior. NT 4. DEFAULT_QUALITY The default quality: the appearance of the font does not matter. FF_DECORATIVE Showy.0 or later. FF_SWISS Swiss font face (proportional-width. fdwPitchAndFamily A bitwise OR combination of exactly one *_PITCH flag specifying the pitch of the font and exactly one FF_* flag specifying the font face family of the font: DEFAULT_PITCH The default pitch. lpszFace The name of the font face to use. sans serif font). CLIP_STROKE_PRECIS Raster.

Windows API Guide: CreateFont Function Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const FW_DONTCARE = 0 FW_THIN = 100 FW_EXTRALIGHT = 200 FW_ULTRALIGHT = 200 FW_LIGHT = 300 FW_NORMAL = 400 FW_REGULAR = 400 FW_MEDIUM = 500 FW_SEMIBOLD = 600 FW_DEMIBOLD = 600 FW_BOLD = 700 FW_EXTRABOLD = 800 FW_ULTRABOLD = 800 FW_HEAVY = 900 FW_BLACK = 900 ANSI_CHARSET = 0 ARABIC_CHARSET = 178 BALTIC_CHARSET = 186 CHINESEBIG5_CHARSET = 136 DEFAULT_CHARSET = 1 EASTEUROPE_CHARSET = 238 GB2312_CHARSET = 134 GREEK_CHARSET = 161 HANGEUL_CHARSET = 129 HEBREW_CHARSET = 177 JOHAB_CHARSET = 130 MAC_CHARSET = 77 OEM_CHARSET = 255 RUSSIAN_CHARSET = 204 SHIFTJIS_CHARSET = 128 SYMBOL_CHARSET = 2 THAI_CHARSET = 222 TURKISH_CHARSET = 162 OUT_DEFAULT_PRECIS = 0 OUT_DEVICE_PRECIS = 5 OUT_OUTLINE_PRECIS = 8 OUT_RASTER_PRECIS = 6 OUT_STRING_PRECIS = 1 OUT_STROKE_PRECIS = 3 OUT_TT_ONLY_PRECIS = 7 OUT_TT_PRECIS = 4 CLIP_DEFAULT_PRECIS = 0 CLIP_EMBEDDED = 128 CLIP_LH_ANGLES = 16 CLIP_STROKE_PRECIS = 2 ANTIALIASED_QUALITY = 4 DEFAULT_QUALITY = 0 DRAFT_QUALITY = 1 NONANTIALIASED_QUALITY = 3 PROOF_QUALITY = 2 http://216.html (5 of 7) [9/1/2002 5:12:25 PM] .168.92/vbapi/ref/c/createfont.26.

10. "ABCDEFGHIJKLMNOPQRSTUVWXYZ". saving the previous selection. FW_BOLD. 26) ' Select retval = ' Delete retval = the previous font back. Only apply boldface ' formatting to the font -. DEFAULT_PITCH Or FF_DECORATIVE. hOldFont = SelectObject(Form1.Windows API Guide: CreateFont Function Const Const Const Const Const Const Const Const DEFAULT_PITCH = 0 FIXED_PITCH = 1 VARIABLE_PITCH = 2 FF_DECORATIVE = 80 FF_DONTCARE = 0 FF_ROMAN = 16 FF_SCRIPT = 64 FF_SWISS = 32 Example ' This code is licensed according to the terms and conditions listed here. SelectObject(Form1. ' Draw the alphabet in the upper-left corner of window Form1 using ' the goofy Symbol font.hDC. Last Modified: October 13. 0.26. 1999 http://216. OUT_DEFAULT_PRECIS.92/vbapi/ref/c/createfont. 0. Go back to the Reference section index. retval = TextOut(Form1. hOldFont) the font we created to free up resources. DEFAULT_QUALITY. Dim hFont As Long ' handle to the Symbol font which is created Dim hOldFont As Long ' handle to the font previously selected by Form1 Dim retval As Long ' return value ' Create a font object using the Symbol font.hDC.hDC. SYMBOL_CHARSET. 10. hFont = CreateFont(0. 0. 0. hFont) ' Draw the alphabet near the upper-left corner.html (6 of 7) [9/1/2002 5:12:25 PM] . 0. 0. CLIP_DEFAULT_PRECIS. "Symbol") ' Select that font for use with Form1.use defaults for most other settings.168. DeleteObject(hFont) See Also CreateFontIndirect Category Fonts & Text Go back to the alphabetical Function listing.

Windows API Guide: CreateFont Function This page is copyright © 1999 Paul Kuliniewicz.html (7 of 7) [9/1/2002 5:12:25 PM] .com Send Encrypted E-Mail This page is at http://www.168.com/ref/c/createfont. 2000 Go back to the Windows API Guide home page.vbapi.92/vbapi/ref/c/createfont.26.html http://216. E-mail: vbapi@vbapi. Copyright Information Revised October 29.

26. Description & Usage CreateFontIndirect creates a font object.com . the function returns 0 (Windows NT. which allows a font with given attributes to be used to draw text on a device.com | www.vbsquare.com | www.vb-shop.html (1 of 3) [9/1/2002 5:12:36 PM] .Windows API Guide: CreateFontIndirect Function vbapi.0 or later.92/vbapi/ref/c/createfontindirect. Windows 2000: Supported.com | CreateFontIndirect Function Declare Function CreateFontIndirect Lib "gdi32. Visual Basic-Specific Issues None. it must be deleted by using DeleteObject.vbforums. Return Value If an error occured. After your program is finished using the font.com | www. the function returns a handle to the font just created. Parameters lplf Information describing the desired attributes to give to the newly created font.168. Example http://216. Windows 98: Supported. 2000: use GetLastError to get the error code). The font created by the function is the one which most closely matches the attributes of the logical font information passed via the structure. If successful.dll" Alias "CreateFontIndirectA" (lplf As LOGFONT) As Long Platforms q q q q q Windows 95: Supported.com | www.vbapi. Windows NT: Requires Windows NT 3.part of the VB-World Network | www. Windows CE: Requires Windows CE 1.1 or later.vbworld.

retval = DeleteObject(hFont) See Also CreateFont Category Fonts & Text Go back to the alphabetical Function listing. 10.html (2 of 3) [9/1/2002 5:12:36 PM] . retval = SystemParametersInfo(SPI_GETICONTITLELOGFONT. retval = SelectObject(Form1. Go back to the Reference section index.hDC.hDC. 0) ' Create a font matching the logical font description. noting the previous font.92/vbapi/ref/c/createfontindirect.26. Last Modified: October 11. hOldFont = SelectObject(Form1. Dim lf As LOGFONT ' receives information about the font Windows uses Dim hFont As Long ' handle to the font that is created Dim hOldFont As Long ' handle to the font which Form1 previously had selected Dim retval As Long ' return value ' Get the attributes of the logical font used by Windows to ' draw the title text of icons. 26) ' Restore the previously selected font for use in Form1.hDC. retval = TextOut(Form1. 2000 Go back to the Windows API Guide home page. 1999 This page is copyright © 1999 Paul Kuliniewicz. lf. hOldFont) ' Delete the created font to free resources. ' Use the font used by Windows to draw the title text of ' icons to write the alphabet on window Form1. E-mail: vbapi@vbapi. hFont) ' Write the alphabet near the upper-left corner of Form1.Windows API Guide: CreateFontIndirect Function ' This code is licensed according to the terms and conditions listed here.com Send Encrypted E-Mail http://216. Len(lf). "ABCDEFGHIJKLMNOPQRSTUVWXYZ". Copyright Information Revised October 29. hFont = CreateFontIndirect(lf) ' Select that font for use in Form1.168. 10.

vbapi.html http://216.92/vbapi/ref/c/createfontindirect.com/ref/c/createfontindirect.26.168.html (3 of 3) [9/1/2002 5:12:36 PM] .Windows API Guide: CreateFontIndirect Function This page is at http://www.

RGB(255.html (1 of 2) [9/1/2002 5:12:43 PM] .vbapi.vbworld.part of the VB-World Network | www.vbshop.com | www. or 0 if an error occured.com | CreateHatchBrush Function Declare Function CreateHatchBrush Lib "gdi32. HS_DIAGCROSS = 5 Cross pattern of perpendicular diagonal lines. HS_HORIZONTAL = 0 Horizontal lines. When used to fill an area or shape. HS_FDIAGONAL = 2 Diagonal lines from the upper-left to the bottom-right. 0)) ' create a hatched yellow brush ' Save Form1's default brush so we can restore it after the program is finished holdbrush = SelectObject(Form1. HS_CROSS = 4 Cross pattern of horizontal and vertical lines.vbsquare. this brush produces a pattern of lines (a "hatch pattern") in a single color using an 8x8 unit cell. Win NT CreateHatchBrush creates a hatched brush object. After the program finishes using the hatched brush.com | www.hDC. Win 95/98. it should use DeleteObject to delete the brush and free system resources.com | www.com | www. nIndex Exactly one of the following flags specifying which hatch pattern to use to make the brush: HS_BDIAGONAL = 3 Diagonal lines from the bottom-left to the upper-right.vbforums.168.92/vbapi/ref/c/createhatchbrush.100) ' on window Form1. Use a yellow brush with a diagonal cross pattern to fill the rectangle. Example: ' Draw a rectangle with corners (10. Dim hbrush As Long ' receives handle to the hatched yellow brush Dim holdbrush As Long ' receives handle to Form1's default brush Dim retval As Long ' return value hbrush = CreateHatchBrush(HS_DIAGCROSS. crColor The RGB value of the color to give the hatched brush. Visual Basic users can use the RGB() function to generate this value. ByVal crColor As Long) As Long Platforms: Win 32s. The function returns a handle to the newly created hatched brush if successful.dll" (ByVal nIndex As Long.26.com .20) and (175. hbrush) ' select the brush ' Draw the rectangle filled using the hatched yellow brush http://216.Windows API Guide: CreateHatchBrush Function vbapi. 255. HS_VERTICAL = 1 Vertical lines.

com Send Encrypted E-Mail This page is at http://www.vbapi. E-mail: vbapi@vbapi.92/vbapi/ref/c/createhatchbrush. Go back to the Windows API Guide home page. Copyright Information.26.hDC. Go back to the Reference section index. holdbrush) ' select old brush retval = DeleteObject(hbrush) ' destroy the hatched yellow brush See Also: CreateSolidBrush Category: Brushes Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz.168.com/ref/c/createhatchbrush. 20. 175.html http://216. 100) ' Restore Form1's previous brush before destroying the created one retval = SelectObject(Form1.Windows API Guide: CreateHatchBrush Function retval = Rectangle(Form1.html (2 of 2) [9/1/2002 5:12:43 PM] .hDC. 10.

Windows API Guide: CreatePen Function vbapi. PS_DASH http://216.1 or later.vbsquare. Windows NT: Requires Windows NT 3. Windows 2000: Supported. Windows CE: Requires Windows CE 2.com | www.vbworld.vbforums.part of the VB-World Network | www.com .com | CreatePen Function Declare Function CreatePen Lib "gdi32. The shape of the pen created by the function is always a square having a side length equal to nWidth. Parameters fnPenStyle One of the following flags specifying the style of the pen to create: PS_SOLID The pen is solid. 2000: use GetLastError to get the error code). After your program is finished using the pen.com | www. ByVal crColor As Long) As Long Platforms q q q q q Windows 95: Supported.vbapi. ByVal nWidth As Long.com | www.com | www. the function returns 0 (Windows NT. Visual Basic-Specific Issues None. Description & Usage CreatePen creates a pen object. If successful. Return Value If an error occured.168. Windows 98: Supported.26.92/vbapi/ref/c/createpen. it must be deleted via the DeleteObject function.html (1 of 3) [9/1/2002 5:12:48 PM] . the function returns a handle to the newly created pen.0 or later.dll" (ByVal fnPenStyle As Long.vb-shop.

PS_DASHDOT The pen has alternating dashes and dots. RGB(0. 150. the pen is always exactly one pixel wide no matter what. ' Draw an ellipse on window Form1 using a one-pixel-wide ' square dashed green pen. 350. hOldPen = SelectObject(Form1. fits entirely within the bounding rectangle. 100. Constant Definitions Const Const Const Const Const Const Const PS_SOLID = 0 PS_DASH = 1 PS_DOT = 2 PS_DASHDOT = 3 PS_DASHDOTDOT = 4 PS_NULL = 5 PS_INSIDEFRAME = 6 Example ' This code is licensed according to the terms and conditions listed here. If this is 0.Windows API Guide: CreatePen Function The pen is dashed. the dimensions of the figure are shrunk so that the entire figure. PS_NULL The pen is invisible.300). 0)) ' Select the pen for use by window Form1. Whenever a drawing function draws a figure inside a bounding rectangle. crColor The RGB value of the color to give the pen. hPen) ' Draw an ellipse with bounding rectangle (100. nWidth must be less than or equal to one. 300) http://216. PS_DASHDOTDOT The pen has alternating dashes followed by two dots. 255. nWidth must be less than or equal to one. Dim hPen As Long ' handle to the pen created Dim hOldPen As Long ' handle to Form1's previously selected pen Dim retval As Long ' return value ' Create the square dashed green pen with a width of zero (always one pixel).26. including the width of the pen.hDC. nWidth must be less than or equal to one. nWidth must be less than or equal to one.168. nWidth The width of the pen. hPen = CreatePen(PS_DASH. PS_DOT The pen is dotted.html (2 of 3) [9/1/2002 5:12:48 PM] .92/vbapi/ref/c/createpen. PS_INSIDEFRAME The pen is solid.hDC.150)-(350. retval = Ellipse(Form1. 0.

com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.vbapi. Last Modified: October 16. SelectObject(Form1.html (3 of 3) [9/1/2002 5:12:48 PM] . hOldPen) the pen we created to free up resources.com/ref/c/createpen.html http://216. Go back to the Reference section index.92/vbapi/ref/c/createpen. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page.168.hDC.26. DeleteObject(hPen) See Also CreatePenIndirect Category Pens Go back to the alphabetical Function listing.Windows API Guide: CreatePen Function ' Select retval = ' Delete retval = the old pen for use by Form1. 1999 This page is copyright © 1999 Paul Kuliniewicz.

Return Value If an error occured.part of the VB-World Network | www. If successful. The pen created is the one which is described by the logical pen information in the structure passed to the function.Windows API Guide: CreatePenIndirect Function vbapi. 2000: use GetLastError to get the error code).com | www. Windows CE: Requires Windows CE 1.com | www.26. Description & Usage CreatePenIndirect creates a pen object.vbworld. Windows 2000: Supported.com | CreatePenIndirect Function Declare Function CreatePenIndirect Lib "gdi32. the function returns 0 (Windows NT. Parameters lpLogPen The description of the attributes to give to the newly created pen.0 or later.1 or later.dll" (lpLogPen As LOGPEN) As Long Platforms q q q q q Windows 95: Supported. Windows 98: Supported.com | www.vbapi. Example http://216.168. Visual Basic-Specific Issues None. the function returns a handle to the newly created pen. it should be deleted via the DeleteObject function.vbsquare.vb-shop.com . After your program is finished using the pen.vbforums.html (1 of 3) [9/1/2002 5:12:59 PM] .92/vbapi/ref/c/createpenindirect. Windows NT: Requires Windows NT 3.com | www.

150)-(350. 350. hOldPen = SelectObject(Form1. E-mail: vbapi@vbapi. lpinfo.y = 0 ' this member is ignored lpinfo.lopnStyle = PS_DASH ' dashed line lpinfo. 100. Go back to the Reference section index. Dim hPen As Long ' handle to the pen created Dim hOldPen As Long ' handle to Form1's previously selected pen Dim lpinfo As LOGPEN ' holds description of the pen Dim retval As Long ' return value ' Create the square dashed green pen with a width of zero (always one pixel). hPen) ' Draw an ellipse with bounding rectangle (100. hOldPen) the pen we created to free up resources. 300) ' Select retval = ' Delete retval = the old pen for use by Form1. 150.hDC. 0) ' green hPen = CreatePenIndirect(lpinfo) ' Select the pen for use by window Form1.hDC.lopnWidth. Last Modified: October 16.lopnColor = RGB(0. 255. retval = Ellipse(Form1. SelectObject(Form1.92/vbapi/ref/c/createpenindirect.html (2 of 3) [9/1/2002 5:12:59 PM] .hDC. ' Draw an ellipse on window Form1 using a one-pixel-wide ' square dashed green pen.com Send Encrypted E-Mail http://216. 1999 This page is copyright © 1999 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page.Windows API Guide: CreatePenIndirect Function ' This code is licensed according to the terms and conditions listed here. Copyright Information Revised October 29. DeleteObject(hPen) See Also CreatePen Category Pens Go back to the alphabetical Function listing.300).x = 0 ' minimum width lpinfo.26.lopnWidth.168.

168.92/vbapi/ref/c/createpenindirect.vbapi.com/ref/c/createpenindirect.Windows API Guide: CreatePenIndirect Function This page is at http://www.html (3 of 3) [9/1/2002 5:12:59 PM] .26.html http://216.

html (1 of 2) [9/1/2002 5:13:02 PM] . The polygon is defined by an array of points specifying its vertices. (250.vbapi. 3. Note that the polygon fill mode must explictly be specified.150) ' 2nd point: (250.com | www.dll" (lpPoint As POINT_TYPE.200) ' Create the polygonal region based on the array of vertices.y = 150 vertex(1).x = 250: vertex(1). retval = InvertRgn(Form1.com | CreatePolygonRgn Function Declare Function CreatePolygonRgn Lib "gdi32. regardless of any intra-polygonal boundaries and edges. Win 95/98. ByVal nCount As Long.hDC. Example: ' Invert the pixels within a triangular region on window Form1. instead of using the one set for whatever device the region is used with. 200). hrgn = CreatePolygonRgn(vertex(0). or 0 if an error occured. Dim vertex(0 To 2) As POINT_TYPE ' array of region's vertices Dim hrgn As Long ' handle to the triangular region Dim retval As Long ' return value ' Load the vertices of the triangular vertex(0).vbforums.y = 200 vertex(2). hrgn) ' Delete the region to free up resources. Specify each point in order only once. WINDING = 2 Any section inside the polygon is filled.150). 200).com | www. and (100.vbsquare. Win NT CreatePolygonRgn creates a polygonal region and provides a handle to it.com | www.x = 150: vertex(0).y = 200 region into the array.vbworld.vbshop. fill mode is irrelevant ' Invert the pixels within the triangular region on Form1.200) ' 3rd point: (100. Note how the points are loaded ' into the array of vertices. lpPoint An array holding the vertices of the polygonal region.com .92/vbapi/ref/c/createpolygonrgn.168.com | www. ALTERNATE) ' for a triangle. http://216.26. nCount The number of elements in the array passed as lpPoint. nPolyFillMode Exactly one of the following flags specifying the polygon fill mode to use for the polygonal region: ALTERNATE = 1 Alternates between filling and not filling contiguous sections whose boundaries are determined by the edge(s) of the polygon crossing through the polygon's interior. ' 1st point: (150. The triangular ' region has vertices (150. The function returns the handle to the newly created region if successful. ByVal nPolyFillMode As Long) As Long Platforms: Win 32s.part of the VB-World Network | www.x = 100: vertex(2).Windows API Guide: CreatePolygonRgn Function vbapi.

E-mail: vbapi@vbapi.html http://216.92/vbapi/ref/c/createpolygonrgn.com/ref/c/createpolygonrgn.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:13:02 PM] . This page is copyright © 2000 Paul Kuliniewicz.Windows API Guide: CreatePolygonRgn Function retval = DeleteObject(hrgn) See Also: CreatePolyPolygonRgn Category: Regions Go back to the alphabetical Function listing.26.vbapi. Go back to the Windows API Guide home page. Copyright Information. Go back to the Reference section index.168.

(50.com | www.92/vbapi/ref/c/createpolypolygonrgn. Specify each point for each polygon only once. or 0 if an error occured. nCount The number of elements in the array passed as lpPolyCounts. Example: ' Invert the points lying within a multi-polygonal region on window Form1. The individual polygons are not joined in any way. ByVal nCount As Long.Windows API Guide: CreatePolyPolygonRgn Function vbapi. Win 95/98.vbshop. The diamond has vertices (150.x = 25: vertex(0).vbforums.dll" (lpPoint As POINT_TYPE. Dim Dim Dim Dim vertex(0 To 6) As POINT_TYPE ' holds vertices of each polygon numvertices(0 To 1) As Long ' holds how many vertices belong to each polygon hrgn As Long ' handle to the multi-polygonal region retval As Long ' return value ' Load the vertices of the triangle into the vertex array.x = 50: vertex(1).y = 25 ' 1st point: (25. (150. lpPolyCounts As Long. ByVal nPolyFillMode As Long) As Long Platforms: Win 32s. instead of using the filling mode set for whatever device the region is used on. nPolyFillMode Exactly one of the following flags specifying the fill mode used for each polygon within the region: ALTERNATE = 1 Alternates between filling and not filling contiguous sections whose boundaries are determined by the edge(s) of the polygon crossing through the polygon's interior.com | www.part of the VB-World Network | www. The vertices of all the polygons are passed to the function in the array passed as lpPoint.50) http://216. Win NT CreatePolyPolygonRgn creates a region consisting of multiple polygons. The function returns the handle to the newly created region if successful. The ' region is made up of a triangle and a diamond.150).168.com | www.200). forming a region of multiple unconnected polygonal areas.vbapi. Note that the fill mode for the multi-polygonal region must be specified explicitly. WINDING = 2 Any section inside the polygon is filled.26. See the example for a demonstration of how to load multiple polygons into this array.250).html (1 of 2) [9/1/2002 5:13:08 PM] .y = 50 ' 2nd point: (50.vbworld. ' and (25.25) vertex(1).25).vbsquare.com | www. (200.com | CreatePolyPolygonRgn Function Declare Function CreatePolyPolygonRgn Lib "gdi32. The triangle has vertices (25.50). Another array specifies how many points within that array belong to each polygon. and (100. lpPoint An array holding the vertices of every polygon making up the new region.50).200). vertex(0). lpPolyCounts An array specifying how many vertices in the array passed as lpPoint belong to each polygon.com . regardless of any intra-polygonal boundaries and edges.

Copyright Information.y = 200 ' vertex(5).y = 150 ' vertex(4).x = 100: vertex(6). hrgn) ' Delete the region to free up resources.y = 250 ' vertex(6).200) triangle ' Create the multi-polygonal region and get a handle to it. E-mail: vbapi@vbapi. 2.hDC. hrgn = CreatePolyPolygonRgn(vertex(0).com Send Encrypted E-Mail This page is at http://www.Windows API Guide: CreatePolyPolygonRgn Function vertex(2).x = 150: vertex(3).92/vbapi/ref/c/createpolypolygonrgn. Go back to the Windows API Guide home page. numvertices(0).200) point: (150.html (2 of 2) [9/1/2002 5:13:08 PM] .html http://216.168.50) numvertices(0) = 3 ' three vertices for the triangle ' Load the vertices of the diamond into vertex(3).y = 200 ' numvertices(1) = 4 ' four vertices for the 1st 2nd 3rd 4th the vertex array.250) point: (100.com/ref/c/createpolypolygonrgn. point: (150. Go back to the Reference section index.x = 25: vertex(2).150) point: (200.vbapi. This page is copyright © 2000 Paul Kuliniewicz. retval = InvertRgn(Form1.x = 200: vertex(4).26. retval = DeleteObject(hrgn) See Also: CreatePolygonRgn Category: Regions Go back to the alphabetical Function listing.x = 150: vertex(5). ALTERNATE) ' Invert the pixels within this region on Form1.y = 50 ' 3rd point: (25.

Windows CE: Requires Windows CE 1. This menu can then be used for a submenu or a popup menu such as a context menu.vbworld.com | CreatePopupMenu Function Declare Function CreatePopupMenu Lib "user32.com | www. use InsertMenuItem to fill it with the desired menu items. Description & Usage CreatePopupMenu creates a new popup menu object.0 or later. Parameters None. Windows 98: Supported. Windows NT: Requires Windows NT 3. the function returns 0 (use GetLastError to get the error code).com .html (1 of 5) [9/1/2002 5:13:15 PM] .com | www.92/vbapi/ref/c/createpopupmenu.vbforums.com | www.168. the function returns a handle to the newly created popup menu. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.Windows API Guide: CreatePopupMenu Function vbapi.vbshop.com | www. Return Value If successful. If an error occured.26.dll" (ByVal hMenu As Long) As Long http://216.vbsquare. The new popup menu is initially empty.dll" () As Long Platforms q q q q q Windows 95: Supported.dll" () As Long Public Declare Function DestroyMenu Lib "user32.vbapi. it should destroy it as necessary using DestroyMenu.) Public Declare Function CreatePopupMenu Lib "user32. Windows 2000: Supported. Visual Basic-Specific Issues None.part of the VB-World Network | www. When your program no longer needs the popup menu.1 or later. Example ' This code is licensed according to the terms and conditions listed here.

dll" (lpRect As RECT) As Long http://216. ByVal _ fuFlags As Long. ByVal y As Long.dll" (ByVal hMenu As Long.html (2 of 5) [9/1/2002 5:13:15 PM] .92/vbapi/ref/c/createpopupmenu. ByVal uItem As Long. ByVal fByPosition As Long. lptpm As _ TPMPARAMS) As Long Public Const TPM_LEFTALIGN = &H0 Public Const TPM_TOPALIGN = &H0 Public Const TPM_NONOTIFY = &H80 Public Const TPM_RETURNCMD = &H100 Public Const TPM_LEFTBUTTON = &H0 Public Type POINT_TYPE x As Long y As Long End Type Public Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long Public Declare Function SetRectEmpty Lib "user32. ByVal x As Long. lpmii As _ MENUITEMINFO) As Long Public Type RECT left As Long top As Long right As Long bottom As Long End Type Public Type TPMPARAMS cbSize As Long rcExclude As RECT End Type Public Declare Function TrackPopupMenuEx Lib "user32.Windows API Guide: CreatePopupMenu Function Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_ID = &H2 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFT_STRING = &H0 Public Const MFS_DEFAULT = &H1000 Public Const MFS_ENABLED = &H0 Public Declare Function InsertMenuItem Lib "user32. ByVal hWnd As Long.168.dll" Alias "InsertMenuItemA" (ByVal _ hMenu As Long.26.

fType= MFT_STRING . The menu is created when ' needed and is destroyed after its use.168.fType = MFT_SEPARATOR . mii) ' Add the final item: "Exit"." With mii ' The size of this structure. divided by a separator bar.. 1. The ' menu only has two options. . 1.Windows API Guide: CreatePopupMenu Function ' When the user clicks button Command1.fType = MFT_STRING ' This item is currently enabled and is the default item.dwTypeData) http://216.. have a very simple popup menu appear. They are not actually part of the API.92/vbapi/ref/c/createpopupmenu." .fState = MFS_ENABLED Or MFS_DEFAULT ' Assign this item an item identifier. .26. they are ' used just to eliminate "magic numbers.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE ' The type of item: a string.dwTypeData = "E&xit" .wID = ID_EXIT . .dwTypeData) End With retval = InsertMenuItem(hPopupMenu. 0.. . mii) ' Add the second item: a separator bar." Private Const ID_ABOUT = 101 Private Const ID_SEPARATOR = 102 Private Const ID_EXIT = 103 Private Sub Dim Dim Dim Dim Dim Dim Command1_Click() hPopupMenu As Long mii As MENUITEMINFO tpm As TPMPARAMS curpos As POINT_TYPE menusel As Long retval As Long ' ' ' ' ' ' handle to the popup menu to display describes menu items to add identifies the exclusion rectangle holds the current mouse coordinates ID of what the user selected in the popup menu generic return value ' Create the popup menu that will be displayed. instead.html (3 of 5) [9/1/2002 5:13:15 PM] . hPopupMenu = CreatePopupMenu() ' Add the menu's first item: "About This Problem. .wID = ID_SEPARATOR End With retval = InsertMenuItem(hPopupMenu.cbSize = Len(mii) ' Which elements of the structure to use.dwTypeData = "&About This Example. With mii . . With mii .cch = Len(.wID = ID_ABOUT ' Display the following text for the item.. ' The following application-defined constants are used to name the menu item ' identifiers used by this example.cch = Len(.fState = MFS_ENABLED . 1.

hWnd. curpos. in order to have ' the popup menu appear at that point.Windows API Guide: CreatePopupMenu Function End With retval = InsertMenuItem(hPopupMenu. 2. have the function merely return the ID of the user's selection.92/vbapi/ref/c/createpopupmenu. With tpm ' Size of the structure. retval = GetCursorPos(curpos) ' Make the exclusion rectangle empty because there's no need for it here. Using the MessageBox API function isn't necessary. TPM_TOPALIGN Or TPM_LEFTALIGN Or TPM_NONOTIFY _ Or TPM_RETURNCMD Or TPM_LEFTBUTTON. vbOkOnly Or vbInformation. retval = SetRectEmpty(. .y. curpos. Instead of sending messages ' to window Form1.x. destroy the popup menu now. mii) ' Determine where the mouse cursor currently is. http://216. Form1. Unload Form1 End Select End Sub See Also DestroyMenu Category Menus Back to the Function list. 1.cbSize = Len(tpm) ' Make the exclusion rectangle empty.".rcExclude) End With ' Display the popup menu at the mouse cursor. menusel = TrackPopupMenuEx(hPopupMenu. retval = DestroyMenu(hPopupMenu) Select Case menusel Case ID_ABOUT ' Use the Visual Basic MsgBox function to display a short message in a dialog ' box.168.html (4 of 5) [9/1/2002 5:13:15 PM] . tpm) ' Before acting upon the user's selection. "Windows API Guide") Case ID_EXIT ' End this program by closing and unloading Form1.26. retval = MsgBox("This example demonstrates how to use the API to display " & _ "a pop-up menu.

E-mail: vbapi@vbapi.vbapi.92/vbapi/ref/c/createpopupmenu.html (5 of 5) [9/1/2002 5:13:15 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page.26.com/ref/c/createpopupmenu.Windows API Guide: CreatePopupMenu Function Back to the Reference section.html http://216. Last Modified: June 4.com Send Encrypted E-Mail This page is at http://www.168. Copyright Information Revised October 29.

html (1 of 2) [9/1/2002 5:13:23 PM] . X2 The x-coordinate of the lower-right corner of the rectangle.vb-shop.vbworld.30)-(150. The function returns a handle to the newly created region if successful. ' has corners (20.26. hrgn) ' Delete the region to free up resources. 30.vbsquare.com | CreateRectRgn Function Declare Function CreateRectRgn Lib "gdi32. ByVal Y2 As Long) As Long Platforms: Win 32s.com | www. Y2 The y-coordinate of the lower-right corner of the rectangle. ByVal Y1 As Long. The rectangle defining the region is specified by passing its upper-left and lower-right corners to the function.dll" (ByVal X1 As Long. 110) ' has corners (20.92/vbapi/ref/c/createrectrgn. hrgn = CreateRectRgn(20. or 0 if an error occured.part of the VB-World Network | www. Y1 The y-coordinate of the upper-left corner of the rectangle. Win NT CreateRectRgn creates a rectangularly-shaped region and provides a handle to it. retval = DeleteObject(hrgn) See Also: CreateRectRgnIndirect. CreateRoundRectRgn Category: Regions http://216. X1 The x-coordinate of the upper-left corner of the rectangle.Windows API Guide: CreateRectRgn Function vbapi.hDC.110). Win 95/98.com | www. Note that the bottom and right edges of the rectangle are not considered to be part of the region.168.vbforums. 150.com | www.110) ' Invert the pixels on Form1 within this region.vbapi.30)-(150.com .com | www. Example: ' Invert the pixels within a rectangular region on window Form1. Dim hrgn As Long ' handle to the rectangular region Dim retval As Long ' return value The region ' Create the rectangular region and get a handle to it. ByVal X2 As Long. retval = InvertRgn(Form1.

html http://216.168. Go back to the Windows API Guide home page.vbapi.92/vbapi/ref/c/createrectrgn.26.com/ref/c/createrectrgn. Go back to the Reference section index. E-mail: vbapi@vbapi.Windows API Guide: CreateRectRgn Function Go back to the alphabetical Function listing.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:13:23 PM] . Copyright Information. This page is copyright © 2000 Paul Kuliniewicz.

The rectangle defining the region is specified by the rectangle passed to the function. The function returns a handle to the newly created region if successful.30)-(150. Dim therect As RECT ' rectangle used to create region Dim hrgn As Long ' handle to the rectangular region Dim retval As Long ' return value ' Set the rectangle to use to create the region. Example: ' Invert the pixels within a rectangular region on window Form1. 30. 20.168. hrgn = CreateRectRgnIndirect(therect) ' Invert the pixels within this region on Form1.html (1 of 2) [9/1/2002 5:13:30 PM] . retval = DeleteObject(hrgn) See Also: CreateRectRgn. CreateRoundRectRgn Category: Regions Go back to the alphabetical Function listing. Win NT CreateRectRgnIndirect creates a rectangularly-shaped region and provides a handle to it.dll" (lpRect As RECT) As Long Platforms: Win 32s.26. Win 95/98.com | www.html vbapi. retval = InvertRgn(Form1. Go back to the Reference section index.http://216.com | www. http://216. or 0 if an error occured. lpRect The rectangle which defines the rectangular region to create.com | www.vbapi.26. hrgn) ' Delete the region to free up resources.com | www.com | CreateRectRgnIndirect Function Declare Function CreateRectRgnIndirect Lib "gdi32.part of the VB-World Network | www.vbsquare.110) ' Create the rectangular region based on this rectangle.hDC.vb-shop. retval = SetRect(therect.92/vbapi/ref/c/createrectrgnindirect.92/vbapi/ref/c/createrectrgnindirect. The region ' has corners (20.vbworld.30)-(150.com . Note that the bottom and right edges of the rectangle are not considered to be part of the region.vbforums.168. 150. 110) ' therect = (20.110).

26. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:13:30 PM] .http://216.html http://216.92/vbapi/ref/c/createrectrgnindirect.26.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/c/createrectrgnindirect.html This page is copyright © 2000 Paul Kuliniewicz.com/ref/c/createrectrgnindirect.vbapi. Copyright Information. Go back to the Windows API Guide home page.168.168.

100) ' Restore Form1's previous brush before destroying the created one retval = SelectObject(Form1. After it is finished using the brush. 0)) ' create a solid yellow brush ' Save Form1's default brush so we can restore it after the program is finished holdbrush = SelectObject(Form1.vbworld. crColor The RGB value of the color to give the solid brush. this brush creates a solid fill of a single color.com | www. hbrush) ' select the brush ' Draw the rectangle filled using the solid yellow brush retval = Rectangle(Form1.dll" (ByVal crColor As Long) As Long Platforms: Win 32s.168. Use a solid yellow brush to fill the rectangle.vbshop.com | CreateSolidBrush Function Declare Function CreateSolidBrush Lib "gdi32.com | www.vbapi. Win 95/98. Go back to the Reference section index.part of the VB-World Network | www. When used to fill an area or shape.hDC.com | www. Visual Basic users can use the intrinsic RGB() function to calculate this value.com | www.com . http://216. or 0 if an error occured.20) and (175.100) ' on window Form1.hDC. 255. the program should use DeleteObject to delete the brush and free up system resources.html (1 of 2) [9/1/2002 5:13:36 PM] . The function returns a handle to the newly created solid brush if successful. Example: ' Draw a rectangle with corners (10.26.vbforums.vbsquare.Windows API Guide: CreateSolidBrush Function vbapi.92/vbapi/ref/c/createsolidbrush. holdbrush) ' select old brush retval = DeleteObject(hbrush) ' destroy the solid yellow brush See Also: CreateHatchBrush Category: Brushes Go back to the alphabetical Function listing.hDC. Win NT CreateSolidBrush creates a solid brush object. 175. 20. Dim hbrush As Long ' receives handle to the solid yellow brush Dim holdbrush As Long ' receives handle to Form1's default brush Dim retval As Long ' return value hbrush = CreateSolidBrush(RGB(255. 10.

92/vbapi/ref/c/createsolidbrush. Go back to the Windows API Guide home page.html http://216. Copyright Information.26.vbapi.com/ref/c/createsolidbrush.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: CreateSolidBrush Function This page is copyright © 2000 Paul Kuliniewicz.html (2 of 2) [9/1/2002 5:13:36 PM] . E-mail: vbapi@vbapi.168.

processes. Windows 98: Supported.vbsquare. After your program no longer needs the snapshot. TH32CS_SNAPALL Include everything (heap list of a process. Depending on the flags specified. the functions returns -1 (use GetLastError to get the error code).26. If an error occured.part of the VB-World Network | www.vbforums.com . among other things.Windows API Guide: CreateToolhelp32Snapshot Function vbapi.com | CreateToolhelp32Snapshot Function Declare Function CreateToolhelp32Snapshot Lib "kernel32. Visual Basic-Specific Issues None. TH32CS_SNAPHEAPLIST Include the heap list of the process specified by th32ProcessID in the snapshot.vbapi. TH32CS_SNAPMODULE http://216. Windows 2000: Supported. Parameters dwFlags A combination of the following flags specifying which information to include in the snapshot: TH32CS_INHERIT Make the returned snapshot handle inheritable.com | www.dll" (ByVal dwFlags As Long. With this snapshot. Windows CE: Not Supported.html (1 of 4) [9/1/2002 5:13:42 PM] . the function returns a handle to the snapshot that was made.vbworld. Description & Usage CreateToolhelp32Snapshot creates a snapshot of what is running on the computer the moment the function is called.vbshop. Return Value If successful. and threads) in the snapshot. ByVal th32ProcessID As Long) As Long Platforms q q q q q Windows 95: Supported. modules.com | www. destroy it using CloseHandle.com | www. you can then examine what things were running when the snapshot was made.168.92/vbapi/ref/c/createtoolhelp32snapshot. Windows NT: Not Supported.com | www. this snapshot can include running processes and/or threads.

26.dll" (ByVal dwFlags As Long. Constant Definitions Const Const Const Const Const Const TH32CS_INHERIT = &H80000000 TH32CS_SNAPALL = &HF TH32CS_SNAPHEAPLIST = &H1 TH32CS_SNAPPROCESS = &H2 TH32CS_SNAPTHREAD = &H4 TH32CS_SNAPMODULE = &H8 Example Print a list of all the processes currently running on the computer when the user clicks button Command1. If neither of those two flags are specified.Windows API Guide: CreateToolhelp32Snapshot Function Include the module list of the process specified by th32ProcessID in the snapshot. To use this example.dll" (ByVal hSnapshot As Long. A value of 0 indicates the current process. TH32CS_SNAPTHREAD Include the thread list in the snapshot. The filename of the process and the number of threads owned by it is then displayed. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. th32ProcessID The identifier of the process for when TH32CS_SNAPHEAPLIST or TH32CS_SNAPMODULE is specified in dwFlags. TH32CS_SNAPPROCESS Include the process list in the snapshot. a snapshot of the running process list is taken.html (2 of 4) [9/1/2002 5:13:42 PM] . _ lppe As PROCESSENTRY32) As Long http://216. ' This code is licensed according to the terms and conditions listed here. _ lppe As PROCESSENTRY32) As Long Public Declare Function Process32Next Lib "kernel32.92/vbapi/ref/c/createtoolhelp32snapshot.dll" (ByVal hSnapshot As Long. place a command button named Command1 on a form window.168. and then each process in it is analyzed. To do this. this parameter is ignored. ByVal _ th32ProcessID As Long) As Long Public Const TH32CS_SNAPPROCESS = &H2 Public Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * 260 End Type Public Declare Function Process32First Lib "kernel32.) Public Declare Function CreateToolhelp32Snapshot Lib "kernel32.

92/vbapi/ref/c/createtoolhelp32snapshot. processInfo) Wend ' Destroy the snapshot. now that we no longer need it.26. make a snapshot of the current process list..szExeFile. remove the empty space) exeName = Left(processInfo. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS. 0) ' Get information about the first process in the list.Windows API Guide: CreateToolhelp32Snapshot Function Public Declare Function CloseHandle Lib "kernel32. processInfo) ' Make sure a handle was returned. *** Private Sub Dim Dim Dim Dim Dim Command1_Click() hSnapshot As Long ' handle to the snapshot of the process list processInfo As PROCESSENTRY32 ' information about a process in that list success As Long ' success of having gotten info on another process exeName As String ' filename of the process retval As Long ' generic return value ' First. if there is one. vbNullChar) . If hSnapshot = -1 Then Debug. processInfo. exeName Debug.cntThreads ' Get information about the next process. Debug. While success <> 0 ' Extract the filename of the process (i. Back to the Reference section.1) ' Display the process name and the number of threads it owns.Print "Unable to take snapshot of process list!" Exit Sub End If ' Loop for each process on the list.Number of threads:".dll" (ByVal hObject As Long) As Long ' *** Place the following code inside a form window.dwSize = Len(processInfo) success = Process32First(hSnapshot. http://216.Print " .dwSize = Len(processInfo) success = Process32Next(hSnapshot.168.e. InStr(processInfo.szExeFile.Print "Process: ".html (3 of 4) [9/1/2002 5:13:42 PM] . retval = CloseHandle(hSnapshot) End Sub Category Tool Help Back to the Function list. processInfo. processInfo.

Windows API Guide: CreateToolhelp32Snapshot Function Last Modified: September 24.html (4 of 4) [9/1/2002 5:13:42 PM] .html http://216.92/vbapi/ref/c/createtoolhelp32snapshot.com/ref/c/createtoolhelp32snapshot.26. E-mail: vbapi@vbapi.168. 2000 Go back to the Windows API Guide home page.vbapi.com Send Encrypted E-Mail This page is at http://www. 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29.

html (1 of 5) [9/1/2002 5:13:48 PM] . If an error occured.vbworld. Windows CE: Requires Windows CE 1.1 or later.vbshop. http://216.0 or later.com .com | www. Return Value If successful. lpWindowName The name to give the newly created window.com | www. Windows 2000: Supported. ByVal hInstance As Long. ByVal x As Long. ByVal lpWindowName As String.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long. The window can be a "regular" (overlapped) window. Parameters dwExStyle A combination of extended styles to give the window.part of the VB-World Network | www. lpParam As Any) As Long Platforms q q q q q Windows 95: Supported. This class must have previously been registered using RegisterClassEx. Windows NT: Requires Windows NT 3. the function returns a handle to the newly created window. ByVal nHeight As Long. Windows 98: Supported.vbapi. this text appears in the window's title bar.com | www. InitCommonControlsEx. or a popup window. Visual Basic-Specific Issues None.26. For controls.Windows API Guide: CreateWindowEx Function vbapi. lpClassName The name of the class to create the window using. a control on another window.92/vbapi/ref/c/createwindowex. For regular windows. the function returns zero (use GetLastError to get the error code). ByVal hMenu As Long. or some other function that registers window classes.vbsquare.vbforums. this text will be the initial content of the control.168. ByVal hWndParent As Long.com | CreateWindowEx Function Declare Function CreateWindowEx Lib "user32.com | www. ByVal nWidth As Long. ByVal y As Long. ByVal dwStyle As Long. Description & Usage CreateWindowEx creates a new window. ByVal lpClassName As String.

To not give the window a menu. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand. It is interpreted in the same way as x. y The initial y-coordinate of the upper-left corner of the window to create. This parameter is ignored if x is set to CW_USEDEFAULT. nHeight The initial height of the window. If this window is a child of another window.Windows API Guide: CreateWindowEx Function dwStyle A combination of the window styles to give the window. used in the window creation messages. this is the child-window identifier. used to notify its parent about events.26. hMenu A handle to a menu to assign to the window. ' This code is licensed according to the terms and conditions listed here. this should be zero. this coordinate is relative to its parent window. the program looks up the first domain name assigned to that address. otherwise it is relative to the screen. this parameter will be ignored.168. place a command button named cmdGetDomain on a form window. set this parameter to zero. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. For child windows. hWndParent A handle to the parent of the window to create. If x is set to CW_USEDEFAULT. Windows 2000: Set this parameter to HWND_MESSAGE to create a message-only window. To use this example.92/vbapi/ref/c/createwindowex. When the user clicks button cmdGetDomain. This is normally a combination of base window styles and styles that are specific to the window's class.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long http://216.html (2 of 5) [9/1/2002 5:13:48 PM] . nHeight will be ignored and the window will be given a default size. If the window does not have a parent. lParam An additional value to associate with the window. y will be ignored and the window will be placed in a default position. nWidth The initial width of the window. Constant Definitions Const CW_USEDEFAULT = &H80000000 Const HWND_BROADCAST = &HFFFF Example Create an IP Address control and use it to prompt the user for an IP address. If this is CW_USEDEFAULT (for an overlapped window only). If this is CW_USEDEFAULT (for overlapped windows only). x The initial x-coordinate of the upper-left corner of the window to create. hInstance A handle to the instance of the module or program that owns the window.

lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32. ByVal lpWindowName As String. Source _ As Any. ByVal hWndParent As Long.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long. ByVal x _ As Long. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32. ByVal dwStyle As Long.168.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.Windows API Guide: CreateWindowEx Function lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.26. ByVal length As Long.dll" (ByVal wVersionRequested As Integer. ByVal nWidth As Long. ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32. _ ByVal lpClassName As String.92/vbapi/ref/c/createwindowex. _ ByVal hMenu As Long.dll" Alias "RtlMoveMemory" (Destination As Any. ByVal y As Long. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.dll" Alias "SendMessageA" (ByVal hWnd As Long. ByVal hInstance As Long.dll" (addr As Long. wParam As Any.html (3 of 5) [9/1/2002 5:13:48 PM] . ByVal Msg _ As Long. ByVal nHeight As Long. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 http://216.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.

IPM_ISBLANK.92/vbapi/ref/c/createwindowex. create an IP Address control in the ' upper-left corner of the form.html (4 of 5) [9/1/2002 5:13:48 PM] . ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. 125. IPM_GETADDRESS.168. ipAddress_h) If retval < 4 Then http://216.hWnd. WS_CHILD Or WS_VISIBLE. in network byte order ' information about the Winsock implementation Dim sockinfo As WSADATA Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT Dim domainName As String ' the primary domain name of the host computer Dim retval As Long ' generic return value ' Verify that an IP address was entered. 20. retval = SendMessage(hIPControl. *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered.hInstance. ByVal CLng(0)) If retval <> 0 Then Debug. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long ' the IP address. _ Me.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim retval As Long ' generic return value ' Register the IP Address control window class.26. "". retval = SendMessage(hIPControl. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control. 0. 0. ByVal CLng(0). WC_IPADDRESS. in host byte order Dim ipAddress_n As Long ' the IP address.dwSize = Len(comctls) . hIPControl = CreateWindowEx(0. ByVal CLng(0). App. With comctls .Windows API Guide: CreateWindowEx Function ' *** Place the following code in a form window. 0.

E-mail: vbapi@vbapi. domainName = Space(lstrlen(hostinfo. Last Modified: October 29. Len(hostinfo) ' Copy the host domain name into a string.com Send Encrypted E-Mail This page is at http://www.h_name)) retval = lstrcpy(domainName. CopyMemory hostinfo.html (5 of 5) [9/1/2002 5:13:48 PM] . pHostinfo = gethostbyaddr(ipAddress_n.Print "Could not find a host with the specified IP address.Print "Domain name is: ".html http://216.h_name) Debug." Else ' Copy the data into the structure.vbapi. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page. ByVal pHostinfo. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer.com/ref/c/createwindowex.Print "ERROR: Attempt to open Winsock failed: error".Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2. retval Exit Sub End If ' Convert the IP address into network byte order. 2000 This page is copyright © 2000 Paul Kuliniewicz.168. retval = WSACleanup() End Sub See Also DestroyWindow Category Windows Back to the Function list.Windows API Guide: CreateWindowEx Function Debug. domainName End If ' End the Winsock session. AF_INET) If pHostInfo = 0 Then Debug. sockinfo) If retval <> 0 Then Debug. 4. Back to the Reference section.2 session.26. retval = WSAStartup(&H202.92/vbapi/ref/c/createwindowex. hostinfo.

92/vbapi/ref/d/defwindowproc. Description & Usage DefWindowProc explicitly calls the operating system's default window procedure to process a message for a window. Windows 2000: Supported. ByVal wParam As Long. Windows 98: Supported.part of the VB-World Network | www.html (1 of 3) [9/1/2002 5:14:00 PM] . Msg The message to process.Windows API Guide: DefWindowProc Function vbapi.vbshop.com | www.com | www.vbsquare. http://216.vbforums.0 or later.1 or later.vbworld.26. This default window procedure provides the minimal functionality necessary for a window procedure function and should be used to provide the default implementation of window messages. wParam Additional information about the message. lParam Additional information about the message. Parameters hWnd A handle to the window to process a message for.com . ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported. ByVal Msg As Long. Windows NT: Requires Windows NT 3.dll" Alias "DefWindowProcA" (ByVal hWnd As Long. Visual Basic-Specific Issues None.com | www. Return Value The function returns the return value of whatever message was processed.168.com | www.vbapi.com | DefWindowProc Function Declare Function DefWindowProc Lib "user32. Windows CE: Requires Windows CE 1.

*** Public pVBProc As Long ' pointer to Visual Basic's window procedure ' (The above variable defaults to 0 automatically. pVBProc = 0 End If ' By allowing the user to switch back and forth. lParam) End Function ' *** Place the following code wherever you wish. pVBProc = SetWindowLong(Form1. Switch to using ' the default one and save the pointer to the VB one. ByVal uMsg As Long. Public Function WindowProc (ByVal hWnd As Long.hWnd.92/vbapi/ref/d/defwindowproc.) ' The following function acts as a wrapper. GWL_WNDPROC. wParam. http://216. uMsg.168. the differences will ' become apparent. See Also CallWindowProc Category Window Procedures Go back to the alphabetical Function listing. Go back to the Reference section index. ByVal lParam As Long) As Long ' Call the default window procedure and return its result. ' *** Place the following code in a module. *** Dim retval As Long ' return value If pVBProc = 0 Then ' Window Form1 is using the VB-provided procedure. AddressOf WindowProc) Else ' Window Form1 is using the default procedure (via the wrapper ' function). ByVal wParam As Long. pVBProc) ' Set pVBProc to 0 so we know which one is being used. WindowProc = DefWindowProc(hWnd.hWnd. GWL_WNDPROC.html (2 of 3) [9/1/2002 5:14:00 PM] . ' ' ' ' Demonstrate how Visual Basic provides a more robust window procedure for windows it creates for the programmer when compared to Windows's default window procedure.Windows API Guide: DefWindowProc Function Example ' This code is licensed according to the terms and conditions listed here. All it ' does is call the default window procedure. retval = SetWindowLong(Form1. Switch to using the VB one.26. Do this by "toggling" between the default and the Visual Basic provided one.

168.26. E-mail: vbapi@vbapi.92/vbapi/ref/d/defwindowproc.Windows API Guide: DefWindowProc Function Last Modified: August 23. 2000 Go back to the Windows API Guide home page.vbapi.html http://216. 1999 This page is copyright © 1999 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.com/ref/d/defwindowproc. Copyright Information Revised October 29.html (3 of 3) [9/1/2002 5:14:00 PM] .

com | DeleteDC Function Declare Function DeleteDC Lib "gdi32.vbshop. If successful.168. Your program should delete a device context once it has finished using it in order to conserve resources. Windows NT: Requires Windows NT 3.1 or later. 2000: use GetLastError to get the error code). Visual Basic-Specific Information None.92/vbapi/ref/d/deletedc.com | www.vbapi. Windows 2000: Supported.com | www. Windows CE: Requires Windows CE 1. ' Print out a page with an ellipse drawn with a thickened black ' pen on it.com . Parameters hdc A handle to the device context to delete.com | www.vbworld. http://216. the function returns a non-zero value.html (1 of 3) [9/1/2002 5:14:14 PM] . Windows 98: Supported.vbforums. Do not use this function to close a device context gotten from GetDC -. The page is printed on the computer's default printer. Example ' This code is licensed according to the terms and conditions listed here.dll" (ByVal hdc As Long) As Long Platforms q q q q q Windows 95: Supported.part of the VB-World Network | www. Return Value If an error occured.vbsquare.com | www. the function returns 0 (Windows NT.26. Description & Usage DeleteDC destroys a device context which was created by CreateDC.0 or later.for those.Windows API Guide: DeleteDC Function vbapi. use ReleaseDC instead.

0. Declare Function lstrcpy Lib "kernel32. consult the ' EnumPrinters page.pPrinterName = Space(lstrlen(buffer(1))) retval = lstrcpy(pi2. using its default initialization.92/vbapi/ref/d/deletedc. hPen = CreatePen(PS_SOLID. printret) If retval = 0 Then Debug. RGB(0.pPrinterName.cbSize = Len(di) ' size of structure di.dll" Alias "lstrcpyA" (ByVal lpString1 As String.lpszDatatype = "" ' data type of file doesn't apply di.26.pPrinterName. retval = StartDoc(hPrintDC.pDriverName = Space(lstrlen(buffer(4))) retval = lstrcpy(pi2.pDriverName. spaceneeded. For a more detailed ' description of the semi-confusing code below.lpszDocName = "Printer API Demonstration" ' name of document di.168. 3076. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. All the ' other information retrieved is not needed and is omitted here. 0)) ' Load information about the document to print into the structure." End ' abort the program End If ' Copy the device and driver names to the structure. di) ' Begin the first and only page to print. retval = StartPage(hPrintDC) ' Select the pen for use with the printer. "". di. 2. buffer(1)) pi2. pi2. ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long ' Variable declarations Dim hPrintDC As Long ' handle to the printer's device context Dim di As DOCINFO ' information about the document to print Dim hPen As Long ' handle to the pen to draw the ellipse with Dim hOldPen As Long ' handle to the printer's previously selected pen Dim buffer(0 To 3076 / 4) As Long ' 3076-byte buffer Dim pi2 As PRINTER_INFO_2 ' receives info about the default printer Dim printret As Long ' receives the number of printers returned from EnumPrinters Dim spaceneeded As Long ' receives space requires for EnumPrinters Dim retval As Long ' return value ' Get the device and driver names of the default printer. pi2.fwType = 0 ' no additional information ' Begin the print job. buffer(0). buffer(4)) ' Create a device context to the printer.lpszOutput = 0 ' do not print to a file di.html (2 of 3) [9/1/2002 5:14:14 PM] . hPrintDC = CreateDC("".Print "No default printer is configured. http://216. 0.Windows API Guide: DeleteDC Function ' The following are special declarations needed to allow string ' manipulation functions to use pointers to strings. 5. ByVal CLng(0)) ' Create a solid black brush with a thickness of 5.

DeleteObject(hPen) the device context to the printer. E-mail: vbapi@vbapi.html (3 of 3) [9/1/2002 5:14:14 PM] . ' Delete retval = ' Delete retval = the pen created for drawing. 2000.3000) retval = Ellipse(hPrintDC.26. hOldPen) ' End information about the first and only page.168. Copyright Information Revised October 29.Windows API Guide: DeleteDC Function hOldPen = SelectObject(hPrintDC.vbapi. 3000) ' Restore the printer's previously selected pen.92/vbapi/ref/d/deletedc. 1000. Go back to the Reference section index. 1500.com Send Encrypted E-Mail This page is at http://www. retval = SelectObject(hPrintDC. retval = EndDoc(hPrintDC) ' The printer will now begin printing the document. retval = EndPage(hPrintDC) ' End information about the document.html http://216. 1999 This page is copyright © 1999 Paul Kuliniewicz. Last Modified: November 6. DeleteDC(hPrintDC) See Also CreateDC Category Devices Go back to the alphabetical Function listing.1500)-(2000. hPen) ' Draw an ellipse with bounding rectangle corners (1000.com/ref/d/deletedc. 2000 Go back to the Windows API Guide home page.

com | www.it does not send it to the Recycle Bin. Copyright Information.html http://216. Example: ' Delete the file C:\Dummy\thefile.html [9/1/2002 5:14:22 PM] . It also doesn't prompt to confirm the deletion.txt") If retval = 1 Then Debug.vbforums. This page is copyright © 2000 Paul Kuliniewicz.vbworld.vbapi.txt Dim retval As Long ' return value retval = DeleteFile("C:\Dummy\thefile.vbsquare.vb-shop.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long Platforms: Win 32s.vbapi.26.com Send Encrypted E-Mail This page is at http://www. Go back to the Reference section index.com | DeleteFile Function Declare Function DeleteFile Lib "kernel32.com | www. The function returns 1 if successful.com .com | www." Category: Files Go back to the alphabetical Function listing. Go back to the Windows API Guide home page. lpFileName The name of the file to delete.168.com | www. Win NT DeleteFile deletes a file completely -.part of the VB-World Network | www. Win 95/98.Print "File deleted successfully.com/ref/d/deletefile.Windows API Guide: DeleteFile Function vbapi. E-mail: vbapi@vbapi. so use it carefully. or 0 if an error occured (most likely the file doesn't exist).92/vbapi/ref/d/deletefile.

hDC. Example: ' Draw a rectangle with corners (10. 175. palette.168.com | DeleteObject Function Declare Function DeleteObject Lib "gdi32.Windows API Guide: DeleteObject Function vbapi.vbworld.com | www. 100) ' Restore Form1's previous brush before destroying the created one retval = SelectObject(Form1. pens. The function returns 1 if successful.26. or 0 if an error occured. 10. palettes. Of course the object should never be deleted until it is no longer in use by any devices (see the example for a demonstration). hObject A handle to the bitmap.com .92/vbapi/ref/d/deleteobject. pen.com | www. Go back to the Windows API Guide home page. 0)) ' create a solid yellow brush ' Save Form1's default brush so we can restore it after the program is finished holdbrush = SelectObject(Form1. This page is copyright © 2000 Paul Kuliniewicz. fonts.vbapi. Dim hbrush As Long ' receives handle to the solid yellow brush Dim holdbrush As Long ' receives handle to Form1's default brush Dim retval As Long ' return value hbrush = CreateSolidBrush(RGB(255.com Send Encrypted E-Mail http://216. These objects include bitmaps. brushes.com | www.vbsquare. Copyright Information.vbforums. Deleting the object frees up system resources associated with it. and regions.100) ' on window Form1. E-mail: vbapi@vbapi.html (1 of 2) [9/1/2002 5:15:13 PM] . font.dll" (ByVal hObject As Long) As Long DeleteObject deletes an object after the program has finished using it.hDC. holdbrush) ' select old brush retval = DeleteObject(hbrush) ' destroy the solid yellow brush Category: Devices Go back to the alphabetical Function listing.hDC. Use a solid yellow brush to fill the rectangle. 255.20) and (175. 20. Go back to the Reference section index. hbrush) ' select the brush ' Draw the rectangle filled using the solid yellow brush retval = Rectangle(Form1.vbshop.part of the VB-World Network | www. or region to delete. brush.com | www.

html http://216.Windows API Guide: DeleteObject Function This page is at http://www.92/vbapi/ref/d/deleteobject.html (2 of 2) [9/1/2002 5:15:13 PM] .com/ref/d/deleteobject.168.26.vbapi.

com | www. Win NT DestroyCursor destroys a cursor and deletes its handle. The new ' cursor is then set to be the cursor for 10 seconds. xorbuffer As String ' buffers for masks Dim andbits(0 To 127) As Byte ' stores the AND mask Dim xorbits(0 To 127) As Byte ' stores the XOR mask Dim c As Integer. Each sequence of eight hex ' characters represents one line in the 32x32 cursor.com | www. Example: ' Create a 32x32 color cursor shaped somewhat like a yin-yang symbol. ' (The bit masks come from Microsoft's documentation on the API cursors function. ' To load the AND and XOR masks. hCursor A handle to the cursor to delete. andbuffer = "FFFC3FFF" & "FFC01FFF" & "FF003FFF" & "FE00FFFF" & _ "F701FFFF" & "F003FFFF" & "F003FFFF" & "E007FFFF" & _ "C007FFFF" & "C00FFFFF" & "800FFFFF" & "800FFFFF" & _ "8007FFFF" & "8007FFFF" & "0003FFFF" & "0000FFFF" & _ "00007FFF" & "00001FFF" & "00000FFF" & "80000FFF" & _ "800007FF" & "800007FF" & "C00007FF" & "C0000FFF" & _ "E0000FFF" & "F0001FFF" & "F0001FFF" & "F8003FFF" & _ "FE007FFF" & "FF00FFFF" & "FFC3FFFF" & "FFFFFFFF" http://216.vbshop.168.) Note how the masks are loaded into the arrays. Win 95/98.com | DestroyCursor Function Declare Function DestroyCursor Lib "user32.com . just to ' give them their due credit. VB does not provide a nice way to load lots of information into an array.vbapi.vbworld.Windows API Guide: DestroyCursor Function vbapi. Note the ' use of the line-continuation character here.92/vbapi/ref/d/destroycursor.html (1 of 2) [9/1/2002 5:15:23 PM] .dll" (ByVal hCursor As Long) As Long Platforms: Win 32s. Do not use this function with a cursor handle obtained in any other manner! The function returns 1 if successful. or 0 if an error occured.26. it's ugly. The cursor must have been created using the CreateCursor functions. Yes.com | www. retval As Long ' counter and return value ' Unfortunately.vbforums.com | www.part of the VB-World Network | www.vbsquare. Dim hnewcursor As Long ' newly created cursor Dim holdcursor As Long ' receives handle of default cursor Dim andbuffer As String. we put the raw hex values into the string buffers ' and use a loop to convert the hex values into numeric values and load them into ' the elements of the array. but there's no better way.

Windows API Guide: DestroyCursor Function xorbuffer = "00000000" & "0003C000" & "003F0000" & "00FE0000" "0EFC0000" & "07F80000" & "07F80000" & "0FF00000" "1FF00000" & "1FE00000" & "3FE00000" & "3FE00000" "3FF00000" & "7FF00000" & "7FF80000" & "7FFC0000" "7FFF0000" & "7FFF8000" & "7FFFE000" & "3FFFE000" "3FC7F000" & "3F83F000" & "1F83F000" & "1F83E000" "0FC7E000" & "07FFC000" & "07FFC000" & "01FF8000" "00FF0000" & "003C0000" & "00000000" & "00000000" ' Now load these hex values into the proper arrays. E-mail: vbapi@vbapi. 19. For c = 0 To 127 andbits(c) = "&H" & Mid(andbuffer. create this cursor! The hotspot is at (19. Copyright Information. andbits(0). This page is copyright © 2000 Paul Kuliniewicz. retval = DestroyCursor(hnewcursor) See Also: CreateCursor Category: Cursor Go back to the alphabetical Function listing.html http://216.26.html (2 of 2) [9/1/2002 5:15:23 PM] .com Send Encrypted E-Mail This page is at http://www. 32.com/ref/d/destroycursor. 2 * c + 1) xorbits(c) = "&H" & Mid(xorbuffer. xorbits(0)) ' Set the new cursor as the current cursor for 10 seconds and then switch back. 2 * c + 1) Next c & & & & & & & _ _ _ _ _ _ _ ' Finally.168.92/vbapi/ref/d/destroycursor. holdcursor = SetCursor(hnewcursor) ' change cursor Sleep 10000 ' wait for 10 seconds retval = SetCursor(holdcursor) ' change cursor back ' Destroy the new cursor. 2. Go back to the Windows API Guide home page. hnewcursor = CreateCursor(App. 32.2) on the cursor. Go back to the Reference section index.hInstance.vbapi.

dll" (ByVal hIcon As Long) As Long Platforms q q q q q Windows 95: Supported.html (1 of 2) [9/1/2002 5:15:31 PM] .vbforums. Windows NT: Requires Windows NT 3.com | www. Windows CE: Requires Windows CE 1.com | DestroyIcon Function Declare Function DestroyIcon Lib "user32.vbapi.com | www. An icon cannot be in use when the program destroys it. whether it is used by the program or other programs.1 or later.com | www.com . Example http://216. the function returns 0 (use GetLastError to get the error code).168. Parameters hIcon A handle to the icon to destroy. while others do not.com | www.part of the VB-World Network | www.vbsquare.Windows API Guide: DestroyIcon Function vbapi.vbworld.vb-shop.26. Return Value If an error occured.0 or later. Windows 98: Supported. Windows 2000: Supported. the function returns a non-zero value. Visual Basic-Specific Issues None. Check the icon function in question to determine whether or not the icon must be destroyed. Some functions which provide an icon (sometimes but not necessarily creating it) require programs to use this function after using an icon. If successful.92/vbapi/ref/d/destroyicon. Description & Usage DestroyIcon destroys an icon and frees the memory which contained the icon.

vbapi.Windows API Guide: DestroyIcon Function ' This code is licensed according to the terms and conditions listed here. If hIcon = 0 Then Debug.hInstance. E-mail: vbapi@vbapi.exe".com/ref/d/destroyicon.168. 2000 Go back to the Windows API Guide home page.26. Copyright Information Revised October 29. ' Therefore we destroy it to free up resources. The icon must be destroyed after the ' program finishes using it.92/vbapi/ref/d/destroyicon. ' Display the first icon (index 0) stored in the executable file ' C:\MyApp\Prog.html http://216. hIcon = ExtractIcon(App. Go back to the Reference section index. retval = DestroyIcon(hIcon) End If Category Icons Go back to the alphabetical Function listing.html (2 of 2) [9/1/2002 5:15:31 PM] . Last Modified: August 4. 0) ' Only attempt to display the icon if we successfully extracted it. 75) on window Form1.hDC.Print "Failed to extract the icon -. 75.com Send Encrypted E-Mail This page is at http://www. retval = DrawIcon(Form1. hIcon) ' Although the icon's image is still visible.aborting. the icon itself is not in use." End ' terminate the program Else ' Display the icon at coordinates (100. Dim hIcon As Long ' handle to the function gotten from the executable file Dim retval As Long ' return value ' Extract the first icon stored in the aforementioned executable file. 1999 This page is copyright © 1999 Paul Kuliniewicz. 100.exe on window Form1. "C:\MyApp\Prog.

vbapi.vbsquare.com | www.com | DestroyMenu Function Declare Function DestroyMenu Lib "user32. Description & Usage DestroyMenu destroys a menu resource.) http://216. the function returns 0 (use GetLastError to get the error code). If an error occured.e. Parameters hMenu A handle to the menu to be destroyed. Windows 2000: Supported. Return Value If successful.dll" (ByVal hMenu As Long) As Long Platforms q q q q q Windows 95: Supported. it is not necessary to call DestroyMenu to destroy a menu that is assigned as a window's menu (or any submenus of that menu). Windows CE: Requires Windows CE 1.vbshop.1 or later.com .com | www. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.com | www. Menus should be destroyed when no longer needed in order to free resources.0 or later.168. Example ' This code is licensed according to the terms and conditions listed here.part of the VB-World Network | www.vbworld. Windows 98: Supported.Windows API Guide: DestroyMenu Function vbapi.26.92/vbapi/ref/d/destroymenu. However.com | www. Windows NT: Requires Windows NT 3. a menu bar) or a popup menu.html (1 of 5) [9/1/2002 5:15:37 PM] . Visual Basic-Specific Issues None.. Those menus are automatically destroyed when their window closes.vbforums. This menu can be either a "regular" menu (i. the function returns a non-zero value.

26. ByVal fByPosition As Long.dll" () As Long Public Declare Function DestroyMenu Lib "user32.dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_ID = &H2 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFT_STRING = &H0 Public Const MFS_DEFAULT = &H1000 Public Const MFS_ENABLED = &H0 Public Declare Function InsertMenuItem Lib "user32. ByVal x As Long. ByVal uItem As Long.Windows API Guide: DestroyMenu Function Public Declare Function CreatePopupMenu Lib "user32.92/vbapi/ref/d/destroymenu. ByVal y As Long. ByVal _ fuFlags As Long. lptpm As _ TPMPARAMS) As Long Public Const TPM_LEFTALIGN = &H0 Public Const TPM_TOPALIGN = &H0 Public Const TPM_NONOTIFY = &H80 Public Const TPM_RETURNCMD = &H100 Public Const TPM_LEFTBUTTON = &H0 Public Type POINT_TYPE x As Long y As Long End Type Public Declare Function GetCursorPos Lib "user32.html (2 of 5) [9/1/2002 5:15:37 PM] .168.dll" (lpPoint As POINT_TYPE) As Long http://216.dll" (ByVal hMenu As Long.dll" Alias "InsertMenuItemA" (ByVal _ hMenu As Long. ByVal hWnd As Long. lpmii As _ MENUITEMINFO) As Long Public Type RECT left As Long top As Long right As Long bottom As Long End Type Public Type TPMPARAMS cbSize As Long rcExclude As RECT End Type Public Declare Function TrackPopupMenuEx Lib "user32.

1. They are not actually part of the API.26.. instead." . ..fType = MFT_STRING ' This item is currently enabled and is the default item. hPopupMenu = CreatePopupMenu() ' Add the menu's first item: "About This Problem. .fState = MFS_ENABLED Or MFS_DEFAULT ' Assign this item an item identifier..92/vbapi/ref/d/destroymenu.dwTypeData = "&About This Example. divided by a separator bar.cbSize = Len(mii) ' Which elements of the structure to use. 1. The menu is created when ' needed and is destroyed after its use.fState = MFS_ENABLED .Windows API Guide: DestroyMenu Function Public Declare Function SetRectEmpty Lib "user32. . With mii .html (3 of 5) [9/1/2002 5:15:37 PM] . ." Private Const ID_ABOUT = 101 Private Const ID_SEPARATOR = 102 Private Const ID_EXIT = 103 Private Sub Dim Dim Dim Dim Dim Dim Command1_Click() hPopupMenu As Long mii As MENUITEMINFO tpm As TPMPARAMS curpos As POINT_TYPE menusel As Long retval As Long ' ' ' ' ' ' handle to the popup menu to display describes menu items to add identifies the exclusion rectangle holds the current mouse coordinates ID of what the user selected in the popup menu generic return value ' Create the popup menu that will be displayed.fType = MFT_SEPARATOR .wID = ID_ABOUT ' Display the following text for the item. mii) ' Add the final item: "Exit". With mii .dll" (lpRect As RECT) As Long ' When the user clicks button Command1. .168.dwTypeData) End With retval = InsertMenuItem(hPopupMenu. have a very simple popup menu appear.cch = Len(. they are ' used just to eliminate "magic numbers. The ' menu only has two options.. 0. ' The following application-defined constants are used to name the menu item ' identifiers used by this example. mii) ' Add the second item: a separator bar." With mii ' The size of this structure. .fType= MFT_STRING .wID = ID_EXIT http://216.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE ' The type of item: a string. 1.wID = ID_SEPARATOR End With retval = InsertMenuItem(hPopupMenu.

in order to have ' the popup menu appear at that point.168. .html (4 of 5) [9/1/2002 5:15:37 PM] .". With tpm ' Size of the structure. menusel = TrackPopupMenuEx(hPopupMenu.26. curpos.cch = Len(. "Windows API Guide") Case ID_EXIT ' End this program by closing and unloading Form1.y. 2.cbSize = Len(tpm) ' Make the exclusion rectangle empty. TPM_TOPALIGN Or TPM_LEFTALIGN Or TPM_NONOTIFY _ Or TPM_RETURNCMD Or TPM_LEFTBUTTON.hWnd. retval = DestroyMenu(hPopupMenu) Select Case menusel Case ID_ABOUT ' Use the Visual Basic MsgBox function to display a short message in a dialog ' box. retval = SetRectEmpty(. destroy the popup menu now. Unload Form1 End Select End Sub See Also CreatePopupMenu Category Menus http://216.92/vbapi/ref/d/destroymenu. Form1. retval = GetCursorPos(curpos) ' Make the exclusion rectangle empty because there's no need for it here.rcExclude) End With ' Display the popup menu at the mouse cursor.dwTypeData) End With retval = InsertMenuItem(hPopupMenu. have the function merely return the ID of the user's selection.Windows API Guide: DestroyMenu Function . tpm) ' Before acting upon the user's selection. vbOkOnly Or vbInformation. mii) ' Determine where the mouse cursor currently is. Instead of sending messages ' to window Form1. 1.dwTypeData = "E&xit" .x. curpos. Using the MessageBox API function isn't necessary. retval = MsgBox("This example demonstrates how to use the API to display " & _ "a pop-up menu.

Last Modified: June 4. 2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi.168.html (5 of 5) [9/1/2002 5:15:37 PM] . Copyright Information Revised October 29.92/vbapi/ref/d/destroymenu. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: DestroyMenu Function Back to the Function list.com/ref/d/destroymenu. Back to the Reference section.html http://216.vbapi.26.

Win NT EnableWindow enables or disables a window.hWnd) If wasenabled = 0 Then ' if not enabled. fEnable If 0.dll" (ByVal hwnd As Long. wasenabled = IsWindowEnabled(Command1. disable it retval = EnableWindow(Command1. Example: ' Reverse the enabled status of window Command1. or a non-zero value if the window had been disabled.html (1 of 2) [9/1/2002 5:15:39 PM] . although any window can be enabled or disabled. the window will be disabled. Win 95/98. hwnd A handle to the window to enable or disable.92/vbapi/ref/e/enablewindow.168. the window will be enabled.com | www. 0) End If See Also: IsWindowEnabled Category: Windows http://216. ByVal fEnable As Long) As Long Platforms: Win 32s.Windows API Guide: EnableWindow Function vbapi.vbapi. The function returns 0 if the window had previously been enabled. Dim wasenabled As Long ' receives enabled/disabled status of Command1 Dim retval As Long ' return value ' Determine if the window Command1 is currently enabled or not. If the window is ' disabled. enable it.26. if it is enabled.com | www.com | www.hWnd.com | EnableWindow Function Declare Function EnableWindow Lib "user32. disable it. If a window is disabled. 1) Else ' if enabled. enable it retval = EnableWindow(Command1.vbworld. Some types of windows.vb-shop.hWnd. will appear grayed when disabled.part of the VB-World Network | www. such as buttons and other controls. it cannot receive the focus and will ignore any attempted input. If non-zero.vbforums.com .vbsquare.com | www.

This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/e/enablewindow.168. E-mail: vbapi@vbapi.26.com/ref/e/enablewindow. Copyright Information. Go back to the Reference section index.Windows API Guide: EnableWindow Function Go back to the alphabetical Function listing.vbapi.html (2 of 2) [9/1/2002 5:15:39 PM] . Go back to the Windows API Guide home page.html http://216.

dll" (ByVal hWnd As Long) As Long Platforms q q q q q Windows 95: Supported.168. however.com | www. If an error occured.part of the VB-World Network | www. timers. Windows 98: Supported.1 or later.vbsquare. When the user clicks button cmdGetDomain. Description & Usage DestroyWindow destroys a window. To use this example. the function returns a nonzero value.com .html (1 of 5) [9/1/2002 5:15:52 PM] .vbworld. Windows NT: Requires Windows NT 3.Windows API Guide: DestroyWindow Function vbapi. http://216.vbshop. Example Create an IP Address control and use it to prompt the user for an IP address.com | www.92/vbapi/ref/d/destroywindow. the program looks up the first domain name assigned to that address. or child windows are automatically destroyed along with it.com | www. Any menus. the function returns zero (use GetLastError to get the error code). place a command button named cmdGetDomain on a form window. Windows 2000: Supported. Visual Basic-Specific Issues None.vbapi. Parameters hWnd A handle to the window to destroy.26. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand.0 or later. Return Value If successful. DestroyWindow only works with windows that are owned by the calling program.com | www.vbforums. Windows CE: Requires Windows CE 1.com | DestroyWindow Function Declare Function DestroyWindow Lib "user32.

dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32. ByVal nWidth As Long.168.dll" Alias "RtlMoveMemory" (Destination As Any.92/vbapi/ref/d/destroywindow. ByVal lpWindowName As String.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.26.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.html (2 of 5) [9/1/2002 5:15:52 PM] . _ ByVal lpClassName As String. ByVal nHeight As Long. _ http://216.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long.Windows API Guide: DestroyWindow Function ' This code is licensed according to the terms and conditions listed here. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. ByVal hWndParent As Long.dll" (ByVal wVersionRequested As Integer.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. ByVal y As Long. ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32. ByVal length As Long. ByVal x _ As Long.dll" (addr As Long. ByVal dwStyle As Long. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32. Source _ As Any.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.

hIPControl = CreateWindowEx(0. ByVal Msg _ As Long. _ Me. 0.dll" Alias "SendMessageA" (ByVal hWnd As Long. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim retval As Long ' generic return value ' Register the IP Address control window class. WS_CHILD Or WS_VISIBLE.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32. It's not ' really necessary to do this. With comctls . lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window. since all children of the form will be automatically ' destroyed once the form is destroyed.26. "". *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized.92/vbapi/ref/d/destroywindow. ByVal hInstance As Long. WC_IPADDRESS.html (3 of 5) [9/1/2002 5:15:52 PM] .hWnd.Windows API Guide: DestroyWindow Function ByVal hMenu As Long. 125. 0. wParam As Any.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control.dwSize = Len(comctls) . in host byte order Dim ipAddress_n As Long ' the IP address. 20. after all. in network byte order Dim sockinfo As WSADATA ' information about the Winsock implementation Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT http://216. 0. App.168. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long ' the IP address. ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. But this is just an example. create an IP Address control in the ' upper-left corner of the form. lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32.hInstance.

retval = WSAStartup(&H202. 4.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2. IPM_GETADDRESS. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer.Print "ERROR: Attempt to open Winsock failed: error". pHostinfo = gethostbyaddr(ipAddress_n. sockinfo) If retval <> 0 Then Debug. WM_CLOSE Category http://216.2 session. retval = WSACleanup() End Sub See Also CreateWindowEx." Else ' Copy the data into the structure.168. domainName = Space(lstrlen(hostinfo. domainName End If ' End the Winsock session. AF_INET) If pHostInfo = 0 Then Debug.h_name) Debug. Len(hostinfo) ' Copy the host domain name into a string. hostinfo. ByVal CLng(0). retval = SendMessage(hIPControl.Windows API Guide: DestroyWindow Function Dim domainName As String Dim retval As Long ' the primary domain name of the host computer ' generic return value ' Verify that an IP address was entered. ipAddress_h) If retval < 4 Then Debug.Print "Could not find a host with the specified IP address. retval = SendMessage(hIPControl.26. retval Exit Sub End If ' Convert the IP address into network byte order. ByVal CLng(0).html (4 of 5) [9/1/2002 5:15:52 PM] . ByVal pHostinfo. CopyMemory hostinfo. IPM_ISBLANK.92/vbapi/ref/d/destroywindow.h_name)) retval = lstrcpy(domainName. ByVal CLng(0)) If retval <> 0 Then Debug.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered.Print "Domain name is: ".

E-mail: vbapi@vbapi. Last Modified: December 17.html (5 of 5) [9/1/2002 5:15:52 PM] . Back to the Reference section. Copyright Information Revised October 29. 2000 This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/d/destroywindow.Windows API Guide: DestroyWindow Function Windows Back to the Function list.26. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.168.html http://216.vbapi.com/ref/d/destroywindow.

The icon is always drawn in its normal dimensions.com | DrawIcon Function Declare Function DrawIcon Lib "user32.1 or later.vbforums.com | www. Return Value If an error occured.html (1 of 3) [9/1/2002 5:15:56 PM] . Windows 98: Supported. ByVal x As Long.26.com | www.vbworld.dll" (ByVal hDC As Long.Windows API Guide: DrawIcon Function vbapi.com | www.vbapi. x The x-coordinate of the point to position the upper-left corner of the icon's image at.0 or later. Windows CE: Requires Windows CE 1. Windows NT: Requires Windows NT 3.com | www. ByVal hIcon As Long) As Long Platforms q q q q q Windows 95: Supported.92/vbapi/ref/d/drawicon. the function returns a non-zero value. hIcon http://216.com .part of the VB-World Network | www. Parameters hDC A handle to a device context to the device to draw the icon on. Description & Usage DrawIcon displays an icon on a device.168. Visual Basic-Specific Issues None.vbsquare.vb-shop. If successful. Windows 2000: Supported. ByVal y As Long. the function returns 0 (use GetLastError to get the error code). The icon's position is determined by a coordinate pair passed to the function identifying the coordinates of the upper-left corner of the icon. y The y-coordinate of the point to position the upper-left corner of the icon's image at.

Example ' This code is licensed according to the terms and conditions listed here. 100. ' Display the first icon (index 0) stored in the executable file ' C:\MyApp\Prog.hDC.exe".hInstance. 0) ' Only attempt to display the icon if we successfully extracted it. The icon must be destroyed after the ' program finishes using it. 75) on window Form1. hIcon) ' Although the icon's image is still visible. 75. hIcon = ExtractIcon(App. Last Modified: August 4. 1999 This page is copyright © 1999 Paul Kuliniewicz." End ' terminate the program Else ' Display the icon at coordinates (100. Dim hIcon As Long ' handle to the function gotten from the executable file Dim retval As Long ' return value ' Extract the first icon stored in the aforementioned executable file. retval = DestroyIcon(hIcon) End If See Also DrawIconEx Category Icons Go back to the alphabetical Function listing. retval = DrawIcon(Form1. ' Therefore we destroy it to free up resources. the icon itself is not in use.exe on window Form1.168.92/vbapi/ref/d/drawicon. E-mail: vbapi@vbapi.26.Print "Failed to extract the icon -. "C:\MyApp\Prog. Go back to the Reference section index. 2000 Go back to the Windows API Guide home page.Windows API Guide: DrawIcon Function A handle to the icon to display.com Send Encrypted E-Mail http://216.aborting. Copyright Information Revised October 29. If hIcon = 0 Then Debug.html (2 of 3) [9/1/2002 5:15:56 PM] .

26.vbapi.168.com/ref/d/drawicon.Windows API Guide: DrawIcon Function This page is at http://www.html (3 of 3) [9/1/2002 5:15:56 PM] .92/vbapi/ref/d/drawicon.html http://216.

ByVal hbrFlickerFreeDraw As Long.com | DrawIconEx Function Declare Function DrawIconEx Lib "user32. Windows 98: Supported.com | www. Description & Usage DrawIconEx displays either an icon or a cursor (or a single frame of an animated cursor) on a device. Windows CE: Requires Windows CE 1. hIcon http://216.0 or later. Return Value If an error occured.com . Windows 2000: Supported. xLeft The x-coordinate of the point to position the upper-left corner of the icon's or cursor's image at.html (1 of 3) [9/1/2002 5:16:01 PM] . ByVal istepIfAniCur As Long.vbworld.part of the VB-World Network | www. ByVal diFlags As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns a nonzero value. yTop The y-coordinate of the point to position the upper-left corner of the icon's or cursor's image at.vbshop. The function can stretch the image in either direction as well as specify other display parameters. Parameters hdc A handle to a device context to the device to draw the icon or cursor on. The image's position is determined by passing the coordinates of the upper-left corner of the image. Windows NT: Requires Windows NT 3.168.com | www. Visual Basic-Specific Issues None. ByVal xLeft As Long. ByVal cxWidth As Long.dll" (ByVal hdc As Long.92/vbapi/ref/d/drawiconex. ByVal yTop As Long.vbsquare.com | www.26. If successful. the function returns 0 (use GetLastError to get the error code).5 or later.Windows API Guide: DrawIconEx Function vbapi.vbforums.com | www.vbapi. ByVal cyWidth As Long. ByVal hIcon As Long.

Windows API Guide: DrawIconEx Function A handle to the icon or cursor to draw. The background is added to the icon's or cursor's image using a flicker-free method. Display them in a row. draw the icon or cursor using the height and width settings defined by the system metrics. DI_DEFAULTSIZE If cxWidth and cyWidth are set to 0. If this is 0. Draw all icons on a light-gray ' background on the window Form1. cxWidth The width in pixels to stretch the icon's or cursor's image to. cyWidth The height in pixels to stretch the icon's or cursor's image to. this parameter is ignored. DI_IMAGE Draw the icon's or cursor's image data onto the device. depending on the flags passed as diFlags. Otherwise. diFlags A combination of the following flags specifying how to draw the icon or cursor: DI_COMPAT Draw the icon or cursor using the system default image instead of the user-specified image. DI_MASK Draw the icon's or cursor's mask data onto the device. hbrFlickerFreeDraw A handle to the brush to use as the icon's or cursor's background. this specifies the index of the particular frame to draw.26. Note how dynamically allocated arrays ' are used to receive the icon handles. Constant Definitions Const Const Const Const Const DI_COMPAT = &H4 DI_DEFAULTSIZE = &H8 DI_IMAGE = &H2 DI_MASK = &H1 DI_NORMAL = &H3 Example ' This code is licensed according to the terms and conditions listed here. the image is drawn using either the icon's or cursor's width or the default width of the system. the image is drawn using either the icon's or cursor's height or the default height of the system.92/vbapi/ref/d/drawiconex. istepIfAniCursor If hIcon is a handle to an animated cursor. as usual. the image is drawn directly onto the device without first adding a background. If this flag is not specified and the two parameters are set to 0. ' Extract all of the regular-sized icons from the file ' C:\MyApp\Prog. stretching or shrinking them to ' a width of 32 and a height of 64. If this is 0. Dim hIcons() As Long ' dynamic array to receive handles to the icons Dim numicons As Long ' number of regular icons in the file Dim hBrush As Long ' handle to the background brush to use http://216.exe. DI_NORMAL Draw the icon or cursor using both its image and mask. depending on the flags passed as diFlags. If this parameter is 0.168. the icon or cursor is drawn using its own dimensions.html (2 of 3) [9/1/2002 5:16:01 PM] .

Go back to the Reference section index. 0. ByVal 0. ByVal 0. ByVal 0.com/ref/d/drawiconex. Copyright Information Revised October 29. hIcons(c). 0. The y coordinate is always 0. 0) If numicons = 0 Then Debug." End ' abort the program if failure occurs End If ReDim hIcons(0 To numicons .vbapi.html http://216. E-mail: vbapi@vbapi. retval = DestroyIcon(hIcons(c)) Next c See Also DrawIcon Category Icons Go back to the alphabetical Function listing. hBrush. 1999 This page is copyright © 1999 Paul Kuliniewicz. For c = 0 To numicons . hBrush = GetStockObject(LTGRAY_BRUSH) ' handle to the brush ' Extract all of the icons to display.aborting. retval = DrawIconEx(Form1. ' Display this particular icon. hIcons(0).exe". DI_NORMAL) ' Now destroy this icon since we no longer are using it.92/vbapi/ref/d/drawiconex. numicons. numicons = ExtractIconEx("C:\MyApp\Prog. 32 * c. -1.1 ' The x coordinate equals 32 * c.Print "No icons found in the file -. 0) ' Loop through each icon.1) As Long ' resize the array to hold all the handles ' Get a handle to the stock solid light gray brush to use for the background.26. 2000 Go back to the Windows API Guide home page. 64. displaying it as previously mentioned. 32.168. retval = ExtractIconEx("C:\MyApp\Prog.html (3 of 3) [9/1/2002 5:16:01 PM] . Last Modified: August 5.exe".Windows API Guide: DrawIconEx Function Dim c As Long ' counter variable Dim retval As Long ' return value ' Determine how many regular icons exist in the file and resize ' the array accordingly.com Send Encrypted E-Mail This page is at http://www.hDC.

com | Ellipse Function Declare Function Ellipse Lib "gdi32. Y2 The y coordinate of the bounding rectangle's lower-right corner. 0) ' set color to draw in to red retval = Ellipse(PictureBox1.vbworld.vbforums. ByVal Y1 As Long. Y1 The y coordinate of the bounding rectangle's upper-left corner.com | www. hdc The device context of the object to draw on. or 1 if it succeeds. 0. if any.vbsquare. Chord.com | www.92/vbapi/ref/e/ellipse.com | www.168. Win 95/98. but define its bounding rectangle. X2 The x coordinate of the bounding rectangle's lower-right corner. ByVal X2 As Long. ArcTo. Example: ' Draw a red ellipse with bounding rectangle (25.com | www.26.30)-(100.part of the VB-World Network | www.ForeColor = RGB(255. 25. The two coordinate pairs passed to the function are not part of the ellipse itself. ByVal Y2 As Long) As Long Platforms: Win32s. X1 The x coordinate of the bounding rectangle's upper-left corner.75) ' on PictureBox1 Dim retval As Long ' return value PictureBox1.dll" (ByVal hdc As Long. ByVal X1 As Long.hdc.com . Win NT Ellipse draws an ellipse on a device. The bounding rectangle is the smallest possible rectangle containing the ellipse. The function returns 0 if it fails. 100. The ellipse is drawn using the device's current drawing color and is filled using the current filling color and brush.vbapi.vb-shop. 75) See Also: AngleArc.Windows API Guide: Ellipse Function vbapi. Arc.html (1 of 2) [9/1/2002 5:16:06 PM] . 30. Pie Category: Filled Shapes http://216.

Windows API Guide: Ellipse Function Go back to the alphabetical Function listing.html http://216.168. Copyright Information.vbapi. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:16:06 PM] . This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page. Go back to the Reference section index.26.92/vbapi/ref/e/ellipse.com/ref/e/ellipse.

Parameters hdc A handle to a device context to the printer which the document is to be printed using.com | www. The page is printed on the computer's default printer.1 or later.dll" (ByVal hdc As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns a positive value.com .vbapi. 2000: use GetLastError to get the error code).Windows API Guide: EndDoc Function vbapi. Description & Usage EndDoc informs the print spooler that the program has finished providing information for how to print a document.part of the VB-World Network | www.168. the function returns either zero or a negative value (Windows NT.com | www.com | www. Windows NT: Requires Windows NT 3.html (1 of 3) [9/1/2002 5:17:14 PM] . This function tells the spooler to finally print the document. ' Print out a page with an ellipse drawn with a thickened black ' pen on it. The StartDoc and EndDoc functions must bracket all the code which draws the document on the printer (see the example for an illustration).vbworld. Return Value If an error occured.0 or later.com | EndDoc Function Declare Function EndDoc Lib "gdi32.vbsquare. Visual Basic-Specific Issues None.com | www.vbforums. Windows CE: Requires Windows CE 2.vbshop. Example ' This code is licensed according to the terms and conditions listed here. Windows 2000: Supported.26. Windows 98: Supported. If successful. http://216.92/vbapi/ref/e/enddoc.

Declare Function lstrcpy Lib "kernel32." End ' abort the program End If ' Copy the device and driver names to the structure.168.Print "No default printer is configured.pDriverName = Space(lstrlen(buffer(4))) retval = lstrcpy(pi2.lpszDatatype = "" ' data type of file doesn't apply di. retval = StartPage(hPrintDC) ' Select the pen for use with the printer. ByVal CLng(0)) ' Create a solid black brush with a thickness of 5.dll" Alias "lstrcpyA" (ByVal lpString1 As String.html (2 of 3) [9/1/2002 5:17:14 PM] . buffer(4)) ' Create a device context to the printer. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. using its default initialization. retval = StartDoc(hPrintDC. 0. pi2. For a more detailed ' description of the semi-confusing code below.92/vbapi/ref/e/enddoc. 5.lpszDocName = "Printer API Demonstration" ' name of document di.pDriverName.lpszOutput = 0 ' do not print to a file di. buffer(1)) pi2. consult the ' EnumPrinters page.Windows API Guide: EndDoc Function ' The following are special declarations needed to allow string ' manipulation functions to use pointers to strings.pPrinterName.pPrinterName. "". 3076. 0)) ' Load information about the document to print into the structure.cbSize = Len(di) ' size of structure di. All the ' other information retrieved is not needed and is omitted here. di. http://216. printret) If retval = 0 Then Debug. RGB(0.pPrinterName = Space(lstrlen(buffer(1))) retval = lstrcpy(pi2. 2. ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32. spaceneeded.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long ' Variable declarations Dim hPrintDC As Long ' handle to the printer's device context Dim di As DOCINFO ' information about the document to print Dim hPen As Long ' handle to the pen to draw the ellipse with Dim hOldPen As Long ' handle to the printer's previously selected pen Dim buffer(0 To 3076 / 4) As Long ' 3076-byte buffer Dim pi2 As PRINTER_INFO_2 ' receives info about the default printer Dim printret As Long ' receives the number of printers returned from EnumPrinters Dim spaceneeded As Long ' receives space requires for EnumPrinters Dim retval As Long ' return value ' Get the device and driver names of the default printer. hPen = CreatePen(PS_SOLID. 0.fwType = 0 ' no additional information ' Begin the print job. pi2. buffer(0). di) ' Begin the first and only page to print.26. hPrintDC = CreateDC("".

hPen) ' Draw an ellipse with bounding rectangle corners (1000.com Send Encrypted E-Mail This page is at http://www. 1999 This page is copyright © 1999 Paul Kuliniewicz.com/ref/e/enddoc. retval = SelectObject(hPrintDC.Windows API Guide: EndDoc Function hOldPen = SelectObject(hPrintDC. Copyright Information Revised October 29.92/vbapi/ref/e/enddoc. 1000. Last Modified: November 2.1500)-(2000. 2000 Go back to the Windows API Guide home page. retval = EndPage(hPrintDC) ' End information about the document. DeleteObject(hPen) the device context to the printer. retval = EndDoc(hPrintDC) ' The printer will now begin printing the document.168. 1500.26.html (3 of 3) [9/1/2002 5:17:14 PM] . E-mail: vbapi@vbapi.html http://216. DeleteDC(hPrintDC) See Also StartDoc Category Printers Go back to the alphabetical Function listing. 2000.3000) retval = Ellipse(hPrintDC. hOldPen) ' End information about the first and only page. Go back to the Reference section index. ' Delete retval = ' Delete retval = the pen created for drawing. 3000) ' Restore the printer's previously selected pen.vbapi.

com | www.com | EndPage Function Declare Function EndPage Lib "gdi32. 2000: use GetLastError to get the error code). ' Print out a page with an ellipse drawn with a thickened black ' pen on it. Visual Basic-Specific Issues None. Description & Usage EndPage informs the print spooler that the program has finished drawing the contents of a printed page.com . Return Value If an error occured.1 or later. The page is printed on the computer's default printer.com | www.26. Windows CE: Requires Windows CE 2. The printer does not actually print the page until the print spooler is told via EndDoc that the entire document is complete. http://216.com | www. Windows 98: Supported.html (1 of 3) [9/1/2002 5:17:21 PM] .vbforums.168.part of the VB-World Network | www. The StartPage and EndPage functions must bracket all code which draws the contents of the printed page. Windows NT: Requires Windows NT 3.92/vbapi/ref/e/endpage. Parameters hDC A handle to a device context to the printer being used to print the document.vbapi.vbshop. The print spooler must have already been informed that it is receiving a document to be printed via StartDoc before drawing the page had begun. Example ' This code is licensed according to the terms and conditions listed here.vbworld. the function returns a positive value. the function returns either zero or a negative value (Windows NT. Windows 2000: Supported.vbsquare. If successful.0 or later.dll" (ByVal hDC As Long) As Long Platforms q q q q q Windows 95: Supported.com | www.Windows API Guide: EndPage Function vbapi.

retval = EnumPrinters(PRINTER_ENUM_DEFAULT.Windows API Guide: EndPage Function ' The following are special declarations needed to allow string ' manipulation functions to use pointers to strings.pPrinterName. pi2. buffer(1)) pi2.pPrinterName. Declare Function lstrcpy Lib "kernel32.pPrinterName = Space(lstrlen(buffer(1))) retval = lstrcpy(pi2.92/vbapi/ref/e/endpage. "". http://216. 5.pDriverName." End ' abort the program End If ' Copy the device and driver names to the structure. spaceneeded.dll" Alias "lstrcpyA" (ByVal lpString1 As String.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long ' Variable declarations Dim hPrintDC As Long ' handle to the printer's device context Dim di As DOCINFO ' information about the document to print Dim hPen As Long ' handle to the pen to draw the ellipse with Dim hOldPen As Long ' handle to the printer's previously selected pen Dim buffer(0 To 3076 / 4) As Long ' 3076-byte buffer Dim pi2 As PRINTER_INFO_2 ' receives info about the default printer Dim printret As Long ' receives the number of printers returned from EnumPrinters Dim spaceneeded As Long ' receives space requires for EnumPrinters Dim retval As Long ' return value ' Get the device and driver names of the default printer. 3076. hPen = CreatePen(PS_SOLID. di) ' Begin the first and only page to print.168.Print "No default printer is configured.lpszOutput = 0 ' do not print to a file di. ByVal CLng(0)) ' Create a solid black brush with a thickness of 5. buffer(4)) ' Create a device context to the printer. 0.lpszDatatype = "" ' data type of file doesn't apply di.pDriverName = Space(lstrlen(buffer(4))) retval = lstrcpy(pi2. All the ' other information retrieved is not needed and is omitted here. di. 0)) ' Load information about the document to print into the structure. retval = StartDoc(hPrintDC. using its default initialization.26. For a more detailed ' description of the semi-confusing code below. buffer(0).lpszDocName = "Printer API Demonstration" ' name of document di. pi2. consult the ' EnumPrinters page. 2.html (2 of 3) [9/1/2002 5:17:21 PM] . retval = StartPage(hPrintDC) ' Select the pen for use with the printer. RGB(0. 0. hPrintDC = CreateDC("". printret) If retval = 0 Then Debug. ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32.fwType = 0 ' no additional information ' Begin the print job.cbSize = Len(di) ' size of structure di.

' Delete retval = ' Delete retval = the pen created for drawing. 1000. Last Modified: November 5. hOldPen) ' End information about the first and only page. 1500. Go back to the Reference section index.Windows API Guide: EndPage Function hOldPen = SelectObject(hPrintDC. retval = SelectObject(hPrintDC. 3000) ' Restore the printer's previously selected pen. 1999 This page is copyright © 1999 Paul Kuliniewicz. retval = EndPage(hPrintDC) ' End information about the document. Copyright Information Revised October 29. DeleteDC(hPrintDC) See Also StartPage Category Printers Go back to the alphabetical Function listing.168. 2000. retval = EndDoc(hPrintDC) ' The printer will now begin printing the document.vbapi. hPen) ' Draw an ellipse with bounding rectangle corners (1000.html http://216. DeleteObject(hPen) the device context to the printer.92/vbapi/ref/e/endpage. E-mail: vbapi@vbapi.1500)-(2000.com/ref/e/endpage.3000) retval = Ellipse(hPrintDC.com Send Encrypted E-Mail This page is at http://www.html (3 of 3) [9/1/2002 5:17:21 PM] .26. 2000 Go back to the Windows API Guide home page.

92/vbapi/ref/e/enumchildwindows. Windows CE: Not Supported. Return Value If an error occured.com | www.1 or later.part of the VB-World Network | www. Description & Usage EnumChildWindows enumerates and provides handles to all of the child windows of a given window.vbshop. Parameters hWndParent A handle to the parent window to enumerate the child windows of.vbapi.Windows API Guide: EnumChildWindows Function vbapi.html (1 of 3) [9/1/2002 5:17:26 PM] .com . Windows 2000: Supported. the function returns 0 (use GetLastError to get the error code). the function passes that handle to a program-defined callback function. If successful.com | www.26.com | www. Windows NT: Requires Windows NT 3.dll" (ByVal hWndParent As Long.vbforums. The function continues doing so until all child windows have been enumerated. ByVal lpEnumFunc As Long.vbsquare.168. Visual Basic-Specific Issues None.vbworld. ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported. Example: http://216.com | www. Windows 98: Supported. the function returns a nonzero value. lParam An additional value to pass to the application-defined callback function. This function will also enumerate any children of the child windows. Each time a child window is located. or until the process has been aborted.com | EnumChildWindows Function Declare Function EnumChildWindows Lib "user32. lpEnumFunc A pointer to the application-defined callback function EnumChildProc.

Go back to the Reference section index. Copyright Information Revised October 29. Public Function EnumChildProc (ByVal hwnd As Long.hWnd. ByVal lParam As Long) As Long Dim slength As Long. This ' task is given to the callback function. ' display number of enumerated window Debug.Print Left(buffer.168. wintext As String ' window title text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated. E-mail: vbapi@vbapi. " : ".92/vbapi/ref/e/enumchildwindows.Windows API Guide: EnumChildWindows Function ' Display the window title of all children of window MDIForm1. EnumWindows Category Windows Go back to the alphabetical Function listing. ' *** Place this code in a module..26. 0) See Also EnumThreadWindows. slength . This is the callback function.html (2 of 3) [9/1/2002 5:17:26 PM] . winnum.Print "Window #". 1999 This page is copyright © 1999 Paul Kuliniewicz. Last Modified: August 15.1) ' display title bar text of enumerated window EnumChildProc = 1 End Function ' nonzero return value means continue enumeration ' *** Place this code wherever you want to enumerate the windows.com Send Encrypted E-Mail http://216.. which will receive each handle individually. Note that lParam is ' set to 0 because we don't need to pass any additional information to the function. retval = EnumChildWindows(MDIForm1. slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd.. buffer. slength) ' get title bar text Debug. 2000 Go back to the Windows API Guide home page. *** ' This function displays the title bar text of the window identified by hwnd. AddressOf EnumChildProc. *** Dim retval As Long ' return value ' Use the above callback function to list all of the enumerated windows.

26.92/vbapi/ref/e/enumchildwindows.vbapi.com/ref/e/enumchildwindows.168.html (3 of 3) [9/1/2002 5:17:26 PM] .Windows API Guide: EnumChildWindows Function This page is at http://www.html http://216.

dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String.168. Visual Basic-Specific Issues None. Parameters lpszDeviceName Windows 95. the function returns zero (Windows NT/2000: use GetLastError to get the error code). Windows CE: Not Supported.Windows API Guide: EnumDisplaySettings Function vbapi. the function returns a non-zero value. Description & Usage EnumDisplaySettings gets the display settings of one of a display device's graphics modes.vb-shop.com .26. Windows NT. Specifically. ByVal iModeNum As Long.vbapi. the function gets the display mode's resolution. or 3.com | EnumDisplaySettings Function Declare Function EnumDisplaySettings Lib "user32.vbforums.com | www.com | www. Windows 2000: Supported. If an error occured. 2000: If this is a null string. Windows NT: Requires Windows NT 3. and frequency. 98: This must be a null string. this is the device name of the display device to examine. lpDevMode As DEVMODE) As Long Platforms q q q q q Windows 95: Supported. Otherwise. 2.92/vbapi/ref/e/enumdisplaysettings.com | www. The string is of the form "\\.vbsquare. Return Value If successful. along with some additional information.part of the VB-World Network | www.vbworld. where X is 1.html (1 of 4) [9/1/2002 5:17:30 PM] . color depth. Windows 98: Supported. the current display device is used.51 or later. iModeNum http://216.\DisplayX".com | www.

this structure's dmSize member must be properly set.168. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.26. To use this example. Only the dmBitsPerPixel. dmDisplayFlags. lpDevMode Receives information about the graphics mode. place a command button named Command1 on a form window. This could also be one of the following flags specifying a graphics mode: ENUM_CURRENT_SETTINGS Get information about the current display settings. Constant Definitions Const ENUM_CURRENT_SETTINGS = -1 Const ENUM_REGISTRY_SETTINGS = -2 Example Display information about the current display settings for the monitor. ENUM_REGISTRY_SETTINGS Get information about the display settings stored in the registry.) Public Type DEVMODE dmDeviceName As String * 32 dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer http://216. ' This code is licensed according to the terms and conditions listed here. and dmDisplayFrequency members have useful data in them. dmPelsWidth. dmPelsHeight.92/vbapi/ref/e/enumdisplaysettings.Windows API Guide: EnumDisplaySettings Function The number of the graphics mode to retrieve information about.html (2 of 4) [9/1/2002 5:17:30 PM] . Before calling the function.

Display Freq.dmDisplayFrequency End Sub See Also ChangeDisplaySettings Category http://216. Debug.dmBitsPerPixel Debug. *** Private Sub Command1_Click() ' info about the display device Dim dm As DEVMODE Dim retval As Long ' return value ' Initialize the structure.Print ".dmPelsWidth Debug. dm) ' Print some information about the display. 98.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String. dm.html (3 of 4) [9/1/2002 5:17:30 PM] .168.92/vbapi/ref/e/enumdisplaysettings.Windows API Guide: EnumDisplaySettings Function dmFormName As String * 32 dmUnusedPadding As Integer dmBitsPerPixel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long ' The following only appear in Windows 95. dm. dm.dmPelsHeight Debug. dm.: ". ENUM_CURRENT_SETTINGS. lpDevMode As DEVMODE) As Long Public Const ENUM_CURRENT_SETTINGS = -1 Public Const ENUM_REGISTRY_SETTINGS = -2 ' *** Place the following code inside the form window.Print ". 2000 dmICMMethod As Long dmICMIntent As Long dmMediaType As Long dmDitherType As Long dmReserved1 As Long dmReserved2 As Long ' The following only appear in Windows 2000 dmPanningWidth As Long dmPanningHeight As Long End Type Public Declare Function EnumDisplaySettings Lib "user32.Print ". retval = EnumDisplaySettings(vbNullString.Print ".Height (Pixels):".26. _ ByVal iModeNum As Long.Width (Pixels): ".dmSize = Len(dm) ' Get the display settings for the current monitor and mode. dm.Bits Per Pixel: ".

92/vbapi/ref/e/enumdisplaysettings.html http://216. Copyright Information Revised October 29.vbapi. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: EnumDisplaySettings Function Devices Back to the Function list.168. Last Modified: January 21.26. 2001 This page is copyright © 2001 Paul Kuliniewicz.html (4 of 4) [9/1/2002 5:17:30 PM] . Back to the Reference section.com/ref/e/enumdisplaysettings. E-mail: vbapi@vbapi.

use EnumFontFamiliesEx instead.1 or later but Obsolete under Windows NT 4. The enumerated fonts are individually passed to a callback function for processing.92/vbapi/ref/e/enumfontfamilies.html (1 of 3) [9/1/2002 5:17:35 PM] .com | www. Windows 98: Supported but Obsolete. Return Value The function returns whatever the final call to the callback function returned. http://216.168.Windows API Guide: EnumFontFamilies Function vbapi. Parameters hdc A handle to a device context to the device to enumerate the fonts of. use EnumFontFamiliesEx instead. ByVal lpEnumFontFamProc As Long. Windows 2000: Supported but Obsolete. ByVal lpszFamily As Any.com .vbsquare. lpEnumFontFamProc A pointer to the EnumFontFamProc callback function which processes the information about each font that is enumerated. The only trait that the function looks for in the enumerated fonts is that it uses the specified typeface. lpszFamily The name of the font typeface which the enumerated fonts must use. use EnumFontFamiliesEx instead.part of the VB-World Network | www.vbforums.com | www. To instead enumerate a single font from each possible typeface. Windows NT: Requires Windows NT 3. the expression CLng(0) must be used. Visual Basic-Specific Issues When passing 0 as lpszFamily.com | www.vbapi. Description & Usage EnumFontFamilies enumerates all of the fonts available for use on a device which use a certain typeface. ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported but Obsolete.vbworld.com | www.dll" Alias "EnumFontFamiliesA" (ByVal hdc As Long.26. Windows CE: Not Supported.vbshop.com | EnumFontFamilies Function Declare Function EnumFontFamilies Lib "gdi32. pass 0 for this parameter (not an empty string!). use EnumFontFamiliesEx instead.0 or later.

Len(ntm) ' Display the name of the font (removing empty space from it). ByVal lpntm As Long. Debug. InStr(elf. ' Enumerate some of the fonts available for window Form1. Debug. *** ' The following callback function processes the enumerated fonts. Public Function EnumFontFamProc (ByVal lpelf As Long. CopyMemory elf. Else ' Copy the text metrics into the appropriate structure. ' Display whether the font is a device or a raster font.92/vbapi/ref/e/enumfontfamilies. Debug.Print " (Raster font)" http://216.lfFaceName. Len(tm) ' Display the name of the font (removing empty space from it). ntm.tmMaxCharWidth ' If the font is not TrueType. InStr(elf.1). use the following code. CopyMemory ntm.26. Debug.Print "Font Name: ". ByVal lpntm.168.elfStyle.1). ' *** Place the following code in a module.Print "Font Style: ".Print " (Device font)" ElseIf FontType = RASTER_FONTTYPE Then Debug.elfFullName.Print " (TrueType font)" ' Display the style of the font (again removing empty space).elfFullName.html (2 of 3) [9/1/2002 5:17:35 PM] . InStr(elf.Print "Average Character Width:". Debug. Debug. If (FontType And TRUETYPE_FONTTYPE) = TRUETYPE_FONTTYPE Then ' Copy the text metrics into the appropriate structure.tmAveCharWidth ' Display the maximum character width.Print "Maximum Character Width:". vbNullChar) .lfFaceName. ' These fonts must have the Times New Roman typeface. vbNullChar) . Example ' This code is licensed according to the terms and conditions listed here. ByVal lParam As Long) As Long Dim elf As ENUMLOGFONT ' receives information about the font Dim ntm As NEWTEXTMETRIC ' receives text metrics for TrueType fonts Dim tm As TEXTMETRIC ' receives text metrics for non-TrueType fonts ' Copy the font information into the appropriate structure.Print "Font Name: ". ' Display some information about each font as it is enumerated. ByVal lpelf.elfLogFont. Len(elf) ' If the font is TrueType. Debug.Print Left(elf. If FontType = DEVICE_FONTTYPE Then Debug.elfLogFont. use the following code. ntm. vbNullChar) 1) ' Display the average character width. ByVal lpntm. Left(elf.Windows API Guide: EnumFontFamilies Function lParam A value to pass to the function specified by lpEnumFontFamProc. ByVal FontType As Long.elfStyle. Left(elf. CopyMemory tm.

Windows API Guide: EnumFontFamilies Function End If Debug. AddressOf EnumFontFamProc. Debug. *** Dim retval As Long ' return value ' Enumerate all the fonts with the Times New Roman ' typeface which are available on Form1.com/ref/e/enumfontfamilies.vbapi." ' Display the average character width.tmAveCharWidth ' Display the maximum character width. 1999 This page is copyright © 1999 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page.Print "Enumeration complete." See Also EnumFontFamiliesEx Category Fonts & Text Go back to the alphabetical Function listing. Last Modified: October 29. Copyright Information Revised October 29.92/vbapi/ref/e/enumfontfamilies.hDC. Go back to the Reference section index. 0) Debug. tm. retval = EnumFontFamilies(Form1.168.Print "***" ' separator ' Tell EnumFontFamilies to continue enumeration.html http://216.Print "Maximum Character Width:". EnumFontFamProc = 1 End Function ' *** Place this code wherever you want the enumerate the fonts.26.com Send Encrypted E-Mail This page is at http://www. tm.Print "Average Character Width:". "Times New Roman".tmMaxCharWidth End If Debug.Print "Font Style does not apply for this font. E-mail: vbapi@vbapi. Debug.html (3 of 3) [9/1/2002 5:17:35 PM] .

com . ByVal dwFlags As Long) As Long Platforms q q q q q Windows 95: Supported. Return Value The function returns whatever the final call to the callback function returned. lpEnumFontFamExProc A pointer to the EnumFontFamExProc callback function which processes the information about each font that is http://216.lfPitchAndFamily member is not used but must be zero.com | www.html (1 of 3) [9/1/2002 5:17:40 PM] .com | www. Description & Usage EnumFontFamiliesEx enumerates all of the fonts available for use on a device which match a basic description.vbapi. The . or DEFAULT_CHARSET to ignore the character set.lfFaceName member identifies the typeface name of the fonts to enumerate. Windows 98: Supported.com | www. or an empty string to ignore the typeface name. Times New Roman with the ANSI character set is considered a different font than Times New Roman with the Cyrillic character set). The fonts are not enumerated in any obvious order. Windows NT: Requires Windows NT 4.92/vbapi/ref/e/enumfontfamiliesex. All other members are ignored. ByVal lParam As Long.vbsquare. lpLogfont Identifies the character set and/or typeface name (or neither) of the fonts to enumerate. ByVal lpEnumFontFamExProc As Long. lpLogfont As LOGFONT.com | www.168. The function enumerates fonts based on their character sets and/or typeface styles (or simply all fonts).vb-shop. The .com | EnumFontFamiliesEx Function Declare Function EnumFontFamiliesEx Lib "gdi32. The function treats identical fonts with different character sets as two different fonts (for example.vbforums.0 or later.26.lfCharset member identifies the character set of the fonts to enumerate. Windows 2000: Supported. Parameters hdc A handle to a device context to the device to enumerate the available fonts of. Visual Basic-Specific Issues None.Windows API Guide: EnumFontFamiliesEx Function vbapi.dll" Alias "EnumFontFamiliesExA" (ByVal hdc As Long. The .part of the VB-World Network | www. Windows CE: Not Supported.vbworld.

Len(ntmx) ' Display the name of the font (removing empty space from it).Print "Font Name: ". Debug. InStr(elfx.elfFullName. Else ' Copy the text metrics into the appropriate structure. If (FontType And TRUETYPE_FONTTYPE) = TRUETYPE_FONTTYPE Then ' Copy the text metrics into the appropriate structure. ByVal lpntme. CopyMemory elfx. vbNullChar) 1) ' Display the average character width.Print "Font Name: ". Example ' This code is licensed according to the terms and conditions listed here. Debug.1).1). Debug.168. Debug.Print "Maximum Character Width:".Print "Font Style: ".Print "Average Character Width:". Left(elfx. CopyMemory tm. vbNullChar) . ntmx. Debug.lfFaceName. Debug. ' Display whether the font is a device or a raster font. ' ' ' ' Enumerate some of the fonts available for window Form1.elfStyle. use the following code. ntmx.26. ' *** Place the following code in a module.elfLogFont. ByVal lpelfe. Left(elfx.elfLogFont.ntmTm.Windows API Guide: EnumFontFamiliesEx Function enumerated. CopyMemory ntmx. Len(elfx) ' If the font is TrueType.html (2 of 3) [9/1/2002 5:17:40 PM] . InStr(elfx. ByVal lpntme. These fonts must have the ANSI character set and have the Times New Roman typeface. Len(tm) ' Display the name of the font (removing empty space from it).ntmTm. dwFlags Reserved -. InStr(elfx. Public Function EnumFontFamExProc (ByVal lpelfe As Long. Display some information about each font as it is enumerated. ByVal lParam As Long) As Long Dim elfx As ENUMLOGFONTEX ' receives information about the font Dim ntmx As NEWTEXTMETRICEX ' receives text metrics for TrueType fonts Dim tm As TEXTMETRIC ' receives text metrics for non-TrueType fonts ' Copy the font information into the appropriate structure. Debug. ByVal lpntme As Long. *** ' The following callback function processes the enumerated fonts.tmMaxCharWidth ' If the font is not TrueType. If FontType = DEVICE_FONTTYPE Then http://216.set to 0. use the following code. ByVal FontType As Long.tmAveCharWidth ' Display the maximum character width.92/vbapi/ref/e/enumfontfamiliesex.elfStyle. lParam A value to pass to the function identified by lpEnumFontFamExProc.Print Left(elfx. vbNullChar) .Print " (TrueType font)" ' Display the style of the font (again removing empty space).elfFullName.lfFaceName.

0) Debug. retval = EnumFontFamiliesEx(Form1.lfPitchAndFamily = 0 ' this must be 0 ' Enumerate such fonts available on window Form1. Debug. *** Dim lf As LOGFONT ' describes enumeration attributes Dim retval As Long ' return value ' Initialize the structure to describe the fonts we want.tmMaxCharWidth End If Debug.Print "***" ' separator ' Tell EnumFontFamiliesEx to continue enumeration.com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29. AddressOf EnumFontFamExProc. lf.Print " (Device font)" ElseIf FontType = RASTER_FONTTYPE Then Debug." ' Display the average character width.168. Debug.tmAveCharWidth ' Display the maximum character width.Print "Enumeration complete.lfFaceName = "Times New Roman" & vbNullChar ' fonts with the Times New Roman typeface lf.26.html (3 of 3) [9/1/2002 5:17:40 PM] .92/vbapi/ref/e/enumfontfamiliesex.vbapi.com/ref/e/enumfontfamiliesex. tm.Print "Average Character Width:".html http://216.lfCharset = ANSI_CHARSET ' fonts with the ANSI character set lf. EnumFontFamExProc = 1 End Function ' *** Place this code wherever you want the enumerate the fonts.hDC. E-mail: vbapi@vbapi. tm. 2000 Go back to the Windows API Guide home page.Print "Font Style does not apply for this font.Windows API Guide: EnumFontFamiliesEx Function Debug." See Also EnumFontFamilies Category Fonts & Text Go back to the alphabetical Function listing. lf. Go back to the Reference section index.Print "Maximum Character Width:".Print " (Raster font)" End If Debug. 0. Last Modified: October 23. 1999 This page is copyright © 1999 Paul Kuliniewicz.

Windows NT: Requires Windows NT 3. the function returns a non-zero value.92/vbapi/ref/e/enumjobs. numeric data members can be copied directly from the array to the structure. ByVal cbBuf As Long. ByVal NoJobs As Long.vbsquare. Return Value If an error occured.com | www. Instead.com | EnumJobs Function Declare Function EnumJobs Lib "winspool. ByVal FirstJob As Long. Windows 98: Supported. If successful. http://216. Instead. and one structure immediately follows another. However. The array's contents must then be transfered to one or more structures.Windows API Guide: EnumJobs Function vbapi. Description & Usage EnumJobs enumerates all of the print jobs pending for a given printer. instead of placing the information directly into the corresponding structures. See the example code for a demonstration on how this is done. ByVal Level As Long. strings are not stored directly. see the example for a clearer demonstration.vbworld.html (1 of 4) [9/1/2002 5:17:44 PM] .com | www. Of course. Windows 2000: Supported. each (desired) member of the structure must manually be copied from the array to the structure. the function places the information into an array. The function can retrieve either (relatively) brief or detailed information describing each job in the print queue for that printer.com | www.drv" Alias "EnumJobsA" (ByVal hPrinter As Long. Note that. pcReturned As Long) As Long Platforms q q q q q Windows 95: Supported.vbforums. In order to determine how much space is necessary to receive the information about each print job.26. pJob As Long. CopyMemory can be used. The string manipulation API functions lstrlen and lstrcpy are needed to copy the pointed-to string into the structure's string data member(s).part of the VB-World Network | www. Windows CE: Not Supported. Each structure's contents appear sequentially in the array.vbshop. Visual Basic-Specific Issues The data retrieved by the function cannot be directly copied into structure(s) using CopyMemory or some other method. The function will set the variable passed as pcbNeeded to the size in bytes of the array necessary hold the information. Again. pcbNeeded As Long. the data placed into the array contains pointers to strings whenever necessary.168. using the corresponding array indices.vbapi.com | www. to copy structures stored under the original structure. the function returns 0 (use GetLastError to get the error code). first call the function with cbBuf set to 0.com . Additionally.1 or later.

Parameters hPrinter A handle to the printer to enumerate the print jobs of. the data is in the format of JOB_INFO_1 structures.168.92/vbapi/ref/e/enumjobs.html (2 of 4) [9/1/2002 5:17:44 PM] . If the function failed. http://216. Level Identifies the format of the information placed into the array passed as pJob. 1. pcReturned Receives the number of print jobs retrieved by the function. To set pJob to 0. 0.26. FirstJob The zero-baded position in the print queue to begin print job enumeration from. To enumerate everything except the first job. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. the data is in the format of JOB_INFO_2 structures. The format of this data is specified in Level. this must also be 0. ' Display a little information about each print job in the ' queue for the default printer. set this to 0. If you are setting cbBuf to 0.Windows API Guide: EnumJobs Function Finally. set this to 1 (identifying the second print job). NoJobs The maximum number of print jobs to enumerate. If this is 1. ByVal 0. To determine how large the array must be. The array must be large enough to receive all the data. needed. numitems) ' Resize the array buffer to the needed size in bytes.Get the name of the default printer. etc. both pJob and cbBuf must be set to 0. pJob An array which receives all the information about the print jobs retrieved by the function. Example ' This code is licensed according to the terms and conditions listed here. Note how both EnumPrinters and ' EnumJobs first copy the data into the arrays before placing ' the information into the desired structure. -' Determine how much space is needed to get the printer information. when determining the space needed for the array. pcbNeeded Receives the number of bytes of data copied into the array passed as pJob. To enumerate all jobs. the expression ByVal 0 must be used. cbBuf The size in bytes of the array passed as pJob. of course set this to 0. If this is 2. "". this is the minimum size in bytes which the array passed as pJob must be. Dim pi1 As PRINTER_INFO_1 ' holds a little information about the printer Dim hPrinter As Long ' handle to the default printer once it is opened Dim arraybuf() As Long ' resizable array used as a buffer Dim jobinfo As JOB_INFO_2 ' holds detailed info about a print job Dim needed As Long ' receives space needed in the buffer array Dim numitems As Long ' receives the number of items returned Dim lendivfour As Long ' the size in Long-type units of the jobinfo structure Dim c As Long ' counter variable Dim retval As Long ' return value ' -.

Print "There are".wYear.Print "Number of pages:". needed.wMonth. 100. arraybuf(lendivfour * c + 20).JobID = arraybuf(lendivfour * c) ' the first element of the array chunk jobinfo.Obtain a handle to the default printer (using default configuration).Print "No print jobs are currently in the queue.wSecond.Print "Printed by user: ". jobinfo.html (3 of 4) [9/1/2002 5:17:44 PM] . jobinfo. If numitems > 0 Then Debug. ":". hPrinter.Submitted.1) ' remember each element is 4 bytes ' Retrieve the information about the default printer. numitems) ' Display the number of print jobs currently in the queue. arraybuf(2)) ' -." End If ' For each print job. -' Determine how much space is needed to get the print jobs' information.Submitted. needed. 0. needed.pUserName = Space(lstrlen(arraybuf(lendivfour * c + 3))) ' fourth element retval = lstrcpy(jobinfo. copy its data into the structure.Submitted. lendivfour = Len(jobinfo) / 4 ' this is the number of elements for each structure in the array For c = 0 To numitems .wHour. The rest is unnecessary. this example copies only a ' few of the data members into the structure. 100.pUserName Debug. jobinfo. pi1.wDay. needed. the ' name of the user who printed it." Else Debug. "".pName.Print "Job ID number:". ByVal 0. and ' the time it was added into the queue. retval = EnumJobs(hPrinter.wMinute.Windows API Guide: EnumJobs Function ReDim arraybuf(0 To needed / 4 .1) ' remember each element is 4 bytes ' Retrieve the information about the print jobs. numitems) ' Resize the array buffer to the needed size in bytes.Submitted) ' twenty-first element ' Display the copied information. "print jobs currently in the queue. Debug.pName = Space(lstrlen(arraybuf(2))) retval = lstrcpy(pi1. Len(jobinfo.168. numitems. 0.Print jobinfo.Enumerate the default printer's print jobs currently queued. jobinfo.Submitted. ReDim arraybuf(0 To needed / 4 .pName. needed.Print jobinfo. For brevity. 2. ":". "-".pUserName.JobID Debug. jobinfo.1 ' loop through each item ' Copy selected information into the structure: the job ID number.TotalPages Debug. 2. ByVal CLng(0)) ' -.Submitted. 0. jobinfo. arraybuf(0). arraybuf(0).92/vbapi/ref/e/enumjobs. numitems) ' Copy the printer name into the structure. the total number of pages. jobinfo. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. arraybuf(lendivfour * c + 3)) jobinfo.Submitted. " ". -retval = OpenPrinter(pi1. Then display selected ' information from the structure. ' (display the date and time stored in jobinfo.Print "Placed in queue on: ". jobinfo.Submitted) Debug. " GMT" Next c http://216. Debug.TotalPages = arraybuf(lendivfour * c + 18) ' nineteenth element CopyMemory jobinfo.Submitted. "-".26. 1. retval = EnumJobs(hPrinter.

2000 Go back to the Windows API Guide home page. 1999 This page is copyright © 1999 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29.com/ref/e/enumjobs.92/vbapi/ref/e/enumjobs.vbapi.Windows API Guide: EnumJobs Function ' Close the printer handle now that it is no longer needed.html (4 of 4) [9/1/2002 5:17:44 PM] .168.26.html http://216. E-mail: vbapi@vbapi. Last Modified: November 24. retval = ClosePrinter(hPrinter) Category Printers Go back to the alphabetical Function listing. Go back to the Reference section index.

Again. pcReturned As Long) As Long Platforms: Win 95/98.com .26. Under Win NT. flags One or more of the following flags specifying which printers to find information about (note that PRINTER_ENUM_LOCAL and PRINTER_ENUM_CONNECTIONS are the only valid flags when using PRINTER_INFO_4): PRINTER_ENUM_CONNECTIONS = &H4 Win NT only: Get information about the network printers which the computer has made connections to. PRINTER_INFO_2. PRINTER_ENUM_SHARED = &H20 Get information about all the printers with the shared attribute. variants of the lstrcpy and lstrlen function must be used. The function returns 1 if successful. or PRINTER_INFO_4 structure. PRINTER_ENUM_REMOTE = &H10 Win NT only: Same as PRINTER_ENUM_NETWORK.com | www. or 0 if an error occured. PRINTER_INFO_2. name http://216. Look at the two examples for details how. Instead.the array must be of Long-type elements. which can then be copied into an array of data structures. Note for Visual Basic users: Due to limitations in the Visual Basic language. see the examples.part of the VB-World Network | www. PRINTER_ENUM_LOCAL = &H2 Get information about local printers (the ones directly connected to the system).vbshop.com | www.vbapi. PRINTER_ENUM_DEFAULT = &H1 Win 95/98 only: Get information about the computer's default printer. it is impossible to pass an array of PRINTER_INFO_* structures as pPrinterEnum -. ByVal Level As Long. These include both local printers (physically connected to the machine) and network printers (accessible via the network). pPrinterEnum As Long.92/vbapi/ref/e/enumprinters. In order to convert a Long-type string pointer (in the array) to a string. The information itself is put into the array passed as pPrinterEnum. Win 95/98 for some reason also considers network printers to be local. CopyMemory. the information can be passed in a PRINTER_INFO_1. ByVal cdBuf As Long. pcbNeeded As Long.com | www. PRINTER_ENUM_NETWORK = &H40 Win NT only: Get information about all the printers under the computer's domain in the network.Windows API Guide: EnumPrinters Function vbapi.com | EnumPrinters Function Declare Function EnumPrinters Lib "winspool. Also. Win NT EnumPrinters finds and returns information about one or more printers which the computer has access to.vbforums. PRINTER_ENUM_NAME = &H8 Get information about all the printers under the network domain specified by name. each individual member of the data structure must be set manually. can be used to copy the data structures which make up parts of the PRINTER_INFO_2 data structure.vbworld.drv" Alias "EnumPrintersA" (ByVal flags As Long. the information can be passed in a PRINTER_INFO_1. This only works with the PRINTER_INFO_1 structure.vbsquare. or PRINTER_INFO_5 structure. ByVal name As String. Note that structures 4 and 5 are the quickest ones to use. however.com | www. for some reason the CopyMemory function cannot be used to successfully transfer the array information into the structure.168.html (1 of 5) [9/1/2002 5:18:04 PM] . Under Win 95/98. The attributes of the chosen structure determine what kinds of information about the printer(s) is returned.

ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32. numbytes.92/vbapi/ref/e/enumprinters. pcReturned Receives the number of printers found by the function.dll" Alias "lstrcpyA" (ByVal lpString1 As String.note how 1 Long = 4 bytes retval = EnumPrinters(PRINTER_ENUM_LOCAL. "". or 4. Level Specifies which PRINTER_INFO_* structure to use. but it may not be ReDim longbuffer(0 To numbytes / 4) As Long ' resize array -. pPrinterEnum An array which receives all of the information found by the function. numneeded.26. set this parameter to an empty string. numprinters) If retval = 0 Then ' try enlarging longbuffer() to receive all necessary information numbytes = numneeded ReDim longbuffer(0 To numbytes / 4) As Long ' make it large enough retval = EnumPrinters(PRINTER_ENUM_LOCAL. pcbNeeded If successful. 2. For Win 95/98. retval As Long ' counter variable & return value ' Get information about the local printers numbytes = 3076 ' should be sufficiently big. cdBuf The size in bytes of the array passed as pPrinterEnum.168. longbuffer(0). Also ' note how the following special declares must be used to allow numeric string pointers ' to be used in place of strings: Declare Function lstrcpy Lib "kernel32. If not used. Example #1: ' Get information about all of the local printers using structure 1. 2. For Win NT. See flags to see when this would be used.Print "Could not successfully enumerate the printes. numprinters) If retval = 0 ' failed again! Debug. or 5." End ' abort program End If http://216. if applicable. receives the number of bytes that pPrinterEnum must have in order to receive all of the information. numbytes.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long Dim longbuffer() As Long ' resizable array receives information from the function Dim printinfo() As PRINTER_INFO_1 ' values inside longbuffer() will be put into here Dim numbytes As Long ' size in bytes of longbuffer() Dim numneeded As Long ' receives number of bytes necessary if longbuffer() is too small Dim numprinters As Long ' receives number of printers found Dim c As Integer.Windows API Guide: EnumPrinters Function The name of the network domain to look under.html (2 of 5) [9/1/2002 5:18:04 PM] . 1. this can be 1. this can be 1. receives the number of bytes of information the function found. longbuffer(0). If unsuccessful. "". 1. This needs to be copied manually into the PRINTER_INFO_* structure. numneeded. Note how ' the elements of the array are loaded into an array of data structures manually.

flags = longbuffer(4 * c) printinfo(c).note how 1 Long = 4 bytes retval = EnumPrinters(PRINTER_ENUM_LOCAL.26. ByVal lpString2 As Long) As Long Declare Function lstrlen Lib "kernel32. longbuffer(4 * c + 3)) Next c ' Display name of each printer For c = 0 To numprinters . longbuffer(4 * c + 1)) printinfo(c). numbytes. but it may not be ReDim longbuffer(0 To numbytes / 4) As Long ' resize array -. putting each set of information into each element ' longbuffer(4 * c) = .flags. " is: ".168.dll" Alias "lstrcpyA" (ByVal lpString1 As String.1) As PRINTER_INFO_1 ' room for each printer For c = 0 To numprinters .Print "Name of printer". ' For each string.Windows API Guide: EnumPrinters Function End If ' Convert longbuffer() data into printinfo() ReDim printinfo(0 To numprinters .pDescription.pComment = Space(lstrlen(longbuffer(4 * c + 3))) retval = lstrcpy(printinfo(c). longbuffer(4 * c + 1) = .pDescription. numprinters) If retval = 0 Then ' try enlarging longbuffer() to receive all necessary information http://216.pName = Space(lstrlen(longbuffer(4 * c + 2))) retval = lstrcpy(printinfo(c). and then the string is copied. longbuffer(0).1 ' loop.pComment.html (3 of 5) [9/1/2002 5:18:04 PM] .pDescription = Space(lstrlen(longbuffer(4 * c + 1))) retval = lstrcpy(printinfo(c). numneeded. Also ' note how the following special declares must be used to allow numeric string pointers ' to be used in place of strings: Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long Dim longbuffer() As Long ' resizable array receives information from the function Dim printinfo() As PRINTER_INFO_2 ' values inside longbuffer() will be put into here Dim numbytes As Long ' size in bytes of longbuffer() Dim numneeded As Long ' receives number of bytes necessary if longbuffer() is too small Dim numprinters As Long ' receives number of printers found Dim c As Integer.pName Next c Example #2: ' Get information about all of the local printers using structure 2. c + 1. Note how ' the elements of the array are loaded into an array of data structures manually.1 Debug. 2. longbuffer(4 * c + 2)) printinfo(c). printinfo(c). printinfo(c). "". etc.92/vbapi/ref/e/enumprinters. retval As Long ' counter variable & return value ' Get information about the local printers numbytes = 3076 ' should be sufficiently big.pName. the string is first buffered to provide enough room.

" End ' abort program End If End If ' Convert longbuffer() data into printinfo() ReDim printinfo(0 To numprinters .pPrinterName.Windows API Guide: EnumPrinters Function numbytes = numneeded ReDim longbuffer(0 To numbytes / 4) As Long ' make it large enough retval = EnumPrinters(PRINTER_ENUM_LOCAL.pPrintProcessor = Space(lstrlen(longbuffer(21 * c + 9))) retval = lstrcpy(printinfo(c).pDevMode.pPrintProcessor. longbuffer(21 * c + 11)) CopyMemory printinfo(c).pServerName.pSecurityDescriptor) printinfo(c).Attributes = longbuffer(21 * c + 13) printinfo(c). longbuffer(21 * c + 5)) printinfo(c).pDevMode) printinfo(c).pDriverName.pLocation.pSepFile = Space(lstrlen(longbuffer(21 * c + 8))) retval = lstrcpy(printinfo(c).pComment.pComment = Space(lstrlen(longbuffer(21 * c + 5))) retval = lstrcpy(printinfo(c). numneeded. longbuffer(21 * c + 2)) printinfo(c). the memory of it is directly copied via CopyMemory using the pointer.pLocation = Space(lstrlen(longbuffer(21 * c + 6))) retval = lstrcpy(printinfo(c). printinfo(c).92/vbapi/ref/e/enumprinters. longbuffer(21 * c + 4)) printinfo(c).1) As PRINTER_INFO_2 ' room for each printer For c = 0 To numprinters . longbuffer(21 * c + 6)) CopyMemory printinfo(c).pDatatype.Priority = longbuffer(21 * c + 14) printinfo(c). longbuffer(21 * c + 9)) printinfo(c). numprinters) If retval = 0 ' failed again! Debug.pParameters.pServerName. putting each set of information into each element ' longbuffer(21 * c) = . longbuffer(21 * c + 8)) printinfo(c).pDriverName = Space(lstrlen(longbuffer(21 * c + 4))) retval = lstrcpy(printinfo(c).pParameters = Space(lstrlen(longbuffer(21 * c + 11))) retval = lstrcpy(printinfo(c). Len(printinfo(c). longbuffer(21 * c + 1) = . the string is first buffered to provide enough room.pPrinterName.Print "Could not successfully enumerate the printes. longbuffer(0).pShareName.pPortName = Space(lstrlen(longbuffer(21 * c + 3))) retval = lstrcpy(printinfo(c). and then the string is copied. Len(printinfo(c). longbuffer(21 * c + 3)) printinfo(c). longbuffer(21 * c + 10)) printinfo(c). "". longbuffer(21 * c + 1)) printinfo(c). ' For each string.pServerName = Space(lstrlen(longbuffer(21 * c))) retval = lstrcpy(printinfo(c).26. etc.DefaultPriority = longbuffer(21 * c + 15) printinfo(c). longbuffer(21 * c + 12).pShareName = Space(lstrlen(longbuffer(21 * c + 2))) retval = lstrcpy(printinfo(c).pSepFile. ' For each structure. longbuffer(21 * c)) printinfo(c).pSecurityDescriptor.pPrinterName = Space(lstrlen(longbuffer(21 * c + 1))) retval = lstrcpy(printinfo(c).168.html (4 of 5) [9/1/2002 5:18:04 PM] .StartTime = longbuffer(21 * c + 16) http://216.1 ' loop.pPortName. longbuffer(21 * c + 7).pDatatype = Space(lstrlen(longbuffer(21 * c + 10))) retval = lstrcpy(printinfo(c). 2. numbytes.

Print printinfo(c).cJobs = longbuffer(21 * c + 19) printinfo(c). This page is copyright © 2000 Paul Kuliniewicz. " prints an average of".com Send Encrypted E-Mail This page is at http://www.AveragePPM = longbuffer(21 * c + 20) Next c ' Display the name of each printer and its average page per minute (ppm) rate For c = 0 To numprinters . Go back to the Windows API Guide home page.html (5 of 5) [9/1/2002 5:18:04 PM] .UntilTime = longbuffer(21 * c + 17) printinfo(c). "pages per minute.html http://216.1 Debug.92/vbapi/ref/e/enumprinters. printinfo(c). E-mail: vbapi@vbapi.pPrinterName. Copyright Information.com/ref/e/enumprinters.Status = longbuffer(21 * c + 18) printinfo(c).26. Go back to the Reference section index.vbapi." Next c Category: Printers Go back to the alphabetical Function listing.Windows API Guide: EnumPrinters Function printinfo(c).168.AveragePPM.

The window properties are not enumerated in any particular order.com | www.26.92/vbapi/ref/e/enumpropsex. http://216. Windows NT: Requires Windows NT 3.html vbapi. to the specified callback function. Information about each property is passed.dll" Alias "EnumPropsExA" (ByVal hWnd As Long.1 or later.com | www. Windows CE: Not Supported. Parameters hWnd A handle to the window to enumerate the window properties of.92/vbapi/ref/e/enumpropsex. Otherwise.html (1 of 3) [9/1/2002 5:18:07 PM] .vbworld.com | www. Windows 2000: Supported.vbforums.http://216. Return Value If the window had no window properties set.com . one at a time.vbsquare. Windows 98: Supported.part of the VB-World Network | www.vbapi.26. ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns -1.com | EnumPropsEx Function Declare Function EnumPropsEx Lib "user32. Visual Basic-Specific Issues None.vbshop. lParam An additional value to pass to the function specified by lpEnumFunc.168. lpEnumFunc A pointer to the PropEnumProcEx callback function which receives information about each enumerated window property. the function returns whatever the most recent value the callback function returned was. ByVal lpEnumFunc As Long.com | www. Description & Usage EnumPropsEx enumerates all of the window properties of a window.168.

92/vbapi/ref/e/enumpropsex. ByVal lpszString As Long. retval = EnumPropsEx(Form1. 0) If retval = -1 Then ' no properties to enumerate Debug.92/vbapi/ref/e/enumpropsex.26. Last Modified: December 24. ByVal hData As Long. ' *** Place the following code in a module. propname = Space(lstrlen(lpszString)) retval = lstrcpy(propname. PropEnumProcEx = 1 End Function ' *** Place the following code wherever you wish to enumerate the properties.". Debug. *** ' This callback function merely displays the name of the window property ' it is given. ' ' ' ' List the names of each window property belonging to window Form1.Print "(no window properties were found)" End If Category Window Properties Go back to the alphabetical Function listing.hWnd. Public Function PropEnumProcEx(ByVal hwnd As Long. Go back to the Reference section index. 1999 This page is copyright © 1999 Paul Kuliniewicz. propname ' Tell EnumPropsEx to continue enumeration.168. Dim retval As Long ' result of enumeration Debug.Print "BEGINNING ENUMERATION OF Form1's PROPERTIES" ' Enumerate the properties of window Form1. lpszString) ' Display the property name (not including its value).168. AddressOf PropEnumProcEx. This example does not display the actual data in the properties because the callback function is not told what the handle for each property refers to. ByVal dwData As Long) As Long Dim propname As String ' receives the name of the window property Dim retval As Long ' generic return value ' Copy the string pointed to by lpString into a "real" string.http://216.html Example ' This code is licensed according to the terms and conditions listed here. 2000 http://216.html (2 of 3) [9/1/2002 5:18:07 PM] .26.Print ". Copyright Information Revised October 29.

com Send Encrypted E-Mail This page is at http://www.168.26.html Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.http://216.92/vbapi/ref/e/enumpropsex.html (3 of 3) [9/1/2002 5:18:07 PM] .26.html http://216.168.vbapi.92/vbapi/ref/e/enumpropsex.com/ref/e/enumpropsex.

ByVal lpfn As Long. or until the process has been aborted.26. Example http://216.1 or later.vbforums. Windows 98: Supported.html (1 of 3) [9/1/2002 5:18:13 PM] . lParam An additional value to pass to the application-defined callback function. the function returns a nonzero value.com | www.dll" (ByVal dwThreadId As Long. Return Value If an error occured.vbsquare. The function continues doing so until all windows have been enumerated. lpfn A pointer to the application-defined callback function EnumThreadWndProc. Windows NT: Requires Windows NT 3.vbworld.part of the VB-World Network | www.168. the function passes that handle to an application-defined callback function. Parameters dwThreadId An identifier to the thread to enumerate the windows of. Windows 2000: Supported.92/vbapi/ref/e/enumthreadwindows.com | EnumThreadWindows Function Declare Function EnumThreadWindows Lib "user32.) Each time a window is located. Description & Usage EnumThreadWindows enumerates and provides handles to all of the windows owned and controlled by a given thread.com .com | www.com | www. the function returns 0 (use GetLastError to get the error code).vbapi. Visual Basic-Specific Issues None.com | www. ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported. Windows CE: Not Supported.Windows API Guide: EnumThreadWindows Function vbapi. If successful.vbshop. (Note that these windows include many windows not visible to the user.

winnum.Print "Window #".html (2 of 3) [9/1/2002 5:18:13 PM] . threadid = GetWindowThreadProcessId(Form1. ' display number of enumerated window Debug.Print Left(buffer. *** ' This function displays the title bar text of the window identified by hwnd. AddressOf EnumThreadWndProc. which will receive each handle individually.26. This task is given to the callback function.168.. slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text If slength > 1 ' if return value refers to non-empty string buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd. wintext As String ' title bar text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated. *** Dim threadid As Long. ' ' ' ' Display the window title of all windows controlled by the thread which the window Form1 is in. EnumWindows Category Windows http://216. slength . processid) ' Use the callback function to list all of the enumerated thrad windows.hWnd. slength) ' get title bar text Debug. Note that lParam ' is set to 0 because we don't need to pass any additional information to the function. " : ". it will not be displayed (for clarity's sake). ' *** Place this code in a module.92/vbapi/ref/e/enumthreadwindows.. retval = EnumThreadWindows(threadid. buffer. 0) See Also EnumChildWindows. ByVal lParam As Long) As Long Dim slength As Long. This is the callback function.1) ' display title bar text of enumerated window End If EnumThreadWndProc = 1 End Function ' return value of 1 means continue enumeration ' *** Place this code wherever you want to enumerate the windows.Windows API Guide: EnumThreadWindows Function ' This code is licensed according to the terms and conditions listed here. Public Function EnumThreadWndProc (ByVal hwnd As Long. processid As Long ' receive id to thread and process of Form1 Dim retval As Long ' return value ' Determine the thread which owns the window Form1. Note that if the window has no title bar text..

html (3 of 3) [9/1/2002 5:18:13 PM] .html http://216. E-mail: vbapi@vbapi.com/ref/e/enumthreadwindows.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/e/enumthreadwindows. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page.168.Windows API Guide: EnumThreadWindows Function Go back to the alphabetical Function listing. Last Modified: August 15.26. 1999 This page is copyright © 1999 Paul Kuliniewicz.vbapi. Go back to the Reference section index.

com | www.vbsquare.1 or later. Windows NT: Requires Windows NT 3. Windows 2000: Supported.168.vbshop. Windows CE: Requires Windows CE 1.com | EnumWindows Function Declare Function EnumWindows Lib "user32.com | www. or until the process has been aborted.0 or later. The function continues doing so until all windows have been enumerated. http://216. Description & Usage EnumWindows enumerates and provides handles to all of the currently open top-level windows.com | www. the function returns a nonzero value. ByVal lParam As Long) As Long Platforms q q q q q Windows 95: Supported. the function passes that handle to an application-defined callback function. Return Value If an error occured.com | www. Visual Basic-Specific Issues None. Windows 98: Supported.vbforums.26.html (1 of 3) [9/1/2002 5:18:26 PM] This . Example: ' Display the title bar text of all top-level windows. If successful. This function will ignore child windows.vbapi.vbworld.) Each time a window is located. Parameters lpEnumFunc A pointer to the application-defined callback function EnumWindowsProc.Windows API Guide: EnumWindows Function vbapi.dll" (ByVal lpEnumFunc As Long. (Note that the top-level windows include many windows not visible to the user.com .part of the VB-World Network | www. the function returns 0 (use GetLastError to get the error code).92/vbapi/ref/e/enumwindows. lParam An additional value to pass to the application-defined callback function.

' display number of enumerated window Debug. *** Dim retval As Long ' return value ' Use the above callback function to list all of the enumerated windows.Windows API Guide: EnumWindows Function ' task is given to the callback function.. Go back to the Reference section index. Public Function EnumWindowsProc (ByVal hwnd As Long. " : ". which will receive each handle individually. This is the callback function. slength . 2000 This page is copyright © 2000 Paul Kuliniewicz. Note that lParam is ' set to 0 because we don't need to pass any additional information to the function. ' Note that if the window has no title bar text.Print Left(buffer. retval = EnumWindows(AddressOf EnumWindowsProc. slength) ' get title bar text Debug.26. buffer As String ' title bar text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated. 2000 http://216.1) ' display title bar text of enumerated window End If EnumWindowsProc = 1 End Function ' return value of 1 means continue enumeration ' *** Place this code wherever you want to enumerate the windows. Last Modified: January 16.92/vbapi/ref/e/enumwindows.Print "Window #". *** ' This function displays the title bar text of the window identified by hwnd. buffer..168. it will not be displayed (for clarity's sake). 0) See Also EnumChildWindows.html (2 of 3) [9/1/2002 5:18:26 PM] . slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text If slength > 1 ' if return value refers to non-empty string buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd.. winnum. Copyright Information Revised October 29. ' *** Place this code in a module. EnumThreadWindows Category Windows Go back to the alphabetical Function listing. ByVal lParam As Long) As Long Dim slength As Long.

com Send Encrypted E-Mail This page is at http://www.vbapi.html (3 of 3) [9/1/2002 5:18:26 PM] .92/vbapi/ref/e/enumwindows.com/ref/e/enumwindows.html http://216.168.26.Windows API Guide: EnumWindows Function Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.

200. http://216.Print "Are Not Equal" ' Change the second rectangle retval = SetRect(s.vbworld. Win NT EqualRect determines if two rectangles are equal. See Also: CopyRect Category: Rectangles Go back to the alphabetical Function listing.html (1 of 2) [9/1/2002 5:18:31 PM] . Example: ' Demonstrate equal and unequal rectangles Dim r As RECT.vbforums.Print "Are Equal" Else Debug. 20.com | www.20)-(100. lpRect2 As RECT) As Long Platforms: Win 32s.110) areequal = EqualRect(r. 250) ' s = (30. 100.110) retval = SetRect(s.com | EqualRect Function Declare Function EqualRect Lib "user32. 110) ' r = (15. 110) ' s = (15.45)-(200. 15. 15.com | www. 30. Rectangles are considered equal if and only if the upper-left and lower-right corners (the points that define the rectangles) of one rectangle are equal to those of another. 100. lpRect1 The first of the two rectangles to check. s) ' compare the rectangles If areequal = 1 Then Debug. The function returns 1 if the two rectangles are equal and 0 if they are unequal.20)-(100.26. the second is Are Not Equal.vbapi.vb-shop.250) areequal = EqualRect(r.part of the VB-World Network | www.vbsquare.com | www.Print "Are Equal" Else Debug. 45.92/vbapi/ref/e/equalrect.dll" (lpRect1 As RECT.Windows API Guide: EqualRect Function vbapi. Win 95/98. 20. s As RECT ' rectangles to use Dim areequal As Long ' receives whether the rectangles are equal or not Dim retval As Long ' return value ' Initialize the two rectangles using the API retval = SetRect(r.168.com .com | www.Print "Are Not Equal" ' The first time is Are Equal. lpRect2 The second of the two rectangles to check. s) ' compare the rectangles If areequal = 1 Then Debug.

Copyright Information.26. Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:18:31 PM] .com/ref/e/equalrect.html http://216.168. E-mail: vbapi@vbapi. This page is copyright © 2000 Paul Kuliniewicz.vbapi.92/vbapi/ref/e/equalrect.Windows API Guide: EqualRect Function Go back to the Reference section index.com Send Encrypted E-Mail This page is at http://www.

they could still refer to regions of identical size. there has to be a command button named Command1 on that window. Visual Basic-Specific Issues None. Description & Usage EqualRgn determines if two regions contain the exact same area.com | www. Example Perform a simple illustration of equal and unequal regions. Although the region handles will of course be different. Return Value If the two regions are equal.vbworld. Besides showing how the function works. the function returns a non-zero value.vbapi. the function returns zero.0 or later. there's no practical value to this example.html (1 of 3) [9/1/2002 5:18:36 PM] .com .com | www.part of the VB-World Network | www. shape. Windows 98: Supported.92/vbapi/ref/e/equalrgn.com | EqualRgn Function Declare Function EqualRgn Lib "gdi32.com | www. If the two regions are different.26.Windows API Guide: EqualRgn Function vbapi. Windows NT: Requires Windows NT 3. Windows 2000: Supported.vbforums. hSrcRgn2 A handle to the second of the two regions to compare. naturally. The example runs when you click on command button Command1 in a form window. So.vbshop.168.com | www. Parameters hSrcRgn1 A handle to the first of the two regions to compare.vbsquare.dll" (ByVal hSrcRgn1 As Long.1 or later. and position. ByVal hSrcRgn2 As Long) As Long Platforms q q q q q Windows 95: Supported. http://216. Windows CE: Requires Windows CE 1.

) Public Declare Function EqualRgn Lib "gdi32. 200. 2000 This page is copyright © 2000 Paul Kuliniewicz. http://216. ByVal nBottomRect As Long) As Long Public Declare Function DeleteObject Lib "gdi32. _ ByVal nTopRect As Long.Print "Not Equal" Else Debug. 80) 50. 120. 150) ' Define all three regions as hRgn1 = CreateEllipticRgn(20. areequal = EqualRgn(hRgn1. Copyright Information.dll" (ByVal hSrcRgn1 As Long. ByVal hSrcRgn2 _ As Long) As Long Public Declare Function CreateEllipticRgn Lib "gdi32.Print "Not Equal" Else Debug. hRgn3) If areequal = 0 Then Debug.Windows API Guide: EqualRgn Function ' This code is licensed according to the terms and conditions listed here. areequal = EqualRgn(hRgn1. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. hRgn2 = CreateEllipticRgn(20. hRgn2 As Long. 120. hRgn3 = CreateEllipticRgn(50. DeleteObject(hRgn1) DeleteObject(hRgn2) DeleteObject(hRgn3) Category Regions Go back to the Function listing.dll" (ByVal hObject As Long) As Long ' *** Place the following code inside a form.Print "Equal" ' Compare regions 1 and 3 (they will not be equal). ' Compare regions 1 and 2 (they will be equal).26.92/vbapi/ref/e/equalrgn.168. 80) 30.Print "Equal" ' Delete retval = retval = retval = End Sub the three regions to free up resources.html (2 of 3) [9/1/2002 5:18:36 PM] . Go back to the Windows API Guide home page. hRgn3 As Long ' the three regions areequal As Long ' receives equal/unequal indicator retval As Long ' generic return value elliptical.dll" (ByVal nLeftRect As Long. *** Private Sub Dim Dim Dim Command1_Click() hRgn1 As Long. hRgn2) If areequal = 0 Then Debug. Last Modified: July 30. 30. ByVal nRightRect As Long. Go back to the Reference section index.

vbapi.com/ref/e/equalrgn.92/vbapi/ref/e/equalrgn.com Send Encrypted E-Mail This page is at http://www.26.html http://216.Windows API Guide: EqualRgn Function E-mail: vbapi@vbapi.168.html (3 of 3) [9/1/2002 5:18:36 PM] .

com | www.vbshop. or if the user simply cancelled it.92/vbapi/ref/e/exitwindowsdialog.part of the VB-World Network | www.Windows API Guide: ExitWindowsDialog Function vbapi. Description & Usage ExitWindowsDialog prompts the user with the "Shut Down Windows" dialog box.com . Return Value This function does not return a value. this function actually begins the shut down.vbsquare. Visual Basic-Specific Issues None. http://216. reboot. Windows NT: Requires Windows NT 3.dll" Alias "#60" (ByVal hwndOwner As Long) Platforms q q q q q Windows 95: Supported. Unlike most API dialogs. Windows 2000: Supported. or whatever other process the user selected. Example ' This code is licensed according to the terms and conditions listed here. Unfortunately. Windows 98: Supported.26.html (1 of 2) [9/1/2002 5:18:42 PM] . The ExitWindowsDialog function is officially undocumented. there is no way to know what the user chose in the dialog box.vbforums.com | www.vbworld.1 or later.com | ExitWindowsDialog Function Declare Sub ExitWindowsDialog Lib "shell32. Windows CE: Unknown.168.com | www.com | www.vbapi. Parameters hwndOwner A handle to the window that is opening the Shut Down dialog box. This is the same box as the one that appears when the user selects "Shut Down" from the Start menu.

Last Modified: July 4.dll" Alias "#60" (ByVal hwndOwner As Long) ' When the user clicks button Command1 on window Form1.html http://216.hWnd ' That's all it takes! End Sub See Also RestartDialog Category Shell Back to the Function list.html (2 of 2) [9/1/2002 5:18:42 PM] .vbapi.Windows API Guide: ExitWindowsDialog Function ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Sub ExitWindowsDialog Lib "shell32. Back to the Reference section.com/ref/e/exitwindowsdialog. Private Sub Command1_Click() ExitWindowsDialog Form1.92/vbapi/ref/e/exitwindowsdialog.com Send Encrypted E-Mail This page is at http://www. display the ' Shut Down Windows dialog box.168. 2000 Go back to the Windows API Guide home page. 2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi. Copyright Information Revised October 29.26.

since the shutdown/reboot process will begin once the function is called. 0) If retval = 0 Then Debug.168. or 1 if successful. EWX_SHUTDOWN = 1 Shut down the system.vbforums.part of the VB-World Network | www. Example: ' Reboot the computer. if possible.com | www.com | www.vbsquare.com | www.com | ExitWindowsEx Function Declare Function ExitWindowsEx Lib "user32. turn the computer off. dwReserved Reserved for future versions of Windows. The function returns 0 if an error occured.vbworld.dll" (ByVal uFlags As Long.com . EWX_LOGOFF = 0 Log off the network. Always set to 0.com | www. forcing any open programs to close Dim retval As Long ' return value retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE. EWX_REBOOT = 2 Perform a full reboot of the system.vb-shop." Category: Other http://216. ByVal dwReserved As Long) As Long Platforms: Win 95/98. EWX_POWEROFF = 8 Shut down the system and.vbapi.26.92/vbapi/ref/e/exitwindowsex. uFlags One or more of the following flags specifying how to shut down or reboot the computer: EWX_FORCE = 4 Force any applications to quit instead of prompting the user to close them.Print "Reboot attempt failed. Win NT ExitWindowsEx shuts down or reboots the user's computer.Windows API Guide: ExitWindowsEx Function vbapi.html (1 of 2) [9/1/2002 5:18:48 PM] . Of course. there won't normally be much left for your program to do.

html (2 of 2) [9/1/2002 5:18:48 PM] .26. E-mail: vbapi@vbapi. This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www. Go back to the Windows API Guide home page. Copyright Information.168.Windows API Guide: ExitWindowsEx Function Go back to the alphabetical Function listing. Go back to the Reference section index.com/ref/e/exitwindowsex.92/vbapi/ref/e/exitwindowsex.vbapi.html http://216.

part of the VB-World Network | www. the function returns a non-zero value. The flood fill begins at a single point and extends in all directions until a condition is met. crColor The RGB value of the color determining the extent of the flood fill operation. ByVal nYStart As Long. Its exact interpretation depends on the http://216. Windows 2000: Supported. nYStart The y-coordinate of the point to begin the flood fill at.com | www. ByVal fuFillType As Long) As Long Platforms q q q q q Windows 95: Supported.168. Windows CE: Not Supported.92/vbapi/ref/e/extfloodfill.vbapi. Windows 98: Supported. Windows NT: Requires Windows NT 3. Description & Usage ExtFloodFill performs a flood fill operation on a device using that device's currently selected brush. The flood fill can extend either until a certain boundary color is reached or while a certain color is being filled over. ByVal nXStart As Long.com .vbforums.vbshop. Return Value If an error occured.Windows API Guide: ExtFloodFill Function vbapi. Visual Basic-Specific Issues None. 2000: use GetLastError to get the error code).1 or later.com | www.vbsquare.com | ExtFloodFill Function Declare Function ExtFloodFill Lib "gdi32. If successful.vbworld.26. nXStart The x-coordinate of the point to begin the flood fill at.dll" (ByVal hdc As Long. ByVal crColor As Long.com | www. the function returns 0 (Windows NT.html (1 of 3) [9/1/2002 5:18:57 PM] . Parameters hdc A handle to a device context to the device to perform the flood fill on.com | www.

0.hDC. hBrush) ' Draw an ellipse with bounding rectangle (100. 255. 255.hDC. 255)) ' Select it for use in Form1. ' Draw a solid green ellipse on window Form1 and fill ' the area outside of it with a diagonally cross-hatched red brush. 25. hOldBrush) the pen and brush to free up resources. Dim hPen As Long. hOldBrush As Long ' handles to the previously selected objects Dim retval As Long ' return value ' Create a solid green pen with a width of one pixel. hPen = CreatePen(PS_SOLID.92/vbapi/ref/e/extfloodfill.Windows API Guide: ExtFloodFill Function flag passed as fuFillType. 150. DeleteObject(hPen) DeleteObject(hBrush) Category http://216. RGB(0.hDC.hDC. hBrush As Long ' handles to the pen and brush to be used Dim hOldPen As Long.hDC. Constant Definitions Const FLOODFILLBORDER = 0 Const FLOODFILLSURFACE = 1 Example ' This code is licensed according to the terms and conditions listed here. 0). retval = ExtFloodFill(Form1. FLOODFILLBORDER) ' Select retval = retval = ' Delete retval = retval = the previously selected pen and brush. 250) ' Flood fill the area outside the ellipse (use a green boundary) ' starting at the point (25. fuFillType One of the following flags specifying how to determine the boundary of the flood fill operation: FLOODFILLBORDER Fill from the beginning point in all directions until a boundary of color crColor is reached. 0. 0)) ' Select it for use in Form1.html (2 of 3) [9/1/2002 5:18:57 PM] . hOldBrush = SelectObject(Form1. 25. The flood fill will cover over any colors within the region which do not have the color of crColor. noting the previous brush. hOldPen) SelectObject(Form1. 350.168. hOldPen = SelectObject(Form1.hDC. hBrush = CreateHatchBrush(HS_DIAGCROSS. 100. hPen) ' Create a blue diagonally cross-hatched brush.30) outside the ellipse.26. 250) retval = Ellipse(Form1. FLOODFILLSURFACE Fill from the beginning point in all directions as long as the fill-in color crColor is encountered. The boundary of the flood fill is made up of any color which is not identical to crColor.150)-(350. noting the previous pen. RGB(0. SelectObject(Form1. RGB(0.

Last Modified: October 17.26.168.html (3 of 3) [9/1/2002 5:18:57 PM] .com/ref/e/extfloodfill.html http://216.92/vbapi/ref/e/extfloodfill. E-mail: vbapi@vbapi. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www. 1999 This page is copyright © 1999 Paul Kuliniewicz.Windows API Guide: ExtFloodFill Function Bitmaps Go back to the alphabetical Function listing. Go back to the Reference section index.vbapi.

html (1 of 3) [9/1/2002 5:19:04 PM] .Windows API Guide: ExtractIcon Function vbapi.com | www.dll). this function can also determine how many icons are stored in such a file. If the function succeeded and the number of icons in the file was requested. the function returns a handle to the extracted icon. If the function failed because the icon requested by the function did not exist. the function returns 1. ByVal lpszExeFileName As String. This file can be an executable (.com | www. Windows CE: Not Supported. Windows 2000: Supported. Windows NT: Requires Windows NT 3.vbsquare. the function returns 0.vb-shop.com | www.vbapi. lpszExeFileName http://216. Description & Usage ExtractIcon extracts a single icon from a file.92/vbapi/ref/e/extracticon. the function returns the number of icons stored in the file. Visual Basic-Specific Issues None.168. Parameters hInst A handle to the instance of the application calling the function.ico).exe) file. Alternately. Return Value If the function failed because the specified file was not found. If the function succeeded and an icon was specified.vbforums. Windows 98: Supported.26.vbworld. or an icon file (. The icon generated by this function must be destroyed using DestroyIcon after the program has finished using it.com | ExtractIcon Function Declare Function ExtractIcon Lib "shell32.1 or later.dll" Alias "ExtractIconA" (ByVal hInst as Long.com | www.com .part of the VB-World Network | www. a dynamic link library (. ByVal nIconIndex As Long) As Long Platforms q q q q q Windows 95: Supported.

NT 4. . or . ExtractIconEx must be used instead. Go back to the Reference section index.dll.hInstance. 100. hIcon) ' Although the icon's image is still visible. the function returns the number of icons stored in the specified file. http://216.168. retval = DestroyIcon(hIcon) End If See Also ExtractIconEx Category Icons Go back to the alphabetical Function listing. The icon must be destroyed after the ' program finishes using it.ico to extract an icon from.exe.). hIcon = ExtractIcon(App. the function extracts the icon whose resource identifier equals the absolute value of this parameter. retval = DrawIcon(Form1.) Example ' This code is licensed according to the terms and conditions listed here.hDC. the icon itself is not in use. etc. If hIcon = 0 Then Debug.exe". 75. ' Display the first icon (index 0) stored in the executable file ' C:\MyApp\Prog.Print "Failed to extract the icon -. 0) ' Only attempt to display the icon if we successfully extracted it.aborting." End ' terminate the program Else ' Display the icon at coordinates (100. (To extract an icon with a resource identifier of 1. 98. If this is a non-negative number. ' Therefore we destroy it to free up resources. "C:\MyApp\Prog. the function extracts the icon using this value as the zero-based index (an index of 0 identifies the first icon.0 or later. Windows 95.92/vbapi/ref/e/extracticon. 75) on window Form1.html (2 of 3) [9/1/2002 5:19:04 PM] . nIconIndex If this is -1. Dim hIcon As Long ' handle to the function gotten from the executable file Dim retval As Long ' return value ' Extract the first icon stored in the aforementioned executable file.exe on window Form1.Windows API Guide: ExtractIcon Function The name of an .26. 2000: If this is negative and not -1.

E-mail: vbapi@vbapi. 2000 Go back to the Windows API Guide home page. 1999 This page is copyright © 1999 Paul Kuliniewicz.Windows API Guide: ExtractIcon Function Last Modified: August 4.168. Copyright Information Revised October 29.html (3 of 3) [9/1/2002 5:19:04 PM] .com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/e/extracticon.26.com/ref/e/extracticon.vbapi.html http://216.

com | www. 2000: If this is a negative integer and at least either phiconLarge or phiconSmall (or both) are not zero.part of the VB-World Network | www.vbforums. . nIconIndex The zero-based index of the first icon to extract from the file.Windows API Guide: ExtractIconEx Function vbapi. This function can extract both large and small icons. this function can also determine how many large/small icon pairs are stores in such a file.vbworld.com | ExtractIconEx Function Declare Function ExtractIconEx Lib "shell32. or . the function returns the number of icons stored in the file specified.168.com | www.exe.dll.html (1 of 3) [9/1/2002 5:19:15 PM] .0 or later. If this is -1 and both phiconLarge and phiconSmall are 0.26.92/vbapi/ref/e/extracticonex. Visual Basic-Specific Issues When passing 0 explicitly as phiconLarge or phiconSmall. Windows 98: Supported. whose handles are placed into two arrays. Parameters lpszFile The name of the .dll" Alias "ExtractIconExA" (ByVal lpszFile As String.exe).ico). Each icon which this function extracts must be destroyed using DestroyIcon after the program has finished using it. Windows CE: Requires Windows CE 1. and phiconSmall is set to 0. the function first extracts the http://216. the function returns the number of icons successfully extracted from the file. ByVal nIconIndex As Long. Windows 2000: Supported. NT 4. the 0 must be preceeded by the ByVal keyword.vbshop. Description & Usage ExtractIconEx extracts multiple icons from a file.ico file to extract the icons from. Return Value If nIconIndex is set to -1.vbsquare.0 or later. phiconSmall As Long. or an icon file (.0 or later. ByVal nIcons As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns the number of icons stored in the file. Windows NT: Requires Windows NT 4. 98.vbapi. Windows 95. This file can be an executable file (. a dynamic link library (.dll).com .com | www. phiconLarge is set to 0. See the example for a demonstration. Otherwise. phiconLarge As Long.com | www. Optionally.

ByVal 0. numicons. hIcons(0). Display them in a row. beginning with the icon identified by nIconIndex. ' Extract all of the regular-sized icons from the file ' C:\MyApp\Prog.exe. 32. Dim hIcons() As Long ' dynamic array to receive handles to the icons Dim numicons As Long ' number of regular icons in the file Dim hBrush As Long ' handle to the background brush to use Dim c As Long ' counter variable Dim retval As Long ' return value ' Determine how many regular icons exist in the file and resize ' the array accordingly. DI_NORMAL) ' Now destroy this icon since we no longer are using it. 0) If numicons = 0 Then Debug. ' Display this particular icon. stretching or shrinking them to ' a width of 32 and a height of 64. 0. hBrush = GetStockObject(LTGRAY_BRUSH) ' handle to the brush ' Extract all of the icons to display. ByVal 0. To not extract any large icons. 0) ' Loop through each icon. hBrush.Print "No icons found in the file -.html (2 of 3) [9/1/2002 5:19:15 PM] . 64. numicons = ExtractIconEx("C:\MyApp\Prog.aborting. Example ' This code is licensed according to the terms and conditions listed here. Note how dynamically allocated arrays ' are used to receive the icon handles. retval = DrawIconEx(Form1. phiconLarge An array which receives the handles of the large icons extracted from the file. retval = DestroyIcon(hIcons(c)) Next c See Also http://216.hDC. nIcons The number of icons to extract from the file.exe". displaying it as previously mentioned. The y coordinate is always 0. retval = ExtractIconEx("C:\MyApp\Prog. -1. hIcons(c). phiconSmall An array which receives the handles of the small icons extracted from the file. pass 0 as this parameter. To not extract any small icons.Windows API Guide: ExtractIconEx Function icon whose resource identifier equals the absolute value of this parameter. Icons are extracted sequentially.168.26. pass 0 as this parameter.1 ' The x coordinate equals 32 * c. 0. ByVal 0. 32 * c. Draw all icons on a light-gray ' background on the window Form1.exe".1) As Long ' resize the array to hold all the handles ' Get a handle to the stock solid light gray brush to use for the background." End ' abort the program if failure occurs End If ReDim hIcons(0 To numicons . For c = 0 To numicons .92/vbapi/ref/e/extracticonex.

Windows API Guide: ExtractIconEx Function ExtractIcon Category Icons Go back to the alphabetical Function listing. 2000 Go back to the Windows API Guide home page.com/ref/e/extracticonex.html http://216.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/e/extracticonex. Copyright Information Revised October 29. 1999 This page is copyright © 1999 Paul Kuliniewicz.26. Last Modified: August 5. E-mail: vbapi@vbapi.vbapi.168. Go back to the Reference section index.html (3 of 3) [9/1/2002 5:19:15 PM] .

Display ' the creation time of each file.168.*".92/vbapi/ref/f/filetimetolocalfiletime.vbforums.part of the VB-World Network | www.vbapi. lpFileTime The source time and date.com | www. Since the file search functions give the file times in UTC ' time.vbshop. The function returns 1 if successful.vbworld. Win NT FileTimeToLocalFileTime converts a time from UTC time (also known as Greenwich Mean Time) to "local time" (inside the computer's selected time zone).com | www. they must be converted to local time before they are displayed. findinfo) If hsearch = -1 Then ' no files match the search string Debug.*". localtime) http://216. The source and target times are stored in FILETIME structures.dll" (lpFileTime As FILETIME.Windows API Guide: FileTimeToLocalFileTime Function vbapi. Example: ' Search for all files that match "C:\MyProgram\user*. Dim hsearch As Long ' handle to the file search Dim findinfo As WIN32_FIND_DATA ' receives info about matching files Dim success As Long ' will be 1 if successive searches are successful.vbsquare.ftCreationTime. Do ' begin loop ' Convert UTC FILETIME to local SYSTEMTIME and display the date: retval = FileTimeToLocalFileTime(findinfo.com | FileTimeToLocalFileTime Function Declare Function FileTimeToLocalFileTime Lib "kernel32.26. the next file (if any) is found.com | www. Win 95/98. lpLocalFileTime Receives the time and date stored in lpFileTime converted into the computer's current time zone time.com . and then the loop restarts.com | www. ' This way the first file (found above) will also be displayed. or 0 if an error occurs.Print "(no files matched search parameter)" End ' abort program End If ' Display creation date of each file that matches the search. lpLocalFileTime As FILETIME) As Long Platforms: Win32s. Note that the name ' is displayed. 0 if not Dim localtime As FILETIME ' receives local creation time Dim systime As SYSTEMTIME ' receives creation time Dim retval As Long ' generic return value ' Begin a file search: hsearch = FindFirstFile("C:\MyProgram\user*.html (1 of 2) [9/1/2002 5:19:22 PM] . which are in UTC time.

Windows API Guide: FileTimeToLocalFileTime Function retval = FileTimeToSystemTime(localtime.wMonth.html (2 of 2) [9/1/2002 5:19:22 PM] .com Send Encrypted E-Mail This page is at http://www. This page is copyright © 2000 Paul Kuliniewicz.Print "Date:".92/vbapi/ref/f/filetimetolocalfiletime. E-mail: vbapi@vbapi.168.html http://216.wDay. Copyright Information.wYear ' Get the next matching file and loop if it exists: success = FindNextFile(hsearch.com/ref/f/filetimetolocalfiletime.vbapi. findinfo) Loop Until success = 0 ' keep looping until no more matching files are found ' Close the file search handle retval = FindClose(hsearch) See Also: LocalFileTimeToFileTime Category: Time Go back to the alphabetical Function listing. systime. systime. "-". Go back to the Reference section index. systime) Debug.26. "-". Go back to the Windows API Guide home page. systime.

com | www.vbworld. Example: ' Display the date when file C:\MyProgram\datafile.vbforums.txt.com | www. Note how CreateFile's alternate declare must be used under Win 95/98 -' see that function's page for more information. 0) If hfile = -1 Then ' if the file could not be opened Debug. lpFileTime The date and time. wtime) ' Convert the creation time from a FILETIME structure to a SYSTEMTIME structure (for usability): http://216.html (1 of 2) [9/1/2002 5:19:28 PM] . Dim hfile As Long ' receives the handle to the file Dim ctime As FILETIME ' receives creation date and time of the file Dim atime As FILETIME ' receives last access date and time of the file Dim wtime As FILETIME ' receives last write-to date and time of the file Dim createtime As SYSTEMTIME ' receives a converted form of ctime Dim retval As Long ' return value ' Get a handle to the file (note how the alternate declare is used): hfile = CreateFileNS("C:\MyProgram\datafile.168.dll" (lpFileTime As FILETIME. Win NT FileTimeToSystemTime converts a time and date stored in a FILETIME structure to an identical time and date stored in a SYSTEMTIME structure.com | www.txt was ' created.vbapi. The latter structure provides a easier way to access a date and time.com | FileTimeToSystemTime Function Declare Function FileTimeToSystemTime Lib "kernel32. Win 95/98. lpSystemTime As SYSTEMTIME) As Long Platforms: Win 32s.vbshop. The function returns 0 if an error occured. Also note how the times returned by GetFileTime ' need to be converted so the program can figure out what the date actually is.txt".part of the VB-World Network | www. whereas the former is used by Windows to identify times and dates associated with files. lpSystemTime Receives the date and time converted into SYSTEMTIME format." End ' abort the program End If ' Get the various times and dates associated with the file: retval = GetFileTime(hfile.com . OPEN_EXISTING. 0.com | www. in FILETIME form. atime.92/vbapi/ref/f/filetimetosystemtime. to convert.Print "Could not open the file C:\MyProgram\datafile.26. The data put into the SYSTEMTIME structure identifies the same time and date as the source structure does. GENERIC_READ.vbsquare. FILE_ATTRIBUTE_ARCHIVE. FILE_SHARE_READ. ctime. or 1 if successful.Windows API Guide: FileTimeToSystemTime Function vbapi.

Copyright Information.wDay. createtime. Go back to the Windows API Guide home page. "-".com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/f/filetimetosystemtime.html http://216. createtime.Print "Creation Date:".168.wYear ' Close the file retval = CloseHandle(hfile) See Also: SystemTimeToFileTime Category: Time Go back to the alphabetical Function listing.com/ref/f/filetimetosystemtime. createtime. Go back to the Reference section index. This page is copyright © 2000 Paul Kuliniewicz.html (2 of 2) [9/1/2002 5:19:28 PM] .vbapi.26. createtime) ' Display the creation date of the file: Debug. "-".Windows API Guide: FileTimeToSystemTime Function retval = FileTimeToSystemTime(ctime.wMonth. E-mail: vbapi@vbapi.

Length The number of memory bytes.168. the ByVal keyword must preceed it.Windows API Guide: FillMemory Function vbapi. Windows CE: Not Supported. However. Return Value FillMemory does not return a value.vbapi. The function does this by setting each byte starting at the given memory location to the desired value.com | www.dll" Alias "RtlFillMemory" (Destination As Any.html (1 of 2) [9/1/2002 5:19:33 PM] .com .vbsquare. Description & Usage FillMemory fills a location in memory with a certain value. to fill. beginning with the address identified by Destination. Windows NT: Requires Windows NT 3.1 or later.26. See the example below for a demonstration.vbshop.com | www. Visual Basic-Specific Issues A pointer to any variable can be automatically generated merely by passing that variable as Destination.vbforums. http://216. Windows 2000: Supported. Windows 98: Supported.com | FillMemory Function Declare Sub FillMemory Lib "kernel32.92/vbapi/ref/f/fillmemory. Fill The byte value to set each byte in the desired memory location to. The memory location is identified by a pointer to the memory address. ByVal Length As Long.com | www. if either a String or a Long holding the desired memory address is passed.vbworld.com | www. Parameters Destination A pointer to the location in memory (often the memory address of a variable) to begin filling with a certain value.part of the VB-World Network | www. ByVal Fill As Byte) Platforms q q q q q Windows 95: Supported.

' set each character in a 20-character string to the character "X". 20. Last Modified: July 25. Go back to the Reference section index.92/vbapi/ref/f/fillmemory.Print bytearray(c).26. bytestring = Space(20) ' make the string 20 characters long FillMemory ByVal bytestring.html http://216.com Send Encrypted E-Mail This page is at http://www. 10. it is passed as normal.168.Print bytestring ' will be twenty X's See Also ZeroMemory Category Memory Go back to the alphabetical Function listing. 2000 Go back to the Windows API Guide home page. ' each value displayed will be 76 Next c Note ' Now fill a 20-character string with "X" (using its ASCII code). in Visual ' Basic. ' Initialize all the elements in an array of bytes to the value 76.Windows API Guide: FillMemory Function Example ' This code is licensed according to the terms and conditions listed here. that. E-mail: vbapi@vbapi. FillMemory bytearray(0). to ' identify the pointer to bytearray()'s memory. Copyright Information Revised October 29. the ByVal keyword must preceed the string in this case. 1999 This page is copyright © 1999 Paul Kuliniewicz. Debug.vbapi. Note how. For c = 0 To 9 ' loop through each element Debug. Dim bytearray(0 To 9) As Byte ' array of 10 bytes Dim bytestring As String ' string to fill Dim c As Integer ' counter variable Also ' Fill the memory at bytearray() in order to initialize its members to 76.html (2 of 2) [9/1/2002 5:19:33 PM] . 76 ' fill 10 bytes to the byte value 76 ' Display the results to verify that it worked. Asc("X") ' set the contents to a bunch of "X"'s ' Display the results to verify that it worked.com/ref/f/fillmemory.

255)) ' Fill in the desired rectangular area retval = FillRect(Form1.vbworld. 175) ' now r = (20.dll" (ByVal hdc As Long.25)-(200. and the bottom and right edges of the given rectangle are not filled in (they are not considered to be part of the interior of the rectangle). r.168.hDC. hdc A device context to the device to fill a rectangular area of. Win 95/98. 200.html (1 of 2) [9/1/2002 5:19:41 PM] . ByVal hBrush As Long) As Long Platforms: Win 32s.Windows API Guide: FillRect Function vbapi. so it is not necessary to use SelectObject to have the device select the brush first. 0. hBrush A handle to the brush to use to fill in the rectangular area. lpRect As RECT.com | www. 25.175).part of the VB-World Network | www.vbapi. Note that this function uses the brush passed to the function.com | FillRect Function Declare Function FillRect Lib "user32.26. Dim hbrush As Long ' receives handle to the blue hatched brush to use Dim r As RECT ' rectangular area to fill Dim retval As Long ' return value ' Set the coordinates of the rectangle r retval = SetRect(r. The function returns 1 if successful.com .com | www. The outline of the rectangular area is not drawn. RGB(0.25)-(200. Example: ' Use a blue diagonal-cross hatched brush to fill in a rectangular ' area on window Form1. lpRect The coordinates of the rectangular area to fill. or 0 if an error occured.175) ' Create a blue diagonal-cross hatched brush hbrush = CreateHatchBrush(HS_DIAGCROSS.com | www.vbshop. 20. FrameRect Category: Filled Shapes http://216.92/vbapi/ref/f/fillrect. Win NT FillRect fills a rectangular area on a device using the specified brush.vbforums.vbsquare.com | www. The rectangular area has coordinates (20. hbrush) ' fill the rectangle using the brush ' Delete the brush we created in order to free up resources retval = DeleteObject(hbrush) See Also: FillRgn.

Go back to the Reference section index. This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page.168.92/vbapi/ref/f/fillrect. Copyright Information.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:19:41 PM] .Windows API Guide: FillRect Function Go back to the alphabetical Function listing.vbapi.html http://216.com/ref/f/fillrect. E-mail: vbapi@vbapi.26.

' Use the light-gray solid stock brush to fill an elliptical region on window ' Form1.26. hdc A device context to the device to fill a region of. hrgn = CreateEllipticRgn(30. The stock brush does not need to be deleted. http://216.com | FillRgn Function Declare Function FillRgn Lib "gdi32. Instead of using the device's currently selected brush. Win 95/98. The bounding rectangle of the ellipse is (30. The function returns 0 if an error occured. retval = FillRgn(Form1.110). hrgn.com | www. only its area is filled.html (1 of 2) [9/1/2002 5:19:47 PM] . Dim hrgn As Long ' handle to the region to fill Dim hbrush As Long ' handle to the brush to fill the region with Dim retval As Long ' return value ' First. The boundary of the region is not drawn. Win NT FillRgn fills the area defined by a region on a device. hBrush A handle to the brush to use to fill the region.20)-(150. 20. 150. retval = DeleteObject(hrgn) See Also: FillRect.dll" (ByVal hdc As Long. create the elliptical region and get a handle to it.com | www.com | www. ByVal hRgn As Long. hbrush) ' Delete the region to free resources.168.vbapi. FrameRgn Category: Regions Go back to the alphabetical Function listing.vbshop. 110) ' Fill the region using the light-gray brush. Go back to the Reference section index. hbrush = GetStockObject(LTGRAY_BRUSH) ' Next.com .part of the VB-World Network | www. hRgn A handle to the region on the device to fill. or a non-zero value if successful. Example: ' This code is licensed according to the terms and conditions listed here. ByVal hBrush As Long) As Long Platforms: Win 32s.vbforums.Windows API Guide: FillRgn Function vbapi.92/vbapi/ref/f/fillrgn.vbworld.vbsquare. get a handle to the stock light-gray solid brush.hDC.com | www. the region is filled using a brush passed to the function.

Windows API Guide: FillRgn Function This page is copyright © 2000 Paul Kuliniewicz.168. Go back to the Windows API Guide home page.com/ref/f/fillrgn.vbapi.html http://216.26. Copyright Information.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:19:47 PM] . E-mail: vbapi@vbapi.92/vbapi/ref/f/fillrgn.

Dim hsearch As Long ' handle to the file search Dim findinfo As WIN32_FIND_DATA ' receives info about matching files Dim success As Long ' will be 1 if successive searches are successful.cFileName.26.com .92/vbapi/ref/f/findclose.Print buffer ' display this filename ' Get the next matching file and loop if it exists: success = FindNextFile(hsearch.com | www.Windows API Guide: FindClose Function vbapi. This function closes the file search handle.com | www. Display ' the filename of each file that matches the string.168. InStr(findinfo. findinfo) Loop Until success = 0 ' keep looping until no more matching files are found ' Close the file search handle retval = FindClose(hsearch) http://216.vbsquare.vbapi.1) Debug.vbforums. vbNullChar) . hFindFile The search handle of the file-search operation to end.part of the VB-World Network | www.vbworld. Do ' begin loop ' Extract the filename from the fixed-length string: buffer = Left(findinfo.html (1 of 2) [9/1/2002 5:20:03 PM] . This way the first file ' (found above) will also be displayed. Win NT FindClose terminates a file-search operation initiated by FindFirstFile. and then the loop restarts.*". Note that the name is displayed. Win 95/98.cFileName. findinfo) If hsearch = -1 Then ' no files match the search string Debug.com | FindClose Function Declare Function FindClose Lib "kernel32.*".com | www.com | www.vbshop.Print "(no files matched search parameter)" End ' abort program End If ' Display name of each file that matches the search.dll" (ByVal hFindFile As Long) As Long Platforms: Win 32s. Example: ' Search for all files that match "C:\MyProgram\user*. 0 if not Dim buffer As Long ' string buffer to use to process the filename(s) Dim retval As Long ' generic return value ' Begin a file search: hsearch = FindFirstFile("C:\MyProgram\user*. the ' next file (if any) is found.

168. FindNextFile Category: Files Go back to the alphabetical Function listing.html (2 of 2) [9/1/2002 5:20:03 PM] .com Send Encrypted E-Mail This page is at http://www.Windows API Guide: FindClose Function See Also: FindFirstFile.html http://216.vbapi. This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page.26. Go back to the Reference section index. Copyright Information.92/vbapi/ref/f/findclose.com/ref/f/findclose.

findinfo) If hsearch = -1 Then ' no files match the search string Debug. The function searches for files based only on a filename with wildcards (* or ?). Dim hsearch As Long ' handle to the file search Dim findinfo As WIN32_FIND_DATA ' receives info about matching files Dim success As Long ' will be 1 if successive searches are successful.vbworld. This way the first file ' (found above) will also be displayed.html (1 of 2) [9/1/2002 5:20:11 PM] .com | www.com | www.vbforums.26. lpFileName The file search string to look for.dll" Alias "FindFirstFileA" (ByVal lpFileName As String. Example: ' Search for all files that match "C:\MyProgram\user*. Do ' begin loop ' Extract the filename from the fixed-length string: buffer = Left(findinfo.cFileName. Win 95/98.part of the VB-World Network | www. It can contain the wildcards * or ?. InStr(findinfo.*". The search only looks in a single directory for the file(s). and then the loop restarts. or -1 if no files match the search (or if an error occured).92/vbapi/ref/f/findfirstfile. the ' next file (if any) is found. including the complete path.com .vbsquare. lpFindFileData Receives identifying information about the first file that matches the search string. Note that the name is displayed. 0 if not Dim buffer As Long ' string buffer to use to process the filename(s) Dim retval As Long ' generic return value ' Begin a file search: hsearch = FindFirstFile("C:\MyProgram\user*.Print buffer ' display this filename http://216. but it will identify any directory names in that directory that match the search string. Display ' the filename of each file that matches the string.com | FindFirstFile Function Declare Function FindFirstFile Lib "kernel32.*". The function returns a "search handle" which can be used to look for additional matching files (via FindNextFile).com | www.vbshop. Identifying information about the file is put into the variable passed as lpFindFileData.1) Debug.cFileName. lpFindFileData As WIN32_FIND_DATA) As Long Platforms: Win 32s. Win NT FindFirstFile begins a file search and provides information about the first matching file.Print "(no files matched search parameter)" End ' abort program End If ' Display name of each file that matches the search.com | www.168.vbapi.Windows API Guide: FindFirstFile Function vbapi. vbNullChar) .

26.html (2 of 2) [9/1/2002 5:20:11 PM] .html http://216.com/ref/f/findfirstfile.Windows API Guide: FindFirstFile Function ' Get the next matching file and loop if it exists: success = FindNextFile(hsearch.vbapi.92/vbapi/ref/f/findfirstfile. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www. Copyright Information. This page is copyright © 2000 Paul Kuliniewicz.168. Go back to the Reference section index. findinfo) Loop Until success = 0 ' keep looping until no more matching files are found ' Close the file search handle retval = FindClose(hsearch) See Also: FindClose. FindNextFile Category: Files Go back to the alphabetical Function listing.

lpFindFileData Receives identifying information about the next matching file that was found.com | www.168. This information is put into the variable passed as lpFindFileData.Windows API Guide: FindNextFile Function vbapi. Dim hsearch As Long ' handle to the file search Dim findinfo As WIN32_FIND_DATA ' receives info about matching files Dim success As Long ' will be 1 if successive searches are successful.vbshop.*". vbNullChar) .*". the ' next file (if any) is found. Win 95/98. It finds and provides identifying information about the next file that matches the search string.vbsquare.Print "(no files matched search parameter)" End ' abort program End If ' Display name of each file that matches the search.cFileName.com | www. and then the loop restarts.com . 0 if not Dim buffer As Long ' string buffer to use to process the filename(s) Dim retval As Long ' generic return value ' Begin a file search: hsearch = FindFirstFile("C:\MyProgram\user*. Win NT FindNextFile continues a file search began by FindFirstFile. Example: ' Search for all files that match "C:\MyProgram\user*.html (1 of 2) [9/1/2002 5:20:17 PM] .vbworld.com | FindNextFile Function Declare Function FindNextFile Lib "kernel32.vbapi. InStr(findinfo.part of the VB-World Network | www. or 0 if no more matching files exist (or if an error occured).26. Display ' the filename of each file that matches the string.vbforums. Note that the name is displayed. This way the first file ' (found above) will also be displayed.com | www. lpFindFileData As WIN32_FIND_DATA) As Long Platforms: Win 32s. hFindFile The handle to the file search initiated by FindFirstFile. The function returns 1 if another matching file was found.cFileName. findinfo) If hsearch = -1 Then ' no files match the search string Debug.Print buffer ' display this filename ' Get the next matching file and loop if it exists: http://216.1) Debug.dll" Alias "FindNextFileA" (ByVal hFindFile As Long.com | www. Do ' begin loop ' Extract the filename from the fixed-length string: buffer = Left(findinfo.92/vbapi/ref/f/findnextfile.

26.vbapi. Go back to the Reference section index. findinfo) Loop Until success = 0 ' keep looping until no more matching files are found ' Close the file search handle retval = FindClose(hsearch) See Also: FindClose.92/vbapi/ref/f/findnextfile. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page. FindFirstFile Category: Files Go back to the alphabetical Function listing.com/ref/f/findnextfile. Copyright Information.html http://216.168.com Send Encrypted E-Mail This page is at http://www. This page is copyright © 2000 Paul Kuliniewicz.Windows API Guide: FindNextFile Function success = FindNextFile(hsearch.html (2 of 2) [9/1/2002 5:20:17 PM] .

Windows 98: Supported. the function returns zero (use GetLastError to get the error code). Windows CE: Requires Windows CE 1. Windows NT: Requires Windows NT 3.vbshop. specify a null string.1 or later.com | FindWindow Function Declare Function FindWindow Lib "user32.com | www. Visual Basic-Specific Issues To pass a null string as one of the function's parameters. lpWindowName The name of the title bar text of the window to find.vbworld. Example http://216. use the vbNullString constant. Windows 2000: Supported. Return Value If successful.26. To ignore the window's class.dll" Alias "FindWindowA" (ByVal lpClassName As String.vbapi. If no matching window could be found.html (1 of 3) [9/1/2002 5:20:22 PM] .0 or later. the function returns a handle to the window that was found.com . To ignore the window's text.vbsquare. If you do not wish to specify one of the parameters. Description & Usage FindWindow searches all windows for one which matches the window class name and/or window name. Parameters lpClassName The name of the window class of the window to find. ByVal lpWindowName As String) As Long Platforms q q q q q Windows 95: Supported. pass a null string for it.Windows API Guide: FindWindow Function vbapi.part of the VB-World Network | www.com | www.92/vbapi/ref/f/findwindow.com | www. specify a null string.168. The function's searching mechanism is not case-sensitive.com | www. or if an error occured.vbforums.

26.) Public Declare Function FindWindow Lib "user32.Print "Minesweeper is not currently running.92/vbapi/ref/f/findwindow.dll" (ByVal dwMilliseconds As Long) ' *** Place the following code inside a form. "Minesweeper") If hWnd = 0 Then Debug. since most likely there won't be any unless Windows's Minesweeper game is running." Else ' Flash the window's title bar on and off once. 1) Sleep 500 ' pause for half a second retval = FlashWindow(hWnd. _ ByVal lpWindowName As String) As Long Public Declare Function FlashWindow Lib "user32. so to use this example. ByVal bInvert As Long) As Long Public Declare Sub Sleep Lib "kernel32. hWnd = FindWindow(vbNullString.dll" Alias "FindWindowA" (ByVal lpClassName As String. *** Private Sub cmdFind_Click() Dim hWnd As Long ' receives handle to the found window Dim retval As Long ' generic return value ' Attempt to locate a window titled Minesweeper.html (2 of 3) [9/1/2002 5:20:22 PM] . This is all done when the user clicks button cmdFind.168.dll" (ByVal hWnd As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.Windows API Guide: FindWindow Function Search for a window called Minesweeper and flash its title bar once. We don't need to know the name of the window's class to find it. you naturally must place a command button named cmdFind on a form window. 0) End If End Sub See Also FindWindowEx Category Windows Go back to the alphabetical Function listing. Go back to the Reference section index. http://216. ' This code is licensed according to the terms and conditions listed here. retval = FlashWindow(hWnd.

html (3 of 3) [9/1/2002 5:20:22 PM] .html http://216.92/vbapi/ref/f/findwindow.com/ref/f/findwindow.168.26.com Send Encrypted E-Mail This page is at http://www. 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.Windows API Guide: FindWindow Function Last Modified: December 17. Copyright Information Revised October 29. 2000 This page is copyright © 2000 Paul Kuliniewicz.vbapi.

ByVal lpszWindow As String) As Long Platforms q q q q q Windows 95: Supported.vbapi.92/vbapi/ref/f/findwindowex.com | www.26. the function returns zero (use GetLastError to get the error code.com | www. ByVal hwndChildAfter As Long. Parameters hWndParentA handle to the parent window to search the child windows of.com | www.vbworld. or if an error occured. beginning with the windows below a specified child window. lpszWindow The name of the title bar text of the window to find. Windows 98: Supported. hWndChildAfterA handle to the child window specifying a place to begin searching.html (1 of 3) [9/1/2002 5:20:27 PM] . Description & Usage FindWindowEx searches for a window matching a specified window class name and/or window name. Specify a null string to ignore the class. To ignore the window's class and/or title. pass a null string for those parameters. To search all windows.Windows API Guide: FindWindowEx Function vbapi. lpszClass The name of the window class of the window to find.com | FindWindowEx Function Declare Function FindWindowEx Lib "user32. http://216. searching begins with the child window at the top of the Z-order. Windows NT: Requires Windows NT 4. ByVal lpszClass As String.vbshop. Specify a null string to ignore the window's title.dll" Alias "FindWindowExA" (ByVal hwndParent As Long. The function searches all of the child windows of a given window (if desired). use the vbNullString constant. Visual Basic-Specific Issues To pass a null string as one of the function's parameters.168. the function returns a handle to the found window.vbforums.com | www. Return Value If successful. Windows 2000: Supported. Searching begins with the child window immediately after this window in the Z-order. If this is 0.part of the VB-World Network | www. If no matching window could be found.com . specify 0 for this parameter.vbsquare. Windows CE: Not Supported.0 or later.

slength + 1) ' Remove the terminating null and display the result.Print "The command button's name is: ". *** Private Sub Dim Dim Dim Dim cmdFind_Click() hWnd As Long slength As Long wintext As String retval As Long ' ' ' ' handle to the found window (the command button) length of the found window's text holds the window's text return value ' Find the "topmost" command button on Form1. _ ByVal lpString As String. wintext = Left(wintext. In VB5 and VB6. slength) Debug. 0.dll" Alias "FindWindowExA" (ByVal hwndParent As Long.) Public Declare Function FindWindowEx Lib "user32.Windows API Guide: FindWindowEx Function Example Display the name of the first command button on window Form1. This search runs when the user clicks button cmdFind. The buttons on a form are child windows of the window they appear in. ByVal nMaxCount As Long) As Long ' *** Place the following code inside the form window. vbNullString) If hWnd = 0 Then Debug.92/vbapi/ref/f/findwindowex.168.html (2 of 3) [9/1/2002 5:20:27 PM] . buttons created in the Form Editor have class "ThunderCommandButton". wintext End If End Sub See Also FindWindow http://216.dll" Alias "GetWindowTextLengthA" _ (ByVal hWnd As Long) As Long Public Declare Function GetWindowText Lib "user32. "ThunderCommandButton".dll" Alias "GetWindowTextA" (ByVal hWnd As Long. so to use this example. ByVal lpszClass As String. ByVal lpszWindow As String) As Long Public Declare Function GetWindowTextLength Lib "user32.26. hWnd = FindWindowEx(Form1. Begin searching at the top.Print "No command buttons of class ThunderCommandButton were found. ' This code is licensed according to the terms and conditions listed here." Else ' Get the text displayed in the button. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. you must first place a command button named cmdFind on a form window. wintext.hWnd. slength = GetWindowTextLength(hWnd) wintext = Space(slength + 1) retval = GetWindowText(hWnd. _ ByVal hwndChildAfter As Long.

2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi. Go back to the Reference section index.168. 2000 Go back to the Windows API Guide home page.html (3 of 3) [9/1/2002 5:20:27 PM] .com/ref/f/findwindowex.vbapi.com Send Encrypted E-Mail This page is at http://www. Last Modified: December 17.Windows API Guide: FindWindowEx Function Category Windows Go back to the alphabetical Function listing.26.92/vbapi/ref/f/findwindowex. Copyright Information Revised October 29.html http://216.

retval As Long ' counter variable & return value For c = 1 To 10 ' flash on five times. ByVal bInvert As Long) As Long Platforms: Win 32s.com | www. If zero. Example: ' Flash Form1 five times to get the user's attention Dim c As Integer.com | www.com | www.com .vbworld. restores the window to its normal look. Flashing is where the title bar of the window is switched from an active to inactive look (or vice versa) to get the user's attention. Go back to the Reference section index.vbforums.hWnd.vbapi.Windows API Guide: FlashWindow Function vbapi.92/vbapi/ref/f/flashwindow. http://216. be sure to call the function again. hwnd The handle of the window to flash one step. The function returns 0 if the window's look was inactive before flashing. If non-zero.26. Win 95/98.168.com | FlashWindow Function Declare Function FlashWindow Lib "user32. Normally this is done multiple times. bInvert Specifies how to flash. Win NT FlashWindow flashes a window one step.dll" (ByVal hwnd As Long.vb-shop. 1) ' toggle the look of the window Sleep 500 ' halt execution for 500 milliseconds (1/2 minute) Next c retval = FlashWindow(Form1. When you are done flashing. 0) ' make sure the window looks normal Category: Windows Go back to the alphabetical Function listing. this time with bInvert set to 0. switches the title bar from an active to inactive look (or vice versa).hWnd.html (1 of 2) [9/1/2002 5:20:34 PM] .vbsquare. or 1 if its look was active. off five times retval = FlashWindow(Form1.com | www.part of the VB-World Network | www. instead of just once.

92/vbapi/ref/f/flashwindow.html (2 of 2) [9/1/2002 5:20:34 PM] . Copyright Information.html http://216.Windows API Guide: FlashWindow Function This page is copyright © 2000 Paul Kuliniewicz.26. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.168. Go back to the Windows API Guide home page.com/ref/f/flashwindow.vbapi.

26. 25. 200. r. lpRect The rectangle that defines the rectangular frame to draw. hdc A device context to the device to draw the rectangular frame on. lpRect As RECT.vbforums. ByVal hBrush As Long) As Long Platforms: Win 32s. FrameRgn Category: Filled Shapes Go back to the alphabetical Function listing.com | www. Dim hbrush As Long ' receives handle to the blue hatched brush to use Dim r As RECT ' rectangular area to frame Dim retval As Long ' return value ' Set the coordinates of the rectangle r retval = SetRect(r.92/vbapi/ref/f/framerect. http://216.com | www.dll" (ByVal hdc As Long. The function returns 1 if successful. so it is not necessary to use SelectObject to have the device select the brush first. Example: ' Use a blue diagonal-cross hatched brush to draw a rectangular ' frame on window Form1.part of the VB-World Network | www.vbworld.com | www. Win 95/98.Windows API Guide: FrameRect Function vbapi.com .com | FrameRect Function Declare Function FrameRect Lib "user32. Note that this function uses the brush passed to the function. This frame is equivalent to what the edge of a filled rectangle (using FillRect) would be. Win NT FrameRect draws a one-pixel-wide frame around a rectangle on a device using a given brush.25)-(200. 20. 0. RGB(0. hBrush A handle to the brush to use to draw the rectangular frame.175) ' Create a blue diagonal-cross hatched brush hbrush = CreateHatchBrush(HS_DIAGCROSS. or 0 if an error occured.vbapi.hDC.175).168. 175) ' now r = (20.vbsquare. hbrush) ' frame the rectangle using the brush ' Delete the brush we created in order to free up resources retval = DeleteObject(hbrush) See Also: FillRect.vbshop. The rectangular frame has coordinates (20.25)-(200.com | www.html (1 of 2) [9/1/2002 5:20:38 PM] . 255)) ' Fill in the desired rectangular area retval = FrameRect(Form1.

vbapi.com Send Encrypted E-Mail This page is at http://www. Copyright Information.html http://216.92/vbapi/ref/f/framerect.26.html (2 of 2) [9/1/2002 5:20:38 PM] .com/ref/f/framerect. E-mail: vbapi@vbapi.Windows API Guide: FrameRect Function Go back to the Reference section index.168. This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page.

' A green diagonally cross-hatched brush is used. hdc A device context to the device to draw on.html (1 of 2) [9/1/2002 5:20:42 PM] .vbworld.com | www. 0)) ' brush ' Frame the region using the created brush. 3) ' frame width = 5. retval = FrameRgn(Form1.92/vbapi/ref/f/framergn.com | FrameRgn Function Declare Function FrameRgn Lib "gdi32. 5.vbforums. or a non-zero value if successful. nWidth The width in pixels of vertical brush strokes to use to draw the frame. Win 95/98. 220. 180) ' elliptical region hBrush = CreateHatchBrush(HS_DIAGCROSS. The device's currently selected brush is not used. ByVal hRgn As Long. hRgn. Example: ' Draw a frame around an elliptical region on window Form1.com . hRgn A handle to the region to draw the frame of.168.vbapi.hDC. ByVal hBrush As Long.com | www.vbshop. hRgn = CreateEllipticRgn(20. hBrush. RGB(0.com | www. The function returns 0 if an error occured. The region has bounding rectangle (20.30)(220.180). The frame will ' have a width of 5 and a height of 3. height = 3 ' Delete the region and brush to free up resources.Windows API Guide: FrameRgn Function vbapi.com | www. ByVal nWidth As Long. 255. nHeight The height in pixels of horizontal brush strokes to use to draw the frame. retval = DeleteObject(hRgn) retval = DeleteObject(hBrush) http://216. ByVal nHeight As Long) As Long Platforms: Win 32s. Win NT FrameRgn draws a frame (border) around a given region on a device using the specified brush.26. hBrush A handle to the brush to use to draw the frame.vbsquare. 30. The width and height of the drawn frame are also specified by the function.dll" (ByVal hdc As Long. Dim hRgn As Long ' handle to the region to frame Dim hBrush As Long ' handle to the green diagonally cross-hatched brush Dim retval As Long ' generic return value ' Create the elliptical region and the brush.part of the VB-World Network | www.

Go back to the Windows API Guide home page.html http://216. Copyright Information.26.com Send Encrypted E-Mail This page is at http://www.168. Go back to the Reference section index.com/ref/f/framergn.html (2 of 2) [9/1/2002 5:20:42 PM] . E-mail: vbapi@vbapi. FrameRect Category: Regions Go back to the alphabetical Function listing.Windows API Guide: FrameRgn Function See Also: FillRgn. This page is copyright © 2000 Paul Kuliniewicz.vbapi.92/vbapi/ref/f/framergn.

html [9/1/2002 5:20:47 PM] .92/vbapi/ref/g/getactivewindow.com | www. the function instead returns 0.com | www.part of the VB-World Network | www. This page is copyright © 2000 Paul Kuliniewicz.168. Copyright Information. Go back to the Windows API Guide home page.com | www. the function will get the window that would be active if the program were active. Go back to the Reference section index. SetActiveWindow Category: Windows Go back to the alphabetical Function listing. it won't find the active window of other programs. Example: ' Use FlashWindow to flash the title bar of the program's ' currently active window once.html http://216.vbworld.com .Windows API Guide: GetActiveWindow Function vbapi.com/ref/g/getactivewindow.vbapi. If an error occurs. Win NT GetActiveWindow returns a handle to your program's currently active window. GetWindow.com | GetActiveWindow Function Declare Function GetActiveWindow Lib "user32. Win 95/98.vb-shop. 1): Sleep 250 retval = FlashWindow(hactive.in other words. 0) See Also: GetForegroundWindow.dll" () As Long Platforms: Win 32s.vbsquare.com Send Encrypted E-Mail This page is at http://www. This only works with windows created by your application -. E-mail: vbapi@vbapi.com | www. or if there is no active window to your program. Dim hactive As Long ' handle to the active window Dim retval As Long ' return value hactive = GetActiveWindow() ' get the handle of the program's active window ' The next three lines flash the window's title bar retval = FlashWindow(hactive.vbforums. 1): Sleep 250 retval = FlashWindow(hactive. If your program is in the background.vbapi.26.

vbapi. Arc. ArcTo. Dim arcdir As Long ' receives arc direction arcdir = GetArcDirection(Form1. AD_COUNTERCLOCKWISE = 1 Arcs are drawn counterclockwise from the starting point to the ending point." End If See Also: AngleArc. Although this function is supported in Win 95/98.html (1 of 2) [9/1/2002 5:20:51 PM] . or exactly one of the following flags specifying which direction arcs on the device will be drawn: AD_CLOCKWISE = 2 Arcs are drawn clockwise from the starting point to the ending point.com .Print "Form1 draws arcs counterclockwise. SetArcDirection Category: Lines & Curves http://216.com | www.com | GetArcDirection Function Declare Function GetArcDirection Lib "gdi32." ElseIf arcdir = AD_COUNTERCLOCKWISE Then Debug.dll" (ByVal hdc As Long) Platforms: Win 32s.vbworld.hDC) ' get the arc direction for Form1 If arcdir = AD_CLOCKWISE Then Debug.part of the VB-World Network | www. Win NT GetArcDirection determines the direction in which arcs are drawn on a graphics-capable device.com | www. Win 95/98.com | www.vbsquare. that platform ignores the setting and always draws arcs counterclockwise! The function returns 0 if an error occured.vbforums.Windows API Guide: GetArcDirection Function vbapi.Print "Form1 draws arcs clockwise.92/vbapi/ref/g/getarcdirection. Example: ' Display which direction window Form1 draws arcs.168. hdc The device context of the device to find the arc-drawing direction of.26.vb-shop. Arcs can be drawn either clockwise or counterclockwise from the starting point to the ending point.com | www.

html http://216. This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getarcdirection.html (2 of 2) [9/1/2002 5:20:51 PM] .168.vbapi. Go back to the Windows API Guide home page.Windows API Guide: GetArcDirection Function Go back to the alphabetical Function listing. Copyright Information.26. Go back to the Reference section index. E-mail: vbapi@vbapi.com/ref/g/getarcdirection.

Windows 98: Supported. Description & Usage GetAsyncKeyState determines whether a certain key is currently pressed and whether that key has been pressed since the last call to the function.dll" (ByVal vKey As Long) As Integer Platforms q q q q q Windows 95: Supported.0 or later.com | www.vbworld.com | GetAsyncKeyState Function Declare Function GetAsyncKeyState Lib "user32.vbapi. Windows 2000: Supported. Windows CE: Requires Windows CE 1.com | www. the key has been pressed at least once since the last time the thread called GetAsyncKeyState. 2000: This could also be one of the following flags which distinguish between the left and right Ctrl. the key is currently pressed down. and Shift keys: VK_LSHIFT The left Shift key. Visual Basic-Specific Issues None.com .1 or later. If the &H1 bit of the return value is set. Alt.com | www.part of the VB-World Network | www. This function fails if the thread calling it does not currently have the input focus.vbsquare.vbshop.26. the function returns 0.Windows API Guide: GetAsyncKeyState Function vbapi. Return Value If the function fails (if the current thread does not have the input focus).html (1 of 3) [9/1/2002 5:20:56 PM] .com | www. If the &H8000 bit of the return value is set.168. Windows NT.92/vbapi/ref/g/getasynckeystate. Parameters vKey The virtual-key code of the key to check.vbforums. VK_LCONTROL The left Ctrl key. http://216. Windows NT: Requires Windows NT 3. VK_RSHIFT The right Shift key.

html (2 of 3) [9/1/2002 5:20:56 PM] . ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.168.26.Windows API Guide: GetAsyncKeyState Function VK_RCONTROL The right Ctrl key. VK_LMENU The left Alt key. If keystate And &H8000 Then Debug.Print "The Q key has not been pressed since the last check.) Public Declare Function GetAsyncKeyState Lib "user32. Constant Definitions Const Const Const Const Const Const VK_LSHIFT = &HA0 VK_RSHIFT = &HA1 VK_LCONTROL = &HA2 VK_RCONTROL = &HA3 VK_LMENU = &HA4 VK_RMENU = &HA5 Example ' This code is licensed according to the terms and conditions listed here." Else Debug.dll" (ByVal vKey As Long) As Integer ' Determine whether the Q key has been pressed or not since the last ' call to the function (assuming this example code has already been run earlier). ' (vbKeyQ is a VB-defined constant for Q's virtual-key code) keystate = GetAsyncKeyState(vbKeyQ) ' Check the &H8000 bit of the return value. Private Sub Command1_Click() Dim keystate As Integer ' state of the Q key ' Get the state of the Q key as returned by the function. ' The code runs when button Command1 is pressed.Print "The Q key has been pressed since the last check." End If End Sub See Also GetKeyState http://216. VK_RMENU The right Alt key.92/vbapi/ref/g/getasynckeystate.

html (3 of 3) [9/1/2002 5:20:56 PM] .com/ref/g/getasynckeystate. Copyright Information Revised October 29.92/vbapi/ref/g/getasynckeystate.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi. Last Modified: July 30. Go back to the Reference section index.Windows API Guide: GetAsyncKeyState Function Category Keyboard Go back to the alphabetical Function listing.html http://216.vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz.26.168. 2000 Go back to the Windows API Guide home page.

hDC. Debug. but Windows can offset the "origin" point determining the adjustment of the brush fill is. brushorg) Debug. Example: ' Display the brush origin point for window Form1.com | www.com | www.com .Print "All brush designs are offset". "pixels right ".dll" (ByVal hdc As Long.168.part of the VB-World Network | www.vbsquare. lpPoint Receives the (x. lpPoint As POINT_TYPE) As Long Platforms: Win 32s. The current brush origin is put into the variable passed as lpPoint.vb-shop.com | www.com | GetBrushOrgEx Function Declare Function GetBrushOrgEx Lib "gdi32.vbforums.3) would shift the fill pattern design 2 pixels right and 3 pixels down.Windows API Guide: GetBrushOrgEx Function vbapi.26. Win NT GetBrushOrgEx determines the origin point for using a brush on a given device is. hdc A device context to the device to find the brush origin point of.com | www.vbworld. The function returns 1 if successful.html (1 of 2) [9/1/2002 5:21:01 PM] . Dim brushorg As POINT_TYPE ' receives brush origin point Dim retval As Long ' return value ' Determine the brush origin and display its coordinates: retval = GetBrushOrgEx(Form1.x. brushorg.92/vbapi/ref/g/getbrushorgex.vbapi. brushorg. "pixels downward. an origin of (2. http://216. All brushes are stored as an 8x8 pixel block. For example.y) coordinate pair of the device's brush origin point. or 0 if an error occured. Win 95/98.y. Go back to the Reference section index." See Also: SetBrushOrgEx Category: Brushes Go back to the alphabetical Function listing.Print "and".

com/ref/g/getbrushorgex.vbapi.Windows API Guide: GetBrushOrgEx Function This page is copyright © 2000 Paul Kuliniewicz.html (2 of 2) [9/1/2002 5:21:01 PM] .168. Copyright Information. Go back to the Windows API Guide home page.26.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getbrushorgex. E-mail: vbapi@vbapi.html http://216.

if another program's window has captured the mouse. Visual Basic-Specific Issues None. if any.1 or later. Constant Definitions Example If a window owned by the program has captured the mouse input.vbshop.com | www.com . Description & Usage GetCapture identifies which window currently has captured the mouse input. The capture is checked when the user clicks button Command1. you must first place a command button named Command1 on a form window.26. this function will not work. However. To use this example.com | www. the function returns a handle to that window.com | GetCapture Function Declare Function GetCapture Lib "user32.com | www.dll" () As Long Platforms q q q q q Windows 95: Supported. display its caption.vbapi. Windows 98: Supported.vbforums.Windows API Guide: GetCapture Function vbapi. inform the user that no program window has captured the mouse. Windows CE: Requires Windows CE 1.part of the VB-World Network | www. the function returns 0.com | www. http://216.vbsquare. If no thread window has captured the mouse.html (1 of 3) [9/1/2002 5:21:06 PM] . this function only works if a window owned by the calling thread. Parameters None. Windows 2000: Supported. If not.92/vbapi/ref/g/getcapture.168.0 or later. Return Value If a window owned by the calling thread has captured the mouse.vbworld. Windows NT: Requires Windows NT 3.

dll" Alias "GetWindowTextA" (ByVal hWnd _ As Long." End If End Sub See Also ReleaseCapture.168. hWndCapture = GetCapture() If hwndCapture = 0 Then Debug. see if a thread window has even captured the mouse. 2000 http://216. *** Private Sub Dim Dim Dim Command1_Click() hWndCapture As Long wintext As String slength As Long ' handle to the window that captured the mouse ' receives the text of the capturing window ' the length of that string ' First. wintext. 2000 This page is copyright © 2000 Paul Kuliniewicz. slength) wintext = Left(wintext.html (2 of 3) [9/1/2002 5:21:06 PM] . Back to the Reference section. ByVal lpString As String. SetCapture Category Mouse Back to the Function list. ByVal nMaxCount As Long) As Long Public Declare Function GetWindowTextLength Lib "user32.Print "This program has not captured the mouse. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.dll" () As Long Public Declare Function GetWindowText Lib "user32. Copyright Information Revised October 29.92/vbapi/ref/g/getcapture.) Public Declare Function GetCapture Lib "user32.26.dll" Alias "GetWindowTextLengthA" _ (ByVal hWnd As Long) As Long ' *** Place the following code inside a form window. slength = GetWindowTextLength(hWndCapture) + 1 wintext = Space(slength) slength = GetWindowText(hWndCapture. Last Modified: August 26.Windows API Guide: GetCapture Function ' This code is licensed according to the terms and conditions listed here. slength) Debug.Print "The window " & Chr(34) & wintext & Chr(34) & " has captured the mouse." Else ' Get the capturing window's text and display it.

26.92/vbapi/ref/g/getcapture.html http://216.com/ref/g/getcapture.html (3 of 3) [9/1/2002 5:21:06 PM] .com Send Encrypted E-Mail This page is at http://www.vbapi. E-mail: vbapi@vbapi.168.Windows API Guide: GetCapture Function Go back to the Windows API Guide home page.

com | www. Windows 2000: Supported but Obsolete. Visual Basic-Specific Issues None.vbapi.0 or later.Windows API Guide: GetClassInfo Function vbapi. ByVal lpClassName As String.html (1 of 3) [9/1/2002 5:21:09 PM] .com .vbsquare.92/vbapi/ref/g/getclassinfo. use GetClassInfoEx instead.com | www. lpClassName The name of the window class to retrieve information about. the function returns a non-zero value. Return Value If an error occured. The information is placed into the structure passed as lpWndClass. or 0 if the window class is defined by the operating system. If successful.vbshop. use GetClassInfoEx instead. Parameters hInstance A handle to the instance which owns the window class.part of the VB-World Network | www.1 or later but Obsolete in Windows NT 3. lpWndClass As WNDCLASS) As Long Platforms q q q q q Windows 95: Supported but Obsolete. Windows 98: Supported but Obsolete.com | GetClassInfo Function Declare Function GetClassInfo Lib "user32. lpWndClass http://216.5 or later. Description & Usage GetClassInfo retrieves most of the information associated with a window class. the function returns 0 (use GetLastError to get the error code).vbforums.168.com | www.vbworld.26. Windows CE: Requires Windows CE 1.dll" Alias "GetClassInfoA" (ByVal hInstance As Long. Windows NT: Requires Windows NT 3. use GetClassInfoEx instead.com | www. use GetClassInfoEx instead.

slength) ' remove the empty space ' Get the information about the window class.hWnd. 255) ' get the name classname = Left(classname. 2000 Go back to the Windows API Guide home page. DI_NORMAL) See Also GetClassInfoEx. Dim classinfo As WNDCLASS ' receives the class information Dim classname As String ' receives the name of the window class Dim slength As Long ' the length of the window class's name Dim retval As Long ' return value ' First. classname.hDC. ' Draw the icon. classinfo) ' Now draw the window class's icon and cursor on window Form1. 0. Example ' This code is licensed according to the terms and conditions listed here.92/vbapi/ref/g/getclassinfo. 50. Go back to the Reference section index. 0. 0.html (2 of 3) [9/1/2002 5:21:09 PM] .hCursor.168. ' Draw the icon and cursor from the window class to which window ' Form1 belongs. 0. 0. Copyright Information Revised October 29. its window class belongs to the application.Windows API Guide: GetClassInfo Function Receives the information about the window class. If it's animated. draw only the first frame of it. 0. 0. 0. The two images are drawn on Form1. 0. retval = DrawIconEx(Form1. Last Modified: August 21. http://216.26. GetClassLong Category Window Classes Go back to the alphabetical Function listing. retval = GetClassInfo(App. get the name of the window class to which Form1 belongs. DI_NORMAL) ' Draw the cursor. classname = Space(255) ' make enough room in the buffer slength = GetClassName(Form1.hDC. classname. 1999 This page is copyright © 1999 Paul Kuliniewicz. 0. retval = DrawIconEx(Form1. classinfo. 0.hInstance. classinfo.hIcon. Since this is a Visual Basic' generated window.

26.com/ref/g/getclassinfo.168.html http://216.html (3 of 3) [9/1/2002 5:21:09 PM] .92/vbapi/ref/g/getclassinfo.vbapi.Windows API Guide: GetClassInfo Function E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.

part of the VB-World Network | www. If successful.com . Visual Basic-Specific Issues None. the function returns 0 (use GetLastError to get the error code). Windows 98: Supported. Windows CE: Not Supported. lpwcx As WNDCLASSEX) As Long Platforms q q q q q Windows 95: Supported. lpwcx Receives the information about the window class.5 or later. http://216. ByVal lpszClass As String.vbshop. Windows NT: Requires Windows NT 3.com | www.168.html (1 of 2) [9/1/2002 5:21:13 PM] .vbapi. Parameters hinst A handle to the instance which owns the window class.com | www. Description & Usage GetClassInfoEx retrieves all of the information associated with a window class.com | www.92/vbapi/ref/g/getclassinfoex.com | GetClassInfoEx Function Declare Function GetClassInfoEx Lib "user32.com | www. Return Value If an error occured. lpszClass The name of the window class to retrieve information about. the function returns a non-zero value.vbworld.vbsquare.dll" Alias "GetClassInfoExA" (ByVal hinst As Long. or 0 if the window class is defined by the operating system.vbforums. The information is placed into the structure passed as lpwcx.26.Windows API Guide: GetClassInfoEx Function vbapi. Windows 2000: Supported.

slength) ' remove the empty space ' Get the information about the window class. 0. DI_NORMAL) See Also GetClassInfo.Windows API Guide: GetClassInfoEx Function Example ' This code is licensed according to the terms and conditions listed here. 0. 0. ' Draw the regular icon. 0. GetClassLong Category Window Classes Go back to the alphabetical Function listing. 0.com/ref/g/getclassinfoex. classname = Space(255) ' make enough room in the buffer slength = GetClassName(Form1.com Send Encrypted E-Mail This page is at http://www.26. retval = DrawIconEx(Form1. 255) ' get the name classname = Left(classname.hWnd. 0. 0. 0. 0.hDC. ' Draw the regular icon and small icon from the window class to which ' window Form1 belongs. Dim classinfo As WNDCLASSEX ' receives the class information Dim classname As String ' receives the name of the window class Dim slength As Long ' the length of the window class's name Dim retval As Long ' return value ' First.168.92/vbapi/ref/g/getclassinfoex. Last Modified: August 21.hIconSm.vbapi.hDC. The two icons are drawn on Form1. classname.hIcon. 50. DI_NORMAL) ' Draw the small icon.html (2 of 2) [9/1/2002 5:21:13 PM] . Since this is a Visual Basic' generated window.hInstance. retval = GetClassInfoEx(App. its window class belongs to the application. 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29. retval = DrawIconEx(Form1. 0. E-mail: vbapi@vbapi. 2000 Go back to the Windows API Guide home page. classinfo. get the name of the window class to which Form1 belongs. classinfo) ' Now draw the window class's regular and small icons on window Form1.html http://216. classname. classinfo. 0. Go back to the Reference section index.

92/vbapi/ref/g/getclasslong. If successful. Windows NT: Requires Windows NT 3. ByVal nIndex As Long) As Long Platforms q q q q q Windows 95: Supported.com | GetClassLong Function Declare Function GetClassLong Lib "user32. the function returns the desired 32-bit value. Description & Usage GetClassLong retrieves a single 32-bit value from the information about the window class to which the specified window belongs.com | www. nIndex To retrieve a 32-bit value from the class's extra memory. inclusive.vbforums.html (1 of 3) [9/1/2002 5:21:24 PM] .dll" Alias "GetClassLongA" (ByVal hWnd As Long.com .vbapi. Valid values are 0 to the number of bytes of extra memory minus 4.Windows API Guide: GetClassLong Function vbapi. To retrieve a 32-bit property of the class.1 or later. Return Value If an error occured.com | www. Parameters hWnd A handle to a window which belongs to the class to read a property of.com | www.part of the VB-World Network | www.168. Windows 98: Supported.vbworld. the function returns 0 (use GetLastError to get the error code). Windows 2000: Supported. set this to one of the following flags specifying which 32-bit value to retrieve from the window class: GCW_ATOM http://216.26. Windows CE: Requires Windows CE 1. set this to the zero-based offset of the byte to begin reading at. This function can also retrieve a 32-bit value from the extra memory area associated with the window class. Visual Basic-Specific Issues None.0 or later. The class's properties may not necessarily match perfectly with the actual properties of the window.vbshop.com | www.vbsquare.

) Public Declare Function GetClassLong Lib "user32. GCL_STYLE Retrieve the window styles associated with the class. GCL_HMODULE Retrieve a handle to the module which registered the class.Windows API Guide: GetClassLong Function Retrieve the atom which identifies the window class. GCL_HCURSOR Retrieve a handle to the cursor associated with the class.168. _ http://216. you must first place a command button named Command1 on a form window. Constant Definitions Const Const Const Const Const Const Const Const Const Const GCW_ATOM = -32 GCL_CBCLSEXTRA = -20 GCL_CBWNDEXTRA = -18 GCL_HBRBACKGROUND = -10 GCL_HCURSOR = -12 GCL_HICON = -14 GCL_HMODULE = -16 GCL_MENUNAME = -8 GCL_STYLE = -26 GCL_WNDPROC = -24 Example When the user clicks button Command1. GCL_HICON Retrieve a handle to the icon associated with the class.92/vbapi/ref/g/getclasslong. GCL_CBCLSEXTRA Retrieve the size in bytes of the extra memory associated with the window class.dll" Alias "GetClassLongA" (ByVal hWnd As Long. draw the icon associated with the parent form window's class in the corner of the client area. This might not be the icon actually displayed by the window.html (2 of 3) [9/1/2002 5:21:24 PM] . GCL_MENUNAME Retrieve a pointer to the string identifying the name of the menu resource associated with the class. to use this exampe.26. Naturally. GCL_HBRBACKGROUND Retrieve a handle to the brush used to paint the backgrounds of windows belonging to the class. GCL_CBWNDEXTRA Retrieve the size in bytes of the extra memory associated with each window belonging to the window class. GCL_HICONSM Retrieve a handle to the small icon associated with the class. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. ' This code is licensed according to the terms and conditions listed here. GCL_WNDPROC Retrieve a pointer to the WindowProc hook function which acts as the window procedure for windows belonging to the window class.

SetClassLong Category Window Classes Go back to the Function listing.26. ByVal hIcon As Long) As Long ' Place the following code inside a form window.0) on Form1.vbapi. 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi. hIcon = GetClassLong(Me.com Send Encrypted E-Mail This page is at http://www. *** Private Sub Command1_Click () Dim hIcon As Long ' handle to the class's icon Dim retval As Long ' return value ' Retrieve a handle to the class's icon. retval = DrawIcon(Me. Copyright Information Revised October 29. 2000 This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/g/getclasslong. Go back to the Reference section index.html http://216. GCL_HICON) ' Draw that icon at coordinate (0.dll" (ByVal hDC As Long.hWnd. ByVal x As Long. hIcon) End Sub See Also GetWindowLong.168. 0.Windows API Guide: GetClassLong Function ByVal nIndex As Long) As Long Public Const GCL_HICON = -14 Public Declare Function DrawIcon Lib "user32.hDC. ByVal y _ As Long.com/ref/g/getclasslong. 0.html (3 of 3) [9/1/2002 5:21:24 PM] . Last Modified: October 29.

0 or later.vbsquare.vb-shop.1 or later.dll" Alias "GetClassNameA" (ByVal hWnd As Long.vbapi. the function returns the number of characters copied into the string passed as lpClassName. Return Value If an error occured.html (1 of 2) [9/1/2002 5:21:29 PM] .com | www. lpClassName http://216.part of the VB-World Network | www. ByVal nMaxCount As Long) As Long Platforms q q q q q Windows 95: Supported. Windows 98: Supported. Parameters hWnd A handle to the window to get the name of the window class of. Windows NT: Requires Windows NT 3.com | GetClassName Function Declare Function GetClassName Lib "user32.com | www.Windows API Guide: GetClassName Function vbapi.92/vbapi/ref/g/getclassname. ByVal lpClassName As String.vbworld. The name of the class is placed into the string passed as lpClassName. Windows CE: Requires Windows CE 1.com | www. Windows 2000: Supported.com | www. the function returns 0 (use GetLastError to get the error code).26. Visual Basic-Specific Issues None. If successful.com . Description & Usage GetClassName retrieves the name of the window class to which a window belongs.168.vbforums.

Print "Form1's window class is: ". 255) ' Extract the useful information from the string and display it.Windows API Guide: GetClassName Function A string which receives the name of the window class.vbapi.26. Example ' This code is licensed according to the terms and conditions listed here.html (2 of 2) [9/1/2002 5:21:29 PM] . 2000 Go back to the Windows API Guide home page.168. slength) ' remove empty space Debug. classname = Space(255) ' much more than enough room ' Get the name of the window class. Go back to the Reference section index. classname Category Window Classes Go back to the alphabetical Function listing.92/vbapi/ref/g/getclassname.html http://216. slength = GetClassName(Form1.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi. Last Modified: August 21. Dim classname As String ' receives the name of the class Dim slength As Long ' length of the string retrieved ' Make room in the string to receive the information.hWnd. nMaxCount The size in bytes of the string passed as lpClassName. classname = Left(classname. Copyright Information Revised October 29. This must first be initialized to a sufficient length to receive the string.com/ref/g/getclassname. 1999 This page is copyright © 1999 Paul Kuliniewicz. ' Display the name of the window class to which window Form1 belongs. classname.

even SetCursorPos cannot free it. lprcReceives the coordinates of the confinement rectangle. Win 95/98. The coordinates of the rectangle is put into lprc.vb-shop.part of the VB-World Network | www.168.vbforums.com | www. Dim r As RECT ' receives coordinates of rectangle Dim retval As Long ' return value retval = GetClipCursor(r) ' read the coordinates and put them into r Debug.26. Example: ' Display the coordinates of the confinement rectangle.92/vbapi/ref/g/getclipcursor. r.Top ' display upper-left (x. it is actually the size of the screen.dll" (lprc As RECT) As Long Platforms: Win 32s.Print r.vbsquare.Bottom ' display lower-right (x. E-mail: vbapi@vbapi.com . The function returns 0 if an error occured. The mouse cursor is confined by using ClipCursor. If there is no apparent confinement rectangle.com | GetClipCursor Function Declare Function GetClipCursor Lib "user32. r.com Send Encrypted E-Mail http://216.Left.y) pair Debug. The cursor is confined inside this rectangle -. Go back to the Reference section index. Go back to the Windows API Guide home page.Right.vbworld.html (1 of 2) [9/1/2002 5:21:34 PM] .vbapi.Print r.com | www. Win NT GetClipCursor finds the current confinement rectangle of the mouse cursor.Windows API Guide: GetClipCursor Function vbapi.com | www.y) pair See Also: ClipCursor Category: Cursor Go back to the alphabetical Function listing. or 1 if it succeeded. Copyright Information. This page is copyright © 2000 Paul Kuliniewicz.com | www.

92/vbapi/ref/g/getclipcursor.168.html http://216.com/ref/g/getclipcursor.html (2 of 2) [9/1/2002 5:21:34 PM] .26.Windows API Guide: GetClipCursor Function This page is at http://www.vbapi.

255) ' get the computer's name ' Remove the trailing null character from the strong compname = Left(compname. Copyright Information.html [9/1/2002 5:21:41 PM] .html http://216.com .part of the VB-World Network | www.com | GetComputerName Function Declare Function GetComputerName Lib "kernel32.vbsquare.vbforums.92/vbapi/ref/g/getcomputername.com | www.com | www. vbNullChar) .com/ref/g/getcomputername.26. Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: GetComputerName Function vbapi.1) Debug. Win NT GetComputerName reads the name of the user's computer. The function returns 0 if an error occured or 1 if successful. Example: ' Display the computer's name Dim compname As String. retval As Long ' string to use as buffer & return value compname = Space(255) ' set a large enough buffer for the computer name retval = GetComputerName(compname.168. This page is copyright © 2000 Paul Kuliniewicz.vbworld.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String. E-mail: vbapi@vbapi. nSize As Long) As Long Platforms: Win 95/98.vbshop.com | www. lpBuffer A string large enough to hold the returned computer name terminated by a null character. The name is put into the string variable passed as lpBuffer. nSize The length in characters of lpBuffer.Print compname ' display name Category: System Information Go back to the alphabetical Function listing. Go back to the Reference section index.com | www.vbapi. InStr(compname.vbapi.

http://216. However.92/vbapi/ref/g/getcurrencyformat. Alternatively. Return Value If an error occured. Windows CE: Requires Windows CE 1. This identifier could be generated by the MAKELCID macro.part of the VB-World Network | www. not including the terminating null character.vbworld. Visual Basic-Specific Issues When passing 0 for the lpFormat parameter.dll" Alias "GetCurrencyFormatA" (ByVal Locale As Long.com | www. ByVal dwFlags As Long. See the example code for a demonstration of this.26. LOCALE_USER_DEFAULT The user's default locale. By default. ByVal cchCurrency As Long) As Long Platforms q q q q q Windows 95: Supported.com | www.vbsquare.com | GetCurrencyFormat Function Declare Function GetCurrencyFormat Lib "kernel32.com | www. the function returns the number of characters copied into the string passed as lpNumberStr.168. Windows 98: Supported. The end result of GetCurrencyFormat is a currency amount displayed according to the user's preferences.com .vbapi. Windows 2000: Supported. Windows NT: Requires Windows NT 3. Parameters Locale The locale identifier of the locale to format the currency value according to. If successful.vbforums. the function formats the currency according to the specified locale's settings. the expression ByVal CLng(0) must be used.com | www. this could be one of the following flags specifying a locale: LOCALE_SYSTEM_DEFAULT The system's default locale. custom formatting preferences can instead be used. ByVal lpCurrencyStr As String.5 or later. the function returns 0 (use GetLastError to get the error code). lpFormat As Any.Windows API Guide: GetCurrencyFormat Function vbapi.0 or later. Description & Usage GetCurrencyFormat formats a currency value for display.html (1 of 4) [9/1/2002 5:21:46 PM] .vbshop. ByVal lpValue As String.

If the number is negative.92/vbapi/ref/g/getcurrencyformat.168. If this is 0. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. regardless of any modifications the user may have made to it.) Public Type CURRENCYFMT NumDigits As Long LeadingZero As Long Grouping As Long lpDecimalSep As String lpThousandSep As String NegativeOrder As Long PositiveOrder As Long lpCurrencySymbol As String End Type Public Declare Function GetCurrencyFormat Lib "kernel32. Any other characters are invalid.567. the current locale settings are used. lpValue A string containing the number to format.89 according to two formatting rules.Windows API Guide: GetCurrencyFormat Function dwFlags If no structure is passed as lpFormat. ByVal cchCurrency As Long) As Long Const LOCALE_USER_DEFAULT = &H800 ' Display the amount of $1. lpCurrencyStr String that receives the null-terminated formatted currency string. Notice how you must not include a currency symbol! lpFormat To override the locale's formatting settings. ByVal lpCurrencyStr As String. The only allowable characters in this string are the digits 0-9 and at most a single decimal point character (. Constant Definitions Const LOCALE_SYSTEM_DEFAULT = &H400 Const LOCALE_USER_DEFAULT = &H800 Const LOCALE_NOUSEROVERRIDE = &H80000000 Example ' This code is licensed according to the terms and conditions listed here.234. this parameter determines the settings used to format the currency value. this could be the following flag: LOCALE_NOUSEROVERRIDE Use the system's default settings for the locale. ByVal lpValue As String. ' 1.26. the first character in the string must be a minus sign character (-). ByVal dwFlags As Long. To use the locale's settings instead. pass a CURRENCYFMT structure that contains the appropriate formatting information. cchCurrency The number of characters in the string passed as lpCurrencyStr. This string must have enough room to receive the string. pass 0 for this parameter.). Use the format specified by the current user locale. http://216.dll" Alias "GetCurrencyFormatA" _ (ByVal Locale As Long. lpFormat _ As Any.html (2 of 4) [9/1/2002 5:21:46 PM] . Or.

. place the $ sign after the digits. _ formatted. Back to the Reference section. formatted. place it in parentheses and put the $ sign after the digits. . ." ' For negative values.Grouping = 3 ' Use a comma to as the decimal point (like they do in France and Spain).Print "Custom format: ". 0.PositiveOrder = 1 ' Use the $ sign to represent the currency. Len(formatted)) formatted = Left(formatted.92/vbapi/ref/g/getcurrencyformat. "1234567.89".168. ByVal CLng(0).LeadingZero = 1 ' Group every three digits to the left of the decimal. .lpDecimalSep = ". "-1234567. .89". _ Len(formatted)) formatted = Left(formatted.html (3 of 4) [9/1/2002 5:21:46 PM] ." ' Likewise. use a period as the grouping separator. . strlen) Debug. cft. formatted = Space(256) strlen = GetCurrencyFormat(LOCALE_USER_DEFAULT.26.NumDigits = 3 ' Display zeros after the decimal point.Print "User locale format: ". formatted ' Now display according the format we specify below. ' custom formatting settings Dim cft As CURRENCYFMT Dim formatted As String ' receives the formatted number strings Dim strlen As Long ' the length of the formatted string ' Display the value formatted according to the current locale. http://216.Windows API Guide: GetCurrencyFormat Function ' 2.lpCurrencySymbol = "$" End With formatted = Space(256) strlen = GetCurrencyFormat(LOCALE_USER_DEFAULT. .lpThousandSep = ". strlen) Debug. formatted See Also GetNumberFormat Category National Language Support Back to the Function list. 0.NegativeOrder = 4 ' For positive values. . Use a custom format specified by a structure passed to the function. With cft ' Display three digits after the decimal point (like in US gasoline prices).

26.html http://216.html (4 of 4) [9/1/2002 5:21:46 PM] .vbapi.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getcurrencyformat.com/ref/g/getcurrencyformat.168. E-mail: vbapi@vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page.Windows API Guide: GetCurrencyFormat Function Last Modified: April 16. Copyright Information Revised October 29.

92/vbapi/ref/g/getcursor.vbforums. The function returns a handle to the cursor picture if successful. IDC_WAIT) ' load the retval = SetCursor(hcursor) ' set the cursor Sleep 3000 ' wait for three seconds retval = SetCursor(holdcursor) ' restore the See Also: SetCursor Category: Cursor Go back to the alphabetical Function listing.com | www.168.vb-shop.com | GetCursor Function Declare Function GetCursor Lib "user32.vbapi. Copyright Information.Windows API Guide: GetCursor Function vbapi.dll" () As Long Platforms: Win 32s. or returns 0 if an error occurs. Dim holdcursor As Long ' receives handle to the original cursor Dim hcursor As Long ' receives handle to the hourglass (wait) cursor Dim retval As Long ' throw-away return value holdcursor = GetCursor() ' get the handle of hcursor = LoadCursor(0. then restore ' the mouse cursor to whatever it was originally.part of the VB-World Network | www. the current mouse cursor hourglass cursor to the hourglass original cursor This page is copyright © 2000 Paul Kuliniewicz.com | www. Example: ' Display the hourglass for three seconds.com . Win 95/98.com | www. Go back to the Windows API Guide home page. http://216.vbworld. Win NT GetCursor finds the handle to the mouse cursor currently in use. This is the cursor that is being used to represent the mouse pointer on the screen.26.html (1 of 2) [9/1/2002 5:21:52 PM] . Go back to the Reference section index.com | www.vbsquare.

html http://216.vbapi.com Send Encrypted E-Mail This page is at http://www.168.26.Windows API Guide: GetCursor Function E-mail: vbapi@vbapi.com/ref/(?/name).92/vbapi/ref/g/getcursor.html (2 of 2) [9/1/2002 5:21:52 PM] .

Go back to the Reference section index.y See Also: SetCursorPos Category: Cursor Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz. Win 95/98.vb-shop.vbapi.com Send Encrypted E-Mail http://216.com | www. coord. The x and y coordinates of the cursor (relative to the screen) are put into the variable passed as lpPoint.html (1 of 2) [9/1/2002 5:21:57 PM] .com | www.part of the VB-World Network | www.com | GetCursorPos Function Declare Function GetCursorPos Lib "user32.x. Win NT GetCursorPos reads the current position of the mouse cursor.com | www.com | www.vbforums.vbsquare.92/vbapi/ref/g/getcursorpos. coord.dll" (lpPoint As POINT_TYPE) As Long Platforms: Win 32s.Windows API Guide: GetCursorPos Function vbapi. lpPoint Receives the x and y coordinates of the mouse cursor. Copyright Information. Example: ' Display the coordinates of the mouse cursor Dim coord As POINT_TYPE ' receives coordinates of cursor Dim retval As Long ' return value retval = GetCursorPos(coord) ' read cursor location Debug.vbworld. The function returns 0 if an error occured or 1 if it is successful.168.Print "The mouse is at:".com .26. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page.

html http://216.com/ref/g/getcursorpos.26.vbapi.92/vbapi/ref/g/getcursorpos.168.Windows API Guide: GetCursorPos Function This page is at http://www.html (2 of 2) [9/1/2002 5:21:57 PM] .

com . Parameters Locale The identifier of the locale to use to format the string as necessary. LOCALE_USER_DEFAULT http://216. Visual Basic-Specific Issues When passing 0 for the lpFormat parameter.26. The date can be formatted using either a predefined format or a custom format specified in the parameter list.com | www.Windows API Guide: GetDateFormat Function vbapi. ByVal lpDateStr As String. This can also be one of the following flags specifying a default locale: LOCALE_SYSTEM_DEFAULT The system's default locale.vbworld.dll" Alias "GetDateFormatA" (ByVal Locale As Long.5 or later. the function returns the size in bytes of the string placed into the variable passed as lpDateStr. If this is 0. If successful. Windows NT: Requires Windows NT 3. the expression CLng(0) must be used.com | www.168. The string generated by this function can be used to present a more human-readable way to display a date.vbforums. lpDate As SYSTEMTIME. Description & Usage GetDateFormat formats a string to display a date according to a locale's settings.vbapi.com | GetDateFormat Function Declare Function GetDateFormat Lib "kernel32.vbsquare. ByVal cchDate As Long) As Long Platforms q q q q q Windows 95: Supported. Windows 2000: Supported. Return Value If an error occured. the function returns 0 (use GetLastError to get the error code).0 or later.html (1 of 4) [9/1/2002 5:22:03 PM] . Windows 98: Supported.com | www. ByVal lpFormat As Any. ByVal dwFlags As Long. Windows CE: Requires Windows CE 1.com | www.92/vbapi/ref/g/getdateformat. the locale of the calling thread is used.part of the VB-World Network | www.vbshop.

LOCALE_NOUSEROVERRIDE Use the system's default date format for the specified locale.168.Windows API Guide: GetDateFormat Function The user's default locale.92/vbapi/ref/g/getdateformat. LOCALE_USE_CP_ACP Use the system's ANSI code page for string translation instead of the locale's code page. ignoring any changes to those defaults which the user may have selected. dwFlags A combination of the following flags specifying how to format the date string. y The last two digits of the year without a leading zero for years between ??00-??09. DATE_USE_ALT_CALENDAR If an alternate calendar exists. lpFormat The format template string used to generate the date string. yy The last two digits of the year with a leading zero for years between ??00-??09. In a format template string.html (2 of 4) [9/1/2002 5:22:03 PM] . To use one of the predefined formats. DATE_LTRREADING Add marks for left-to-right reading layout. yyyy All four digits of the year. MMMM The full name of the month. DATE_RTLREADING Add marks for right-to-left reading layout. dd The day of the month as digits with a leading zero for single-digit days. the following series of characters stand for the following components of the date: d The day of the month as digits without a leading zero for single-digit days. dddd The full name of the day of the week. ddd The three-letter abbreviation for the name of the day of the week. DATE_YEARMONTH Format the date string using the year/month date format. DATE_LONGDATE Format the date string using the long date format. this parameter must be 0. http://216. MM The month as digits with a leading zero for single-digit months. If a format string is passed as lpFormat. MMM The three-letter abbreviation for the name of the month. this parameter must be set to 0. use the default date format of that calendar to format the date string. DATE_SHORTDATE Format the date string using the short date format. M The month as digits without a leading zero for single-digit months. The members of the structure which specify the time are ignored. lpDate The date to format as a string.26.

Dim today As SYSTEMTIME ' today's date and time Dim datestr As String ' receives the formatted date string Dim strlen As Long ' length of the buffer for the formatted date string ' Get today's date and time in the local time zone. strlen) ' Display today's date as a Long Date.Print "Today is ". http://216. today. you must enclose the literal text in single quotation marks.168. cchDate The length of the string passed as lpDateStr. Constant Definitions Const Const Const Const Const Const Const Const Const Const LOCALE_SYSTEM_DEFAULT = &H400 LOCALE_USER_DEFAULT = &H800 LOCALE_NOUSEROVERRIDE = &H80000000 LOCALE_USE_CP_ACP = &H40000000 DATE_SHORTDATE = &H1 DATE_LONGDATE = &H2 DATE_USE_ALT_CALENDAR = &H4 DATE_YEARMONTH = &H8 DATE_LTRREADING = &H10 DATE_RTLREADING = &H20 Example ' This code is licensed according to the terms and conditions listed here. strlen = GetDateFormat(0. datestr = Space(255) ' Format today's date in the format used in HTTP. datestr. datestr ' Now make sufficient room once again. If it is not defined. this string is ignored. ' Display today's date first in the default Long Date format and ' then in the standard HTTP date format. Debug. datestr = Left(datestr.92/vbapi/ref/g/getdateformat. GetLocalTime today ' Make sufficient room in the buffer to receive the date string. CLng(0).26. DATE_LONGDATE.Windows API Guide: GetDateFormat Function gg The period/era string. Any spaces appearing in the template string appear verbatim in the formatted string. Len(datestr)) ' Remove the empty space from the formatted date string. This must initally be sufficiently long to receive the string. To place any other "fixed" characters or text in the format string. lpDateStr Receives the formatted date string. datestr = Space(255) ' Format today's date as a Long Date.html (3 of 4) [9/1/2002 5:22:03 PM] . if defined for the locale.

com/ref/g/getdateformat.html (4 of 4) [9/1/2002 5:22:03 PM] . Len(datestr)) ' Remove the empty space from the formatted string.html http://216. 2000 This page is copyright © 2000 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page. datestr See Also GetTimeFormat Category National Language Support Go back to the alphabetical Function listing.Print "Today is ". today. Copyright Information Revised October 29. Go back to the Reference section index.92/vbapi/ref/g/getdateformat.168.' dd MMM yyyy".com Send Encrypted E-Mail This page is at http://www. datestr.26. strlen) ' Display today's date in the HTTP-style format. Last Modified: January 1. datestr = Left(datestr. E-mail: vbapi@vbapi.Windows API Guide: GetDateFormat Function strlen = GetDateFormat(0.vbapi. "ddd'. Debug. 0.

Go back to the Reference section index.vbforums. hWnd The handle of the object or device to get the device context of.com | GetDC Function Declare Function GetDC Lib "user32. deskhdc) context See Also: CreateDC. you should use ReleaseDC to free up system resources.com | www. Win NT GetDC returns the device context (DC) of a window or other device.html http://216.. Copyright Information.vbapi.168.Windows API Guide: GetDC Function vbapi. given the object's handle.html [9/1/2002 5:22:22 PM] .com/ref/g/getdc. pass the function a handle to a file) or another error occurs.vbworld. When you are finished using the device context. Example: ' Find the device context of the desktop Dim deskhwnd As Long ' handle to the desktop Dim deskhdc As Long ' device context to the desktop Dim retval As Long ' return value deskhwnd = GetDesktopWindow() ' get the desktop's handle deskhdc = GetDC(deskhwnd) ' get the desktop's device context ' You could put any code that works with the desktop here retval = ReleaseDC(deskhwnd. Win 95/98.vbshop. ' free up resources associated with the device This page is copyright © 2000 Paul Kuliniewicz. the function will instead return 0.e.vbapi. Go back to the Windows API Guide home page.com . If you try to get the device context of something that is not a device (i.26. Do not use DeleteDC to destroy the device context when you are done. ReleaseDC Category: Devices Go back to the alphabetical Function listing.part of the VB-World Network | www.vbsquare.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getdc. E-mail: vbapi@vbapi.dll" (ByVal hWnd As Long) As Long Platforms: Win 32s.com | www.com | www.com | www.

com | www.vbshop. The desktop window is the window that makes up the desktop of the computer -.92/vbapi/ref/g/getdesktopwindow.com | www.168.26. Win NT GetDesktopWindow returns a handle to the desktop window.that is.vbsquare.com/ref/g/getdesktopwindow.dll" () As Long Platforms: Win 32s.168.html [9/1/2002 5:22:27 PM] .com | www.com | www.com . If the function fails. ' free up resources associated with the device This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.vbapi. the screen.http://216.vbforums.com | GetDesktopWindow Function Declare Function GetDesktopWindow Lib "user32. Go back to the Windows API Guide home page.vbapi. E-mail: vbapi@vbapi. Go back to the Reference section index. Win 95/98. deskhdc) context Category: Windows Go back to the alphabetical Function listing.part of the VB-World Network | www. it will return 0 instead of the handle.html vbapi.com Send Encrypted E-Mail This page is at http://www.vbworld.26.92/vbapi/ref/g/getdesktopwindow. Example: ' Find the device context of the desktop ' The handle to the desktop is needed to find the device context Dim deskhwnd As Long ' handle to the desktop Dim deskhdc As Long ' device context to the desktop Dim retval As Long ' return value deskhwnd = GetDesktopWindow() ' get the desktop's handle deskhdc = GetDC(deskhwnd) ' get the desktop's device context ' You could put any code that works with the desktop here retval = ReleaseDC(deskhwnd.html http://216.

Windows NT: Requires Windows NT 3.vb-shop.com | GetDiskFreeSpace Function Declare Function GetDiskFreeSpace Lib "kernel32. Windows 98: Supported but Obsolete.part of the VB-World Network | www. the function returns 0 (use GetLastError to determine the error code).com .vbworld.168. This information includes the number of sectors in each cluster. the function returns a non-zero value. use GetDiskFreeSpaceEx instead.com | www. Due to the limitations of the 32-bit integer data type.92/vbapi/ref/g/getdiskfreespace.vbapi.0 or later. lpBytesPerSector As Long.html (1 of 3) [9/1/2002 5:22:32 PM] . The replacement function GetDiskFreeSpaceEx does not have this limitation.com | www. lpNumberOfFreeClusters As Long.dll" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String.com | www. Return Value If an error occured.26. Visual Basic-Specific Issues None Parameters http://216. Windows 2000: Supported but Obsolete. Windows CE: Not Supported. this function only works properly with disks with a capacity less than 2 MB. lpSectorsPerCluster As Long. the number of free clusters.Windows API Guide: GetDiskFreeSpace Function vbapi. use GetDiskFreeSpaceEx instead. use GetDiskFreeSpaceEx instead.vbforums. and the total number of clusters.com | www.vbsquare. If successful. use GetDiskFreeSpaceEx instead. Description & Usage GetDiskFreeSpace retrives information about the amount of space on a disk. the number of bytes in each sector.1 or later but obsolete in Windows NT 4. lpTotalNumberOfClusters As Long) As Long Platforms q q q q q Windows 95: Supported but Obsolete with OEM Service Release 2 (OEM2) or later.

totalClus * secPerClus * bytePerSec. bytePerSec. used and unused.92/vbapi/ref/g/getdiskfreespace. freeClus.Print "Total space:".Windows API Guide: GetDiskFreeSpace Function lpRootPathName The root directory of the disk to get information on. http://216. Go back to the Reference section index. empty clusters on the disk. secPerClus. freeClus * secPerClus * bytePerSec. Example ' This code is licensed according to the terms and conditions listed here.168. lpBytesPerSector 32-bit integer variable which receives the number of bytes in a sector on the disk.html (2 of 3) [9/1/2002 5:22:32 PM] . ' Calculate and display the free and total space on drive C: Dim secPerClus As Long ' receives sectors per cluster Dim bytePerSec As Long ' receives bytes per sector Dim freeClus As Long ' receives number of free clusters Dim totalClus As Long ' receives total number of clusters Dim retval As Long ' return value ' Read the information into the variables retval = GetDiskFreeSpace("c:\". Windows 2000: This may be lower than the actual value if per-user quotas are enabled. on the disk. such as "c:\" or "a:\" lpSectorsPerCluster 32-bit integer variable which receives the number of sectors in a cluster on the disk. lpTotalNumberOfClusters 32-bit integer variable which receives the total number of clusters. totalClus) ' Display the information Debug.26.Print "Free space:". "bytes" Debug. Windows 2000: This may be lower than the actual value if per-user quotas are enabled. lpNumberOfFreeClusters 32-bit integer variable which receives the number of unused. "bytes" See Also GetDiskFreeSpaceEx Category Files Go back to the alphabetical Function listing.

1999 This page is copyright © 1999 Paul Kuliniewicz.Windows API Guide: GetDiskFreeSpace Function Last Modified: July 25.html http://216. E-mail: vbapi@vbapi.com/ref/g/getdiskfreespace.html (3 of 3) [9/1/2002 5:22:32 PM] . 2000 Go back to the Windows API Guide home page. Copyright Information Revised October 29.26.vbapi.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getdiskfreespace.168.

If successful. lpFreeBytesAvailableToCaller Unsigned 64-bit integer variable which receives the amount of free disk space available. It finds the free space available to the current user. Visual Basic-Specific Issues None.com | www.com | GetDiskFreeSpaceEx Function Declare Function GetDiskFreeSpaceEx Lib "kernel32. that can be used instead.html (1 of 3) [9/1/2002 5:22:37 PM] .0 or later. (If your programming language supplies an intrinsic unsigned 64-bit integer data type. lpFreeBytesAvailableToCaller As ULARGE_INTEGER. http://216. Windows NT: Requires Windows NT 4. to the user. Description & Usage GetDiskFreeSpaceEx determines information about the size of a disk. While this can be the name of the disk's root directory. it doesn't have to be.Windows API Guide: GetDiskFreeSpaceEx Function vbapi. Windows 2000: Supported. the function returns 0 (use GetLastError to retrieve the error code).vbforums.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String. lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long Platforms q q q q q Windows 95: Requires OEM Service Release 2 (OSR2) or later.vbsquare.168.com | www.com . in bytes. Windows 2000: This may be lower than the actual value if per-user disk space quotas are enabled. lpTotalNumberOfBytes As ULARGE_INTEGER. and the amount of free space (all in bytes).com | www.92/vbapi/ref/g/getdiskfreespaceex. Each value is placed into a ULARGE_INTEGER structure which can hold the unsigned 64-bit integer values.part of the VB-World Network | www. the total disk space. Windows 98: Supported.) Return Value If an error occured. Windows CE: Not Supported.vbapi. Parameters lpDirectoryName The name of a directory on the disk to retrieve the size information about.com | www.vbshop.26. the function returns a non-zero value.vbworld.

CopyMemory tempval. retval = GetDiskFreeSpaceEx("C:\".92/vbapi/ref/g/getdiskfreespaceex. ByVal Length As Long) ' *** Place the following code inside the form window. "bytes" End Sub http://216. Source _ As Any.html (2 of 3) [9/1/2002 5:22:37 PM] . in bytes. 8 ' Multiply by 10.26. ' This code is licensed according to the terms and conditions listed here. Debug. *** Private Sub Dim Dim Dim Dim Dim Command1_Click() userbytes As ULARGE_INTEGER totalbytes As ULARGE_INTEGER freebytes As ULARGE_INTEGER tempval As Currency retval As Long ' ' ' ' ' bytes free to user total bytes on disk free bytes on disk display buffer for 64-bit values generic return value ' Get information about the C: drive.dll" Alias "RtlMoveMemory" (Destination As Any. Windows 2000: This may be lower than the actual value if per-user disk space quotas are enabled.Print "Free Space on the C: drive:". This example runs when the user click button Command1. you need to place a command button named Command1 on a form window. lpTotalNumberOfFreeBytes Unsigned 64-bit integer variable which receives the amount of free disk space. lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long Public Declare Sub CopyMemory Lib "kernel32.168. the workaround described on this page is needed to display the values properly. totalbytes. so to use this example. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. freebytes.) Public Type ULARGE_INTEGER LowPart As Long HighPart As Long End Type Public Declare Function GetDiskFreeSpaceEx Lib "kernel32. in bytes. tempval. lpFreeBytesAvailableToCaller As ULARGE_INTEGER.000 to move Visual Basic's decimal point to the end of the actual number. userbytes. tempval = tempval * 10000 ' Display the amount of free space on C:. _ lpTotalNumberOfBytes As ULARGE_INTEGER. Example Display the total free space available on drive C:.Windows API Guide: GetDiskFreeSpaceEx Function lpTotalNumberOfBytes Unsigned 64-bit integer variable which receives the amount of total disk space. freebytes) ' Copy freebytes into the Currency data type. Because Visual Basic doesn't have good support for the 64-bit integers needed for modern hard drive's free spaces.dll" Alias "GetDiskFreeSpaceExA" (ByVal _ lpDirectoryName As String.

Copyright Information Revised October 29.92/vbapi/ref/g/getdiskfreespaceex.html http://216.Windows API Guide: GetDiskFreeSpaceEx Function See Also GetDiskFreeSpace Category Files Go back to the Function listing.com/ref/g/getdiskfreespaceex. 2000 This page is copyright © 2000 Paul Kuliniewicz.html (3 of 3) [9/1/2002 5:22:37 PM] . E-mail: vbapi@vbapi. Last Modified: September 24.vbapi. Go back to the Reference section index. 2000 Go back to the Windows API Guide home page.168.26.com Send Encrypted E-Mail This page is at http://www.

Windows API Guide: GetDoubleClickTime Function vbapi.vbsquare.92/vbapi/ref/g/getdoubleclicktime.168. Dim doubletime As Long ' receives double click time doubletime = GetDoubleClickTime() ' get the maximum double click time Debug.vbapi.26.com | www.com | www.html http://216. Win NT GetDoubleClickTime determines the maximum time allowed between successive mouse clicks for Windows to interpret it as a double click (along with negligible mouse movement).com .vbshop. Win 95/98.com | www.part of the VB-World Network | www.com Send Encrypted E-Mail This page is at http://www.com | GetDoubleClickTime Function Declare Function GetDoubleClickTime Lib "user32. Go back to the Reference section index. Copyright Information. The function returns the maximum double click time.vbapi.Print doubletime. "milliseconds are allowed between clicks during a double click.html [9/1/2002 5:22:42 PM] . Example: ' Display the maximum amount of time between clicks to ' consider the operation a double click.com/ref/g/getdoubleclicktime. E-mail: vbapi@vbapi." See Also: SetDoubleClickTime Category: Mouse Go back to the alphabetical Function listing. Go back to the Windows API Guide home page.vbforums.com | www.dll" () As Long Platforms: Win 32s. This page is copyright © 2000 Paul Kuliniewicz.vbworld. The maximum time between clicks is given in milliseconds.

dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long Platforms: Win 32s." If drivetype = DRIVE_REMOVABLE Then Print "Drive D:\ is a removable-disk drive.vbworld.com | www.vbsquare. Win NT GetDriveType finds the type of disks a disk drive is/uses. nDrive The root directory of the drive to check. DRIVE_RAMDISK = 6 A RAM disk.part of the VB-World Network | www. Go back to the Reference section index. Win 95/98.Print "Drive D:\ does not exist.vbshop. Category: Files Go back to the alphabetical Function listing.168. DRIVE_REMOTE = 4 A network drive or a drive located on a network server.vbforums." If drivetype = DRIVE_FIXED Then Print "Drive D:\ is a hard drive. Other return values are one of the following flags identifying the drive type: DRIVE_CDROM = 5 A CD-ROM drive. such as "c:\" or "a:\" Example: ' Determine what type of drive D: is Dim drivetype As Long ' receives the drive type drivetype = GetDriveType("d:\") ' determine which kind of drive this is If drivetype = 1 Then Debug. DRIVE_FIXED = 3 A hard drive.26. The function returns the drive type. etc. DRIVE_REMOVABLE = 2 A floppy drive or some other removable-disk drive." If drivetype = DRIVE_CDROM Then Print "Drive D:\ is a CD-ROM drive. 0 means that an error occured. a floppy drive.com | GetDriveType Function Declare Function GetDriveType Lib "kernel32.com | www. a CDROM drive.com | www. 1 means that the specified drive does not exist.92/vbapi/ref/g/getdrivetype.vbapi.com . http://216. This could be a fixed (hard) drive." ' etc.com | www.html (1 of 2) [9/1/2002 5:22:45 PM] .Windows API Guide: GetDriveType Function vbapi.

com Send Encrypted E-Mail This page is at http://www.Windows API Guide: GetDriveType Function This page is copyright © 2000 Paul Kuliniewicz.com/ref/g/getdrivetype.168.vbapi.26.html http://216. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:22:45 PM] . Copyright Information.92/vbapi/ref/g/getdrivetype.

1 or later.168.vbapi. Windows CE: Not Supported.html (1 of 3) [9/1/2002 5:22:51 PM] . Visual Basic-Specific Issues None. The value is placed into the string buffer passed as the lpBuffer parameter. the function returns the necessary minimum buffer length. http://216.vbworld.com | GetEnvironmentVariable Function Declare Function GetEnvironmentVariable Lib "kernel32.com | www.vbforums. Windows 2000: Supported. This string must be sufficiently long to receive the value copied into it. If successful.vbsquare. Windows NT: Requires Windows NT 3. Windows 98: Supported. the function returns zero. If the string passed as lpBuffer was too short to receive the environment variable's value. not counting the terminating null character. nSize The length of the string passed as lpBuffer.part of the VB-World Network | www. Description & Usage GetEnvironmentVariable reads the value of one of the computer's environment variables. lpBuffer Receives the value of the environment variable.com | www.Windows API Guide: GetEnvironmentVariable Function vbapi.92/vbapi/ref/g/getenvironmentvariable.26. Return Value If the specified environment variable does not exist. the function returns the length of the string copied into lpBuffer.vbshop. ByVal lpBuffer As String.com .dll" Alias "GetEnvironmentVariableA" (ByVal lpName As String. Parameters lpName The name of the environment variable to read. ByVal nSize As Long) As Long Platforms q q q q q Windows 95: Supported.com | www.com | www.

168.92/vbapi/ref/g/getenvironmentvariable. But then again.Windows API Guide: GetEnvironmentVariable Function Example Read the BLASTER environment variable. this is just an example of how to use GetEnvironmentVariable. envvar End If End Sub See Also SetEnvironmentVariable Category Processes & Threads Back to the Function list. The example runs when button Command1 is clicked. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. so you must place a command button named Command1 on a form window before running this example. ByVal lpBuffer As String. Len(envvar)) If slength = 0 Then Debug.26. slength = GetEnvironmentVariable("BLASTER". ' This code is licensed according to the terms and conditions listed here. which contains some information about the Sound Blaster configuration on the computer. Typically. envvar. *** Private Sub Command1_Click() Dim envvar As String ' receives the value of the environment variable Dim slength As Long ' length of the string copied into envvar ' Make enough room in envvar to receive the data. slength) Debug. so it isn't very useful for Windows applications.) Public Declare Function GetEnvironmentVariable Lib "kernel32. envvar = Space(256) ' Read the value of the BLASTER environment variable.html (2 of 3) [9/1/2002 5:22:51 PM] .dll" Alias "GetEnvironmentVariableA" (ByVal _ lpName As String. envvar = Left(envvar. ByVal nSize As Long) As Long ' *** Place the following code inside a form window.Print "The BLASTER environment variable does not exist on this system. this variable is only used by DOS programs. http://216." Else ' Remove the terminating null and everything following it. Back to the Reference section.Print "BLASTER = ".

26. 2000 Go back to the Windows API Guide home page.168.com/ref/g/getenvironmentvariable.Windows API Guide: GetEnvironmentVariable Function Last Modified: August 26.com Send Encrypted E-Mail This page is at http://www.html http://216.vbapi. Copyright Information Revised October 29.html (3 of 3) [9/1/2002 5:22:51 PM] .92/vbapi/ref/g/getenvironmentvariable. 2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi.

com | www. If the function fails.26.vbforums.dll" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long Platforms: Win 32s.html (1 of 2) [9/1/2002 5:22:56 PM] .exe Dim attribs As Long ' receives file attributes attribs = GetFileAttributes("C:\Files\program.92/vbapi/ref/g/getfileattributes. Win NT GetFileAttributes returns the attributes of a file or a directory.com | GetFileAttributes Function Declare Function GetFileAttributes Lib "kernel32.com . FILE_ATTRIBUTE_READONLY = &H1 A read-only file.168. it will return 0.vbsquare. lpFileName The full name of the file or directory to check the attributes of. it will return -1. Example: ' Display the attributes of C:\Files\program. used exclusively by the operating system.com | www.Print "Hidden" http://216. Win 95/98. FILE_ATTRIBUTE_COMPRESSED = &H800 A file residing in a compressed drive or directory. the return value will be one or more of the following file attribute flags: FILE_ATTRIBUTE_ARCHIVE = &H20 An archive file (which most files are). Otherwise.Windows API Guide: GetFileAttributes Function vbapi.vbapi. not normally visible to the user. FILE_ATTRIBUTE_DIRECTORY = &H10 A directory instead of a file.part of the VB-World Network | www. Attributes determine such things as read-only status. hidden status.vbworld. including the full path.exe") ' read file attributes If (attribs And FILE_ATTRIBUTES_ARCHIVE) <> 0 Then Debug. archive status (most files are).com | www. etc.vb-shop. FILE_ATTRIBUTE_SYSTEM = &H4 A system file.com | www. FILE_ATTRIBUTE_NORMAL = &H80 An attribute-less file (cannot be combined with other attributes).Print "Archive" If (attribs And FILE_ATTRIBUTES_HIDDEN) <> 0 Then Debug. If the file or directory cannot be found. FILE_ATTRIBUTE_HIDDEN = &H2 A hidden file.

92/vbapi/ref/g/getfileattributes.Print "Read-only" ' etc. Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.168.Windows API Guide: GetFileAttributes Function If (attribs And FILE_ATTRIBUTES_READONLY) <> 0 Then Debug.vbapi. Go back to the Reference section index. SetFileAttributes Category: Files Go back to the alphabetical Function listing.html http://216.html (2 of 2) [9/1/2002 5:22:56 PM] . See Also: GetFileInformationByHandle. This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi... Copyright Information.26.com/ref/g/getfileattributes..

OPEN_EXISTING.com | www. using hexadecimal: retval = GetFileInformationByHandle(hfile.see its page for details. Also note that the alternate declare ' of CreateFile must be used here since we're using Win 95/98 -.part of the VB-World Network | www." End ' abort the program End If ' Display the serial number. All of this information is put into the structure passed as lpFileInformation. Win NT GetFileInformationByHandle determines various information about a file.com | www.168. or 1 if successful. fileinfo) ' read the information hexstring = Hex(fileinfo.com | www. Note that here we ' aren't interested in the other information we receive.in other words.dwVolumeSerialNumber) ' get the hexadecimal value of the serial number http://216. and the its unique numeric identifier.vbshop. the number of links to it in the file system. the size of the file.vbapi.92/vbapi/ref/g/getfileinformationbyhandle.html (1 of 2) [9/1/2002 5:23:03 PM] . its creation.vbsquare. 0) If hfile = -1 Then ' if the file could not be opened Debug. The function returns 0 if an error occured. last-access.com | www. FILE_SHARE_READ.vbworld.txt". This information includes the file's attributes. hFile A handle to the file to get the information of. we are finding the serial number of drive C:. 0.com | GetFileInformationByHandle Function Declare Function GetFileInformationByHandle Lib "kernel32. FILE_ATTRIBUTE_ARCHIVE. lpFileInformation Receives the information (specified above) relating to the file.vbforums.txt.Windows API Guide: GetFileInformationByHandle Function vbapi. the serial number of the disk the file is on. lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long Platforms: Win 32s.txt ' is on -. GENERIC_READ.dll" (ByVal hFile As Long.com . Example: ' Display the serial number of the disk that file C:\MyProgram\datafile. Win 95/98.26. and last-modified dates and times. Dim hfile As Long ' receives the handle to the file Dim fileinfo As BY_HANDLE_FILE_INFORMATION ' receives info about the file Dim hexstring As String ' will receive the hexadecimal form of the serial number Dim retval As Long ' return value ' Get a handle to the file (note how the alternate declare is used): hfile = CreateFileNS("C:\MyProgram\datafile.Print "Could not open the file C:\MyProgram\datafile.

vbapi. GetFileTime Category: Files Go back to the alphabetical Function listing.92/vbapi/ref/g/getfileinformationbyhandle. Copyright Information.168.Print "The serial number of C: is ".com/ref/g/getfileinformationbyhandle.Windows API Guide: GetFileInformationByHandle Function If Len(hexstring) < 8 Then ' if the string is less than 8 characters. Go back to the Reference section index.com Send Encrypted E-Mail This page is at http://www. hexstring = String("0". GetFileSize. Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:23:03 PM] . This page is copyright © 2000 Paul Kuliniewicz.html http://216. 8 . hexstring ' Close the file: retval = CloseHandle See Also: GetFileAttributes. E-mail: vbapi@vbapi.Len(hexstring)) & hexstring ' then right-pad it with "0"s End If Debug.26.

29 GB!) ' Visual Basic has no 64-bit variables.26. hfile = CreateFileNS("C:\MyProgram\datafile. The file must be opened with at least either read-level or write-level access.vbworld. GENERIC_READ. OPEN_EXISTING.txt".com | www.txt".txt" End ' abort the program End If ' Read and display that file's size in bytes. 0. The file size is given in a 64-bit value that is split into two 32-bit values.and high-order halves of the file size Dim retval As Long ' return value ' Get a handle to the file using CreateFile's alternate declare (necessary for nonWin NT).vbapi.com | www.com | GetFileSize Function Declare Function GetFileSize Lib "kernel32. "bytes" ' display the file size Else ' if there is a high-order part (file size >= 4.com | www. highorder.Print "Could not open file C:\MyProgram\datafile. Example: ' Display the file size of "C:\MyProgram\datafile. To get the size. hFile A handle to the file to determine the size of. FILE_ATTRIBUTE_ARCHIVE.vbshop. Win 95/98. "bytes (in base-10)" ' But we can combine the two hex values to give the result in hexadecimal: http://216.html (1 of 2) [9/1/2002 5:23:10 PM] . you can either put the binary or hexadecimal values of the two variables side-by-side.Print "File size:".vbforums.vbsquare.Windows API Guide: GetFileSize Function vbapi.dll" (ByVal hFile As Long. Dim hfile As Long ' receives a handle to the file Dim loworder As Long. the low-order half is returned by the function.Print "File size:".92/vbapi/ref/g/getfilesize. lpFileSizeHigh As Long) As Long Platforms: Win 32s. If an error occurs. highorder As Long ' receive the low. highorder = 0 ' initialize the value for high-order half loworder = GetFileSize(hfile. so we can't display the actual value: Debug. "* 2^32 +". lpFileSizeHigh Variable that receives the high-order half of the file size. loworder. The highorder half is put into the variable passed as lpFileSizeHigh. 0) If hfile = -1 Then ' error opening the file Debug.see that function's page for details. the function instead returns -1. Note how ' the alternate declare of the CreateFile function (needed to get the file's handle) ' must be used -.168. loworder.part of the VB-World Network | www. FILE_SHARE_READ.com | www. or use the formula filesize = lpFileSizeHigh * 2^32 + return value. Win NT GetFileSize determines the size of the file.com . highorder) ' read the file's size If highorder = 0 Then ' if there is no high-order part Debug.

" bytes (in hexadecimal)" End If ' Close the file retval = CloseHandle(hfile) See Also: GetFileInformationByHandle Category: Files Go back to the alphabetical Function listing.com Send Encrypted E-Mail This page is at http://www.com/ref/g/getfilesize.html http://216.26. E-mail: vbapi@vbapi.Windows API Guide: GetFileSize Function Debug. Go back to the Windows API Guide home page.92/vbapi/ref/g/getfilesize. Copyright Information.168. ' close the handle This page is copyright © 2000 Paul Kuliniewicz.vbapi. Hex(loworder). Go back to the Reference section index.Print "File size: ". Hex(highorder).html (2 of 2) [9/1/2002 5:23:10 PM] .

last access. lpLastAccessTime Receives the time and date of when the file was last accessed. last access.1 or later. http://216. Visual Basic-Specific Issues None.vbapi.com | www. Windows NT: Requires Windows NT 3.0 or later.26. Parameters hFile A handle to the file to obtain the creation. Greenwich Mean Time (GMT)). a.com | GetFileTime Function Declare Function GetFileTime Lib "kernel32. the function returns a non-zero value.vbforums. and last modification (write-to) of a file. the exact resolution of file times may vary -.92/vbapi/ref/g/getfiletime. The file must have been opened with at least read-level access. and last modification times and dates of.vbshop.dll" (ByVal hFile As Long.com .a.html (1 of 3) [9/1/2002 5:23:14 PM] .vbsquare.vbworld. the function returns 0 (use GetLastError to get the error code).26. Note that. If successful. depending on the operating system. Description & Usage GetFileTime determines the times and dates of creation. Windows CE: Requires Windows CE 1.92/vbapi/ref/g/getfiletime.the file times obtained by the function may not correspond to the actual date and time of creation/access/modification simply because the operating system does not store the information that precisely. Return Value If an error occured.html vbapi. Each of these times are placed in the corresponding structures passed to the function.k. Windows 98: Supported.com | www. All times obtained by the function are in UTC time (Coordinated Universal Time. lpCreationTime As FILETIME. lpLastAccessTime As FILETIME.com | www.http://216.com | www. lpLastWriteTime As FILETIME) As Long Platforms q q q q q Windows 95: Supported. Windows 2000: Supported. not in the system's local time.168. lpCreationTime Receives the time and date of when the file was created.168.part of the VB-World Network | www.

html lpLastWriteTime Receives the time and date of when the file was last written to or modified. mtime) ' Convert the creation time to the local time zone. "-".http://216.26.aborting. retval = FileTimeToLocalFileTime(ctime. get the creation. thetime. SetFileTime Category Files Go back to the alphabetical Function listing. retval = CloseHandle(hFile) See Also GetFileInformationByHandle. and last-modification times. Dim hFile As Long ' handle to the opened file Dim ctime As FILETIME ' receives time of creation Dim atime As FILETIME ' receives time of last access Dim mtime As FILETIME ' receives time of last modification Dim thetime As SYSTEMTIME ' used to manipulate the time Dim retval As Long ' return value ' First. ' Display the date on which the file C:\MyApp\test.Print "Could not open the file successfully -. Debug.txt". ctime) ' Convert the FILETIME format to the SYSTEMTIME format.26. open the file C:\MyApp\test. thetime.wYear ' Close the file to free up resources. last-access. 0) If hFile = -1 Then Debug.168. ctime.wMonth. "-". Example ' This code is licensed according to the terms and conditions listed here.txt for read-level access.wDay. ByVal CLng(0).92/vbapi/ref/g/getfiletime. retval = GetFileTime(hFile." End ' terminate the program End If ' Next.Print "The file was created on ".txt was ' created. hFile = CreateFile("C:\MyApp\test.html (2 of 3) [9/1/2002 5:23:14 PM] . GENERIC_READ.168. FILE_ATTRIBUTE_ARCHIVE. thetime. atime. OPEN_EXISTING.92/vbapi/ref/g/getfiletime. Note how the time zone conversion is necessary. FILE_SHARE_READ. Note the ' expression necessary to pass 0 as lpSecurityAttributes. thetime) ' Display the date of creation of the file to the user. http://216. retval = FileTimeToSystemTime(ctime.

168.html http://216.92/vbapi/ref/g/getfiletime.com/ref/g/getfiletime.vbapi.92/vbapi/ref/g/getfiletime.html Go back to the Reference section index. 2000 Go back to the Windows API Guide home page.26.168.http://216.com Send Encrypted E-Mail This page is at http://www. 1999 This page is copyright © 1999 Paul Kuliniewicz.26. E-mail: vbapi@vbapi. Last Modified: October 1. Copyright Information Revised October 29.html (3 of 3) [9/1/2002 5:23:14 PM] .

Visual Basic-Specific Issues None. lpData A buffer. Description & Usage GetFileVersionInfo extracts the version information resource stored inside a 32-bit executable-type file.part of the VB-World Network | www. the function returns a non-zero value.com | GetFileVersionInfo Function Declare Function GetFileVersionInfo Lib "version.vbsquare. such as a byte array. Windows NT: Requires Windows NT 3.92/vbapi/ref/g/getfileversioninfo.vbapi.set to 0. Parameters lpstrFilename The full path and filename of the file.vbshop.26. Return Value If successful.com | www. Windows 2000: Supported.com | www.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String. dwHandle Reserved -.Windows API Guide: GetFileVersionInfo Function vbapi. Windows 98: Supported.html (1 of 5) [9/1/2002 5:23:22 PM] . If an error occured. the function returns 0 (use GetLastError to get the error code). dwLen The size in bytes of the buffer passed as lpData. Windows CE: Not Supported. ByVal dwLen As Long.com . The version information resource is a series of bytes that is difficult to read directly. ByVal dwHandle As Long.vbforums. that receives the version information resource of the file.com | www. http://216.vbworld.com | www.1 or later. Use the VerQueryValue to retrieve the desired pieces of data from the resource.168. lpData As Any) As Long Platforms q q q q q Windows 95: Supported.

Obviously.html (2 of 5) [9/1/2002 5:23:22 PM] . ByVal lpSubBlock As String.92/vbapi/ref/g/getfileversioninfo. lpdwHandle As Long) As Long Public Declare Function VerQueryValue Lib "version. ByVal lpString2 As Any) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 _ As Any. Display the version number. lplpBuffer As Long. _ lpData As Any) As Long Public Declare Function GetFileVersionInfoSize Lib "version.) Public Declare Function GetFileVersionInfo Lib "version. To use this example. and file description when button Command1 is pressed.Windows API Guide: GetFileVersionInfo Function Example Display information about the file whose full path and filename is entered into textbox Text1.168. ByVal dwLen As Long. ByVal Length As Long) Public Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersion As Long dwFileVersionMS As Long dwFileVersionLS As Long dwProductVersionMS As Long dwProductVersionLS As Long dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Public Const VFT_APP = &H1 Public Const VFT_DLL = &H2 Public Const VFT_DRV = &H3 Public Const VFT_VXD = &H5 ' *** Place the following function definitions inside a module.dll" Alias "GetFileVersionInfoA" _ (ByVal lptstrFilename As String.26. copyright information. _ Source As Any. *** http://216. ByVal dwHandle As Long. into Text1. you obviously have to enter the filename of a 32-bit executable/DLL/etc. this example requires that you create a text box called Text1 and a command button called Command1. puLen As Long) As Long Public Declare Function lstrcpy Lib "kernel32. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.dll" Alias "RtlMoveMemory" (Destination As Any.dll" Alias _ "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String.dll" Alias "VerQueryValueA" (pBlock _ As Any. ' This code is licensed according to the terms and conditions listed here.

byte2 As Byte) byte1 = byte1 Xor byte2 byte2 = byte1 Xor byte2 byte1 = byte1 Xor byte2 End Sub ' This function creates a hexadecimal string to represent a number.168.1) As Byte ' Get the version information resource. ' This technique. Public Sub SwapByte (byte1 As Byte. ByVal nDigits As Long) As String FixedHex = Right("00000000" & Hex(hexval).Text. works as long as the two values to be swapped are ' numeric and of the same data type (here. nDigits) End Function ' *** Place the following code inside the form that has Command1 and Text1. *** Private Sub Dim Dim Dim Dim Dim Dim Dim Dim Command1_Click() vffi As VS_FIXEDFILEINFO buffer() As Byte pData As Long nDataLen As Long cpl(0 To 3) As Byte cplstr As String dispstr As String retval As Long ' ' ' ' ' ' ' ' version info structure buffer for version info resource pointer to version info data length of info pointed at by pData buffer for code page & language 8-digit hex string of cpl string used to display version information generic return value ' First. LOWORD = CLng("&H" & Right(hexstr. 0. nDataLen = GetFileVersionInfoSize(Text1.html (3 of 5) [9/1/2002 5:23:22 PM] . get the size of the version info resource. retval = GetFileVersionInfo(Text1. 4)) End Function Public Function LOWORD (ByVal dwValue As Long) As Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue). which uses Xor.Windows API Guide: GetFileVersionInfo Function ' HIWORD and LOWORD are API macros defined below. Public Function HIWORD (ByVal dwValue As Long) As Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue). both Byte). then Text1 ' identifies a file that isn't a 32-bit executable/DLL/etc. pData) If nDataLen = 0 Then Debug.92/vbapi/ref/g/getfileversioninfo. If this function fails. The "&H" prefix is not put into the string. but it ' outputs a string of a fixed number of digits. HIWORD = CLng("&H" & Left(hexstr.26. 4)) End Function Long 8) Long 8) ' This nifty subroutine swaps two byte values without needing a buffer variable. buffer(0)) http://216.Print "Not a 32-bit executable!" Exit Sub End If ' Make the buffer large enough to hold the version info resource. nDataLen. ReDim buffer(0 To nDataLen . Public Function FixedHex (ByVal hexval As Long. Extra zeros are added to make ' the string the proper length.Text.

http://216.dwFileType Case VFT_APP dispstr = "Application" Case VFT_DLL dispstr = "Dynamic Link Library (DLL)" Case VFT_DRV dispstr = "Device Driver" Case VFT_VXD dispstr = "Virtual Device Driver" Case Else dispstr = "Unknown" End Select Debug.Windows API Guide: GetFileVersionInfo Function ' Get a pointer to a structure that holds a bunch of data. 2) & FixedHex(cpl(2). 4 ' It is necessary to swap the first two bytes. CopyMemory cpl(0).dwFileVersionLS))) & ". cpl(1) SwapByte cpl(2). pData." & _ Trim(Str(HIWORD(vffi.Print "Copyright Info: ". ' Read the copyright information from the version info resource. executable.e. "\". cpl(3) ' Convert those four bytes into a 8-digit hexadecimal string. Select Case vffi. etc. "\VarFileInfo\Translation". ByVal pData. 2) & _ FixedHex(cpl(3).). DLL." & _ Trim(Str(LOWORD(vffi. read a description of the file and display it. cplstr = FixedHex(cpl(0).dwFileVersionLS))) Debug..92/vbapi/ref/g/getfileversioninfo." & _ Trim(Str(LOWORD(vffi. we must first determine the code page ' and language. dispstr ' Similarly. pData. dispstr = Space(nDataLen) retval = lstrcpy(dispstr. SwapByte cpl(0).Print "File Type: ".168. retval = VerQueryValue(buffer(0). nDataLen) ' Copy that structure into the one we can access. pData) ' Display the result. "\StringFileInfo\" & cplstr & "\LegalCopyright". dispstr = Trim(Str(HIWORD(vffi. nDataLen ' Display the full version number of the file. CopyMemory vffi.dwFileVersionMS))) & ". 2) ' cplstr now represents the code page and language to read strings as. Debug. as well as the last two bytes. nDataLen) ' Copy that informtion into the byte array. dispstr ' Before reading any strings out of the resource. retval = VerQueryValue(buffer(0). dispstr ' Display the type of file it is (i. ByVal pData. _ pData.Print "Version Number: ".html (4 of 5) [9/1/2002 5:23:22 PM] . 2) & FixedHex(cpl(1). nDataLen) ' Copy that data into a string for display.dwFileVersionMS))) & ". The code to get this information follows.26. retval = VerQueryValue(buffer(0).

"\StringFileInfo\" & cplstr & "\FileDescription". VerQueryValue Category Files Back to the Function list. nDataLen) dispstr = Space(nDataLen) retval = lstrcpy(dispstr.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getfileversioninfo.vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz.168. _ pData.Windows API Guide: GetFileVersionInfo Function retval = VerQueryValue(buffer(0).com/ref/g/getfileversioninfo.html (5 of 5) [9/1/2002 5:23:22 PM] . E-mail: vbapi@vbapi. Back to the Reference section.html http://216. 2000 Go back to the Windows API Guide home page. Last Modified: July 30. Copyright Information Revised October 29.Print "File Description: ". dispstr End Sub See Also GetFileVersionInfoSize.26. pData) Debug.

lpdwHandle Receives a value of 0.com .168.92/vbapi/ref/g/getfileversioninfosize.168. Example http://216. Windows 2000: Supported. Windows CE: Not Supported. Parameters lpstrFilename The full path and filename of the file. If an error occured.vbapi.1 or later. Windows 98: Supported.26.com | www. Windows NT: Requires Windows NT 3. This function does not work with 16-bit executable-type files.com | GetFileVersionInfoSize Function Declare Function GetFileVersionInfoSize Lib "version.vbworld.http://216.vbforums.vbshop. the function returns the size in bytes of the file's version information resource.html (1 of 5) [9/1/2002 5:23:31 PM] .com | www. nor with files that are not executable at all.26. you must pass a variable to receive this meaningless value.vbsquare. Return Value If successful. lpdwHandle As Long) As Long Platforms q q q q q Windows 95: Supported.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String.html vbapi. the function returns 0 (use GetLastError to get the error code). Although this parameter is effectively reserved.com | www. Description & Usage GetFileVersionInfoSize determines the length of the version information resource stored with a 32-bit executable-type file.com | www. Visual Basic-Specific Issues None.part of the VB-World Network | www.92/vbapi/ref/g/getfileversioninfosize. The actual version information resource is obtained by using GetFileVersionInfo.

dll" Alias "VerQueryValueA" (pBlock _ As Any.dll" Alias "RtlMoveMemory" (Destination As Any.html (2 of 5) [9/1/2002 5:23:31 PM] .dll" Alias "GetFileVersionInfoA" _ (ByVal lptstrFilename As String.26. lplpBuffer As Long. _ lpData As Any) As Long Public Declare Function GetFileVersionInfoSize Lib "version. ' This code is licensed according to the terms and conditions listed here. lpdwHandle As Long) As Long Public Declare Function VerQueryValue Lib "version.dll" Alias "lstrcpyA" (ByVal lpString1 _ As Any. ByVal lpSubBlock As String.html Display information about the file whose full path and filename is entered into textbox Text1. _ Source As Any.http://216. Obviously. ByVal lpString2 As Any) As Long Public Declare Sub CopyMemory Lib "kernel32. and file description when button Command1 is pressed. copyright information. ByVal Length As Long) Public Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersion As Long dwFileVersionMS As Long dwFileVersionLS As Long dwProductVersionMS As Long dwProductVersionLS As Long dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Public Const VFT_APP = &H1 Public Const VFT_DLL = &H2 Public Const VFT_DRV = &H3 Public Const VFT_VXD = &H5 ' *** Place the following function definitions inside a module.92/vbapi/ref/g/getfileversioninfosize. Display the version number. into Text1. puLen As Long) As Long Public Declare Function lstrcpy Lib "kernel32. ByVal dwHandle As Long. To use this example.) Public Declare Function GetFileVersionInfo Lib "version. *** ' HIWORD and LOWORD are API macros defined below. this example requires that you create a text box called Text1 and a command button called Command1.dll" Alias _ "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String. Public Function HIWORD (ByVal dwValue As Long) As Long Dim hexstr As String http://216.168. you obviously have to enter the filename of a 32-bit executable/DLL/etc.92/vbapi/ref/g/getfileversioninfosize. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.168.26. ByVal dwLen As Long.

4)) End Function Public Function LOWORD (ByVal dwValue As Long) As Long Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue). Public Sub SwapByte (byte1 As Byte.Text.168.26. byte2 As Byte) byte1 = byte1 Xor byte2 byte2 = byte1 Xor byte2 byte1 = byte1 Xor byte2 End Sub ' This function creates a hexadecimal string to represent a number. Public Function FixedHex (ByVal hexval As Long. pData) If nDataLen = 0 Then Debug. works as long as the two values to be swapped are ' numeric and of the same data type (here.92/vbapi/ref/g/getfileversioninfosize.html (3 of 5) [9/1/2002 5:23:31 PM] . Extra zeros are added to make ' the string the proper length. 0. 8) HIWORD = CLng("&H" & Left(hexstr. retval = VerQueryValue(buffer(0). but it ' outputs a string of a fixed number of digits.1) As Byte ' Get the version information resource. *** Private Sub Dim Dim Dim Dim Dim Dim Dim Dim Command1_Click() vffi As VS_FIXEDFILEINFO buffer() As Byte pData As Long nDataLen As Long cpl(0 To 3) As Byte cplstr As String dispstr As String retval As Long ' ' ' ' ' ' ' ' version info structure buffer for version info resource pointer to version info data length of info pointed at by pData buffer for code page & language 8-digit hex string of cpl string used to display version information generic return value ' First. ReDim buffer(0 To nDataLen .168. nDataLen = GetFileVersionInfoSize(Text1. nDigits) End Function ' *** Place the following code inside the form that has Command1 and Text1. 8) LOWORD = CLng("&H" & Right(hexstr. retval = GetFileVersionInfo(Text1. ' This technique. buffer(0)) ' Get a pointer to a structure that holds a bunch of data. then Text1 ' identifies a file that isn't a 32-bit executable/DLL/etc. nDataLen) ' Copy that structure into the one we can access. which uses Xor. get the size of the version info resource.html hexstr = Right("00000000" & Hex(dwValue). ByVal nDigits As Long) As String FixedHex = Right("00000000" & Hex(hexval).Text.26. http://216.Print "Not a 32-bit executable!" Exit Sub End If ' Make the buffer large enough to hold the version info resource. "\". pData.http://216.92/vbapi/ref/g/getfileversioninfosize. both Byte). The "&H" prefix is not put into the string. 4)) End Function ' This nifty subroutine swaps two byte values without needing a buffer variable. If this function fails. nDataLen.

retval = VerQueryValue(buffer(0).92/vbapi/ref/g/getfileversioninfosize. 4 ' It is necessary to swap the first two bytes. nDataLen) dispstr = Space(nDataLen) http://216. cpl(3) ' Convert those four bytes into a 8-digit hexadecimal string.26. ' Read the copyright information from the version info resource. The code to get this information follows. nDataLen ' Display the full version number of the file. we must first determine the code page ' and language. dispstr ' Similarly. etc. _ pData.dwFileVersionLS))) Debug. read a description of the file and display it. "\StringFileInfo\" & cplstr & "\LegalCopyright". 2) & _ FixedHex(cpl(3).dwFileVersionMS))) & ". SwapByte cpl(0)." & _ Trim(Str(LOWORD(vffi.html (4 of 5) [9/1/2002 5:23:31 PM] . 2) & FixedHex(cpl(1). _ pData.dwFileType Case VFT_APP dispstr = "Application" Case VFT_DLL dispstr = "Dynamic Link Library (DLL)" Case VFT_DRV dispstr = "Device Driver" Case VFT_VXD dispstr = "Virtual Device Driver" Case Else dispstr = "Unknown" End Select Debug.).http://216. executable.168. nDataLen) ' Copy that data into a string for display.92/vbapi/ref/g/getfileversioninfosize. cpl(1) SwapByte cpl(2). nDataLen) ' Copy that informtion into the byte array. dispstr = Trim(Str(HIWORD(vffi. retval = VerQueryValue(buffer(0).Print "File Type: ". Debug. 2) & FixedHex(cpl(2). dispstr ' Before reading any strings out of the resource. pData.dwFileVersionLS))) & ". cplstr = FixedHex(cpl(0).html CopyMemory vffi. "\VarFileInfo\Translation".168. dispstr ' Display the type of file it is (i.26.e. as well as the last two bytes. "\StringFileInfo\" & cplstr & "\FileDescription". pData) ' Display the result." & _ Trim(Str(HIWORD(vffi.Print "Version Number: ". 2) ' cplstr now represents the code page and language to read strings as. DLL." & _ Trim(Str(LOWORD(vffi. ByVal pData. dispstr = Space(nDataLen) retval = lstrcpy(dispstr. retval = VerQueryValue(buffer(0)..dwFileVersionMS))) & ".Print "Copyright Info: ". CopyMemory cpl(0). Select Case vffi. ByVal pData.

2000 Go back to the Windows API Guide home page. Copyright Information Revised October 29. Last Modified: July 30. dispstr End Sub See Also GetFileVersionInfo Category Files Back to the Function list.com Send Encrypted E-Mail This page is at http://www.26.http://216.html retval = lstrcpy(dispstr. 2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi. pData) Debug.92/vbapi/ref/g/getfileversioninfosize.html http://216.92/vbapi/ref/g/getfileversioninfosize.168.vbapi.html (5 of 5) [9/1/2002 5:23:31 PM] .com/ref/g/getfileversioninfosize.26.168. Back to the Reference section.Print "File Description: ".

Windows API Guide: GetFocus Function vbapi.com | www.1 or later.com . Parameters None.0 or later. Description & Usage GetFocus obtains a handle to the window in the calling thread that has the input focus.168.part of the VB-World Network | www.26. or if another program has the input focus.com | www. This is done whenever timer timCheck elapses.92/vbapi/ref/g/getfocus. so to use this example. Windows NT: Requires Windows NT 3. you must first place a timer named timCheck on a form window.vbshop. If another program has the input focus. Windows 98: Supported. If an error occured. Visual Basic-Specific Issues None.html (1 of 3) [9/1/2002 5:23:35 PM] . the function returns zero (use GetLastError to get the error code).com | GetFocus Function Declare Function GetFocus Lib "user32. Example Print the title of the window that currently has the input focus.vbsquare. Windows 2000: Supported.com | www. If not. ' This code is licensed according to the terms and conditions listed here. Windows CE: Requires Windows CE 1.dll" () As Long Platforms q q q q q Windows 95: Supported. if our program has it. Return Value If successful.vbworld. http://216.vbapi.vbforums. inform the user that some other program has int focus. however. this function will not work and will report an error.com | www. the function returns a handle to the window that has the input focus.

dll" Alias "GetWindowTextLengthA" _ (ByVal hWnd As Long) As Long Public Declare Function GetWindowText Lib "user32. Copyright Information Revised October 29. if any. removing the terminating null. wintext. *** Private Sub Dim Dim Dim timCheck_Timer() hWnd As Long wintext As String textlen As Long ' window that has the focus ' title of the window ' length of the title ' First. _ ByVal lpString As String.) Public Declare Function GetFocus Lib "user32. hWnd = GetFocus() If hWnd = 0 Then Debug." Else ' Get the title of the window that has the focus.26.Print "This program does not have the input focus.dll" () As Long Public Declare Function GetWindowTextLength Lib "user32." End If End Sub See Also SetFocus Category Windows Back to the Function list.92/vbapi/ref/g/getfocus.html (2 of 3) [9/1/2002 5:23:35 PM] . Debug.168. 2000 Go back to the Windows API Guide home page. ByVal nMaxCount As Long) As Long ' *** Place the following code inside the form window. textlen) & "' has the focus. has the input focus. Back to the Reference section. see which window in the program. http://216. textlen = GetWindowTextLength(hWnd) + 1 wintext = Space(textlen) textlen = GetWindowText(hWnd.Windows API Guide: GetFocus Function ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. textlen) ' Display the title.Print "The window titled '" & Left(wintext. Last Modified: December 17.dll" Alias "GetWindowTextA" (ByVal hWnd As Long. 2000 This page is copyright © 2000 Paul Kuliniewicz.

html http://216.html (3 of 3) [9/1/2002 5:23:35 PM] .92/vbapi/ref/g/getfocus.com Send Encrypted E-Mail This page is at http://www.26.168.com/ref/g/getfocus.vbapi.Windows API Guide: GetFocus Function E-mail: vbapi@vbapi.

com | www.com | GetForegroundWindow Function Declare Function GetForegroundWindow Lib "user32.vbworld.com Send Encrypted E-Mail This page is at http://www.i.com | www. " is the foreground window. the window with the focus.Windows API Guide: GetForegroundWindow Function vbapi.168.html http://216.vbapi.com/ref/g/getforegroundwindow. This page is copyright © 2000 Paul Kuliniewicz.vbsquare. Dim hforewnd As Long ' receives handle of foreground window Dim slength As Long ' length of foreground window's title bar text Dim wintext As String ' buffer for foreground window's title bar text Dim retval As Long ' return value hforewnd = GetForegroundWindow() ' determine the foreground window slength = GetWindowTextLength(hforewnd) + 1 ' length of its title bar text wintext = Space(slength) ' make room in the buffer to receive the text retval = GetWindowText(hforewnd.com | www. or the handle of the foreground window if successful.vbapi. Go back to the Windows API Guide home page. Go back to the Reference section index. with which the user is currently working with -.com | www.part of the VB-World Network | www.com .92/vbapi/ref/g/getforegroundwindow.Print "The window ". The function returns 0 if an error occured." See Also: SetForegroundWindow Category: Windows Go back to the alphabetical Function listing. E-mail: vbapi@vbapi.1) ' remove null character from end of string Debug. wintext. Example: ' Display the title bar text of the foreground window.e. Win NT GetForegroundWindow finds which window is currently the foreground window.vbforums. Copyright Information. wintext.dll" () As Long Platforms: Win 95/98..html [9/1/2002 5:23:39 PM] . The foreground window is the window. slength) ' get title bar text wintext = Left(wintext. slength .vbshop. usually at the top of the Z-order.26.

html (1 of 2) [9/1/2002 5:23:46 PM] .dll" Alias "GetFullPathNameA" (ByVal lpFileName As String. nBufferLength The size in characters of lpBuffer. Win 95/98.txt". lpBuffer A string variabled that receives the null-terminated combined path and filename.vbsquare.26. numchar) ' extract data from the returned string Debug. Go back to the Reference section index.txt" and the current directory is "C:\My Documents\Junk".com | www.Windows API Guide: GetFullPathName Function vbapi. This string is put into the string passed as lpBuffer.com | GetFullPathName Function Declare Function GetFullPathName Lib "kernel32. or the length of the final string if successful.92/vbapi/ref/g/getfullpathname. lpFilePart ??? (appears to have no effect) Example: ' Append the filename datafile. the resulting filename would be "C:\My Documents\Junk\hello.com | www. buffer.vbforums. "") ' put the result string into buffer buffer = Left(buffer.com | www. http://216. ByVal nBufferLength As Long.com | www.168.vbshop. lpFileName The name of the file to append.vbapi. Win NT GetFullPathName appends a specified filename to the name of the current directory.part of the VB-World Network | www. if you specify the file "hello. ByVal lpBuffer As String.dat to C:\Programs\Test Dim buffer As String ' receives path and filename string Dim numchar As Long ' receives length of buffer after function call ChDir "\Programs\Test" ' change current directory to C:\Programs\Test buffer = Space(255) ' make room for buffer to receive the string numchar = GetFullPathName("datafile. 255. ByVal lpFilePart As String) As Long Platforms: Win 32s.dat".Print buffer ' display resulting string See Also: GetShortPathName Category: Files Go back to the alphabetical Function listing.com . The function returns 0 if an error occured.vbworld. For example.

com Send Encrypted E-Mail This page is at http://www.vbapi. Go back to the Windows API Guide home page.Windows API Guide: GetFullPathName Function This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.html (2 of 2) [9/1/2002 5:23:46 PM] .168. E-mail: vbapi@vbapi.92/vbapi/ref/g/getfullpathname.26.html http://216.com/ref/g/getfullpathname.

Visual Basic-Specific Issues To access the returned data.html (1 of 7) [9/1/2002 5:23:53 PM] . For IP addresses. Windows CE: Requires Windows CE 1. Windows 2000: Supported.com | www. Return Value If successful.com . The computer is identified by its network address (usually but not necessary an IP address). Windows NT: Requires Windows NT 3. If an error occured. a pointer to which is returned by the function. Parameters addr The address of the host computer to get information about.com | www.vbsquare. ByVal length As Long.part of the VB-World Network | www. the function returns zero (use WSAGetLastError to get the error code.26.1 or later. The information about the host is placed into a HOSTENT structure.vbshop. The flag identifies the protocol in which the address is used. use CopyMemory to copy the data referenced by the pointer into a HOSTENT structure allocated by your program. This address must be in network byte order. protocol One of the following flags specifying the type of address specified in addr.vbworld. ByVal protocol As Long) As Long Platforms q q q q q Windows 95: Supported.dll" (addr As Long.com | www. See the example for a demonstration of this.Windows API Guide: gethostbyaddr Function vbapi. AF_12844 http://216. This pointer is only guaranteed to be valid until the next call to a Winsock function.vbforums. the function returns a pointer to a HOSTENT structure that contains data about the host.168.vbapi.com | www.com | gethostbyaddr Function Declare Function gethostbyaddr Lib "wsock32.92/vbapi/ref/g/gethostbyaddr.0 or later. length The length in bytes of the address. Description & Usage gethostbyaddr gets information about a host computer. Windows 98: Supported. this will be 4.

AF_HYLINK NSC Hyperchannel protocol. AF_IPX One of the IPX protocols (such as IPX or SPX).25).92/vbapi/ref/g/gethostbyaddr. AF_UNIX A Unix-type local-to-host pipe or portal.26.) AF_PUP A PUP protocol address. AF_UNKNOWN1 An unknown protocol. AF_DECnet DECnet protocol.Windows API Guide: gethostbyaddr Function IEEE 1284. AF_DLI Direct Data Link interface. AF_CCITT One of the CCITT protocols (such as X. AF_ATM Native ATM services protocol. AF_VOICEVIEW http://216. AF_APPLETALK Appletalk protocol. AF_FIREFOX A FireFox protocol. AF_NETBIOS NetBIOS protocol.4 WG AF Protocol. AF_BAN Banyan protocol. (Same as AF_ISO. AF_INET6 Internet or other inter-network address using IPv6 addresses. AF_DATAKIT One of the Datakit protocols. including IPX. AF_NS One of the Xerox NS protocols. AF_LAT LAT protocol. AF_SNA IBM SNA protocol. AF_ECMA A European Computer Manufacturers protocol. AF_CHAOS One of the MIT CHAOS protocols. AF_OSI One of the ISO protocols.html (2 of 7) [9/1/2002 5:23:53 PM] . AF_IMPLINK Arpanet IMP address. AF_CLUSTER Microsoft Wolfpack protocol.168. AF_INET Internet or other inter-network address (such as UDP/IP or TCP/IP). AF_ISO One of the ISO protocols.

The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand. When the user clicks button cmdGetDomain. ' This code is licensed according to the terms and conditions listed here. Constant Definitions Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const AF_12844 = 25 AF_APPLETALK = 16 AF_ATM = 22 AF_BAN = 21 AF_CCITT = 10 AF_CHAOS = 5 AF_CLUSTER = 24 AF_DATAKIT = 9 AF_DECnet = 12 AF_DLI = 13 AF_ECMA = 8 AF_FIREFOX = 19 AF_HYLINK = 15 AF_IMPLINK = 3 AF_INET = 2 AF_INET6 = 23 AF_IPX = 6 AF_ISO = 7 AF_LAT = 14 AF_NETBIOS = 17 AF_NS = 6 AF_OSI = 7 AF_PUP = 4 AF_SNA = 11 AF_UNIX = 1 AF_UNKNOWN1 = 20 AF_VOICEVIEW = 18 Example Create an IP Address control and use it to prompt the user for an IP address.html (3 of 7) [9/1/2002 5:23:53 PM] . place a command button named cmdGetDomain on a form window. To use this example.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long http://216. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. the program looks up the first domain name assigned to that address.26.168.92/vbapi/ref/g/gethostbyaddr.Windows API Guide: gethostbyaddr Function VoiceView protocol.

html (4 of 7) [9/1/2002 5:23:53 PM] . ByVal hInstance As Long. ByVal length As Long. _ ByVal hMenu As Long. ByVal dwStyle As Long. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. ByVal nHeight As Long. lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 http://216.dll" (ByVal wVersionRequested As Integer. ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32.dll" Alias "SendMessageA" (ByVal hWnd As Long. ByVal lpWindowName As String. ByVal x _ As Long. ByVal nWidth As Long. _ ByVal lpClassName As String.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. ByVal Msg _ As Long.26. Source _ As Any. wParam As Any.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long.92/vbapi/ref/g/gethostbyaddr.dll" (addr As Long.168.dll" Alias "RtlMoveMemory" (Destination As Any.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. ByVal y As Long.Windows API Guide: gethostbyaddr Function iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32. lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32. ByVal hWndParent As Long.

IPM_ISBLANK. 0. WC_IPADDRESS. IPM_GETADDRESS. in host byte order Dim ipAddress_n As Long ' the IP address. With comctls . ByVal CLng(0)) If retval <> 0 Then Debug. ByVal CLng(0). _ Me. "". create an IP Address control in the ' upper-left corner of the form. 0. ByVal CLng(0). ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. App.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. in network byte order ' information about the Winsock implementation Dim sockinfo As WSADATA Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT Dim domainName As String ' the primary domain name of the host computer Dim retval As Long ' generic return value ' Verify that an IP address was entered.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered. 20.92/vbapi/ref/g/gethostbyaddr. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control. hIPControl = CreateWindowEx(0. 0.html (5 of 7) [9/1/2002 5:23:53 PM] . ipAddress_h) http://216.dwSize = Len(comctls) .hWnd. WS_CHILD Or WS_VISIBLE. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long ' the IP address.168.hInstance. 125.26.Windows API Guide: gethostbyaddr Function ' *** Place the following code in a form window. retval = SendMessage(hIPControl. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim retval As Long ' generic return value ' Register the IP Address control window class. retval = SendMessage(hIPControl. *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized.

ByVal pHostinfo. hostinfo.h_name)) retval = lstrcpy(domainName. 2000 This page is copyright © 2000 Paul Kuliniewicz. E-mail: vbapi@vbapi. Last Modified: October 29.Print "ERROR: Attempt to open Winsock failed: error". Len(hostinfo) ' Copy the host domain name into a string. AF_INET) If pHostInfo = 0 Then Debug. retval = WSAStartup(&H202. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer. CopyMemory hostinfo. 4.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: gethostbyaddr Function If retval < 4 Then Debug.html (6 of 7) [9/1/2002 5:23:53 PM] .92/vbapi/ref/g/gethostbyaddr.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2.h_name) Debug.2 session. Back to the Reference section.vbapi.26.168. 2000 Go back to the Windows API Guide home page. sockinfo) If retval <> 0 Then Debug. retval = WSACleanup() End Sub See Also gethostbyname Category Winsock Back to the Function list. Copyright Information Revised October 29. pHostinfo = gethostbyaddr(ipAddress_n." Else ' Copy the data into the structure.html http://216.Print "Domain name is: ". domainName End If ' End the Winsock session.com/ref/g/gethostbyaddr.Print "Could not find a host with the specified IP address. domainName = Space(lstrlen(hostinfo. retval Exit Sub End If ' Convert the IP address into network byte order.

92/vbapi/ref/g/gethostbyaddr.26.html (7 of 7) [9/1/2002 5:23:53 PM] .Windows API Guide: gethostbyaddr Function http://216.168.

com | gethostbyname Function Declare Function gethostbyname Lib "wsock32.com | www. Winsock is briefly used to resolve the domain name http://216.1 or later.com | www. Visual Basic-Specific Issues To access the returned data. a pointer to which is returned by the function. Windows 98: Supported.html vbapi.26. the function returns a pointer to a HOSTENT structure that contains data about the host.dll" (ByVal name As String) As Long Platforms q q q q q Windows 95: Supported. Example Print the IP address associated with a domain name specified by the user.26. This pointer is only guaranteed to be valid until the next call to a Winsock function. Windows NT: Requires Windows NT 3.0 or later.com | www.vbapi. If an error occured.168.) Return Value If successful. Windows CE: Requires Windows CE 1. The information about the host is placed into a HOSTENT structure. See the example for a demonstration of this.92/vbapi/ref/g/gethostbyname. This cannot be an IP address string.92/vbapi/ref/g/gethostbyname.com | www.http://216. Parameters name The domain name of the network host to get information about. the function returns zero (use WSAGetLastError to get the error code).vbsquare.vbworld. use gethostbyaddr instead.vbshop. The computer is identified by its domain name.part of the VB-World Network | www. use CopyMemory to copy the data referenced by the pointer into a HOSTENT structure allocated by your program.com . Windows 2000: Supported. Description & Usage gethostbyname gets information about a host computer. (To get information about a computer with a particular IP address.168.html (1 of 4) [9/1/2002 5:24:02 PM] . Note that gethostbyname cannot identify a host computer by its IP address string.vbforums.

2)) End Function ' *** Place the following code inside the form window.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.168. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32. To run this example.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32. and the domain name is resolved when the user clicks button cmdGetIP.dll" (ByVal name As String) As Long Public Declare Function inet_ntoa Lib "wsock32.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function gethostbyname Lib "wsock32. place a text box named txtDomain and a command button named cmdGetIP on a form window.92/vbapi/ref/g/gethostbyname.168. ByVal _ lpString2 As Any) As Long ' Define a relevant API macro.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.html (2 of 4) [9/1/2002 5:24:02 PM] .http://216. Public Function MAKEWORD(ByVal bLow As Byte. Source _ As Any. 2) & Right("00" & Hex(bLow). ' This code is licensed according to the terms and conditions listed here.dll" Alias "RtlMoveMemory" (Destination As Any. The user enters the domain name to resolve in text box txtDomain.92/vbapi/ref/g/gethostbyname. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" (ByVal wVersionRequested As Integer.26. *** http://216.dll" (ByVal inaddr As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.26. ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh).html and format a printable IP address string.

ipString = Space(lstrlen(pIPString)) retval = lstrcpy(ipString.html Private Sub Dim Dim Dim Dim Dim Dim Dim Dim cmdGetIP_Click() sockinfo As WSADATA hostinfo As HOSTENT pHostinfo As Long pIPAddress As Long ipAddress As Long pIPString As Long ipString As String retval As Long ' ' ' ' ' ' ' ' information about Winsock information about an Internet host pointer to a HOSTENT structure pointer to an IP address dword an IP address.Text) If pHostinfo = 0 Then Debug. 2).Print "A non-IP address was returned. packed into a dword pointer to an IP address formatted as a string holds a human-readable IP address string generic return value ' Open up a Winsock session. sockinfo) If retval <> 0 Then Debug." Else ' Copy the data into a HOSTENT structure. retval = WSACleanup() End Sub See Also gethostbyaddr http://216. ByVal pHostinfo.Print ipString End If End If ' Close the Winsock session.2. pIPString) ' Print the result: a human-readable IP address. retval = WSAStartup(MAKEWORD(2. using version 2.Print "ERROR: Attempt to open Winsock failed: error". 4 ' Convert the IP address into a human-readable string.26.168. pHostinfo = gethostbyname(txtDomain.26. ByVal pIPAddress.http://216.h_addr_list.92/vbapi/ref/g/gethostbyname. CopyMemory ipAddress. CopyMemory hostinfo. CopyMemory pIPAddress.h_addrtype <> AF_INET Then Debug. Len(hostinfo) If hostinfo.Print "Unable to resolve domain name.html (3 of 4) [9/1/2002 5:24:02 PM] . ByVal hostinfo. retval Exit Sub End If ' Get information about the domain specified in txtDomain.168.92/vbapi/ref/g/gethostbyname." Else ' Copy the pointer to the first (and probably only) IP address in the structure. 4 ' Copy the actual IP address. Debug. pIPString = inet_ntoa(ipAddress) ' Copy the result into a string variable.

html http://216.vbapi. Back to the Reference section.com/ref/g/gethostbyname.com Send Encrypted E-Mail This page is at http://www.168. 2000 This page is copyright © 2000 Paul Kuliniewicz.html Category Winsock Back to the Function list. Last Modified: October 29.http://216. E-mail: vbapi@vbapi.26.92/vbapi/ref/g/gethostbyname.html (4 of 4) [9/1/2002 5:24:02 PM] . 2000 Go back to the Windows API Guide home page.92/vbapi/ref/g/gethostbyname. Copyright Information Revised October 29.26.168.

vbworld. Parameters lpKeyState http://216. If the &H1 bit is set.dll" (lpKeyState As Byte) As Long Platforms q q q q q Windows 95: Supported.com | www.com | www. Windows NT: Requires Windows NT 3. Return Value If an error occured. If successful.26. Visual Basic-Specific Issues None. the function returns 0 (use GetLastError to get the error code).92/vbapi/ref/g/getkeyboardstate.com .vbforums. the key is currently pressed down. If the &H80 bit is set. Windows CE: Not Supported.vbsquare. The keyboard information retrieved by this function is thread-specific.part of the VB-World Network | www.1 or later. its information does not necessarily reflect key states pertaining to the system as a whole. Each element of the 256-element array identifies information about the virtual-key whose virtual-key code matches the index of the element.html (1 of 3) [9/1/2002 5:24:08 PM] .vbapi. Description & Usage GetKeyboardState retrieves the state of every key on the keyboard and places the information into an array.168.Windows API Guide: GetKeyboardState Function vbapi.com | www. Windows 2000: Supported. the function returns a non-zero value.com | GetKeyboardState Function Declare Function GetKeyboardState Lib "user32. that key is toggled.vb-shop. Windows 98: Supported.com | www.

For c = 0 To 255 ' Make sure the &H1 bit is not set. VK_RMENU The right Alt key.html (2 of 3) [9/1/2002 5:24:08 PM] . VK_LCONTROL The left Ctrl key.168. VK_LMENU The left Alt key. 2000: In addition to the virtual keys. ' Set the toggle status for every key on the keyboard to "not ' toggled. Dim keystates(0 To 255) As Byte ' holds states of entire keyboard Dim c As Integer ' counter variable Dim retval As Long ' return value ' First. and Shift keys. VK_RCONTROL The right Ctrl key. VK_RSHIFT The right Shift key.26. Constant Definitions Const Const Const Const Const Const VK_LSHIFT = &HA0 VK_RSHIFT = &HA1 VK_LCONTROL = &HA2 VK_RCONTROL = &HA3 VK_LMENU = &HA4 VK_RMENU = &HA5 Example ' This code is licensed according to the terms and conditions listed here." This change only applies to the current thread. get the current state of the keyboard. keystates(c) = keystates(c) And (Not &H1) Next c http://216.92/vbapi/ref/g/getkeyboardstate. Each key is identified by the element corresponding with the key's virtual key code. loop through each element and explicitly set the toggle bit to 0. Alt. retval = GetKeyboardState(keystates(0)) ' Now.Windows API Guide: GetKeyboardState Function A 256-element byte array which receives the key status information for all virtual-keys. the array also receives information which distinguish between the left and right Ctrl. Windows NT. which are placed in the array at the following indices: VK_LSHIFT The left Shift key.

26.vbapi. 2000 Go back to the Windows API Guide home page. 1999 This page is copyright © 1999 Paul Kuliniewicz.html (3 of 3) [9/1/2002 5:24:08 PM] .com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.168. Go back to the Reference section index.92/vbapi/ref/g/getkeyboardstate. retval = SetKeyboardState(keystates(0)) See Also GetKeyState.html http://216.com/ref/g/getkeyboardstate. Copyright Information Revised October 29.Windows API Guide: GetKeyboardState Function ' Finally. Last Modified: September 5. SetKeyboardState Category Keyboard Go back to the alphabetical Function listing. set this to the current keyboard state.

vbsquare. If an error occured.com .Windows API Guide: gethostname Function vbapi.vbapi. Parameters name String that receives the host name of the computer.vbworld. Example When the form window opens.26. Windows 2000: Supported.dll" (ByVal name As String. the function returns zero.part of the VB-World Network | www.92/vbapi/ref/g/gethostname. This string must have sufficient room to receive the string copied into it.com | www.com | www.com | www. to get its IP address). Visual Basic-Specific Issues None.vbshop. No matter what it is. Windows 98: Supported.com | gethostname Function Declare Function gethostname Lib "wsock32. Windows CE: Requires Windows CE 1. create an IP address control in the upper-left corner and initialize it to the IP address of the http://216. This could be a simple host name or a fully-qualified domain name. terminated by a null character.html (1 of 5) [9/1/2002 5:24:30 PM] .vbforums.com | www. Return Value If successful. though. it can be successfully given to gethostbyname to get information about the computer as a network host (for example. ByVal namelen As Long) As Long Platforms q q q q q Windows 95: Supported.168. Windows NT: Requires Windows NT 3.1 or later. Description & Usage gethostname retrieves the network host name for the computer. the function returns a non-zero value (use WSAGetLastError to get the error code). namelen The length of the string passed as name.0 or later.

ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32. No special effort is needed to run this example.26.dll" (ByVal hostlong As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.168.dll" (ByVal name As String. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32. ByVal namelen As Long) As Long Public Declare Function gethostbyname Lib "wsock32.92/vbapi/ref/g/gethostname.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long.dll" Alias "RtlMoveMemory" (Destination As Any. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.html (2 of 5) [9/1/2002 5:24:30 PM] .) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32. since the IP Address control is created programmatically when the form loads.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function gethostname Lib "wsock32.dll" (ByVal wVersionRequested As Integer.Windows API Guide: gethostname Function computer. Source _ As Any. _ http://216.dll" (ByVal name As String) As Long Public Declare Function ntohl Lib "wsock32. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. ' This code is licensed according to the terms and conditions listed here.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.

2) & Right("00" & Hex(bLow). ByVal Msg _ As Long.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32. ByVal x _ As Long. ByVal nWidth As Long.92/vbapi/ref/g/gethostname.dwSize = Len(comctls) . 0.dll" Alias "SendMessageA" (ByVal hWnd As Long. lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32. 0.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window.Windows API Guide: gethostname Function ByVal lpClassName As String.hWnd. hIPControl = CreateWindowEx(0. WS_CHILD Or WS_VISIBLE. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim sockinfo As WSADATA ' information about Winsock Dim hostinfo As HOSTENT ' information about an Internet host Dim pHostinfo As Long ' pointer to a HOSTENT structure Dim localhostName As String ' the computer's domain name Dim pIPAddress As Long ' pointer to an IP address dword Dim ipAddress_n As Long ' the IP address in network byte order Dim ipAddress_h As Long ' the IP address in host byte order Dim retval As Long ' generic return value ' Register the IP Address control window class. ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh). 0. lParam As Any) As Long Public Const IPM_SETADDRESS = &H465 ' Define a relevant API macro.2). Public Function MAKEWORD(ByVal bLow As Byte. ByVal CLng(0)) ' Open a new Winsock session (version 2.html (3 of 5) [9/1/2002 5:24:30 PM] . ByVal nHeight As Long. With comctls .168. 2)) End Function ' *** Place the following code inside the form window.hInstance. ByVal lpWindowName As String. App. WC_IPADDRESS. 20. ByVal hWndParent As Long. 125. http://216. ByVal hInstance As Long. ByVal dwStyle As Long. create an IP Address control in the ' upper-left corner of the form. *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized.26. ByVal y As Long. _ Me. _ ByVal hMenu As Long. "". wParam As Any.

pHostinfo = gethostbyname(localhostName) If pHostinfo = 0 Then Debug. retval Exit Sub End If ' Get the domain name of the computer.Windows API Guide: gethostname Function retval = WSAStartup(MAKEWORD(2. failing that. ByVal pIPAddress. 2). _ ByVal CLng(0).92/vbapi/ref/g/gethostname. 256) localhostName = Left(localhostName. 4 ' Convert it to host byte order. ipAddress_h = ntohl(ipAddress_n) ' Set the IP Address control to hold this address. ByVal ipAddress_h) End If End If End Sub ' Destroy the IP Address control when the form closes. localhostName = Space(256) retval = gethostname(localhostName.h_addr_list. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub Category Winsock Back to the Function list. vbNullChar) ." Else ' Copy the data into a HOSTENT structure. CopyMemory hostinfo. or. IPM_SETADDRESS. 4 ' Copy the actual IP address.1) ' Get information about this computer on the network." Else ' Copy the pointer to the first (and probably only) IP address in the structure.h_addrtype <> AF_INET Then Debug.Print "A non-IP address was returned. ' Get information about the domain specified in txtDomain. sockinfo) If retval <> 0 Then Debug. InStr(localhostName. CopyMemory pIPAddress. ByVal hostinfo.html (4 of 5) [9/1/2002 5:24:30 PM] . a string ' that gethostbyname can handle to give an IP address. ByVal pHostinfo. CopyMemory ipAddress_n.Print "Unable to resolve domain name.Print "ERROR: Attempt to open Winsock failed: error". retval = SendMessage(hIPControl.168. Len(hostinfo) If hostinfo. Back to the Reference section. http://216.26.

26. E-mail: vbapi@vbapi.html (5 of 5) [9/1/2002 5:24:30 PM] .92/vbapi/ref/g/gethostname.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: gethostname Function Last Modified: October 29.html http://216. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page. 2000 This page is copyright © 2000 Paul Kuliniewicz.com/ref/g/gethostname.168.vbapi.

Windows 2000: Supported.vbforums.vbworld.vbsquare.vbapi.vbshop.com | www.com | www. VK_RSHIFT The right Shift key. Parameters nVirtKey The virtual-key code of the key to read the status of. Windows NT. Visual Basic-Specific Issues None. its information does not necessarily reflect key states pertaining to the system as a whole.com | www. the key is currently pressed down. and Shift keys: VK_LSHIFT The left Shift key. the key is toggled. Return Value If the &H1 bit of the return value is set. Windows CE: Requires Windows CE 1.part of the VB-World Network | www.dll" (ByVal nVirtKey As Long) As Integer Platforms q q q q q Windows 95: Supported.html (1 of 3) [9/1/2002 5:24:44 PM] . http://216. Description & Usage GetKeyState determines the current status of a key. The function both finds whether the key is currently pressed down or not.com | GetKeyState Function Declare Function GetKeyState Lib "user32.Windows API Guide: GetKeyState Function vbapi. If the &H8000 bit of the return value is set. The keyboard information retrieved by this function is threadspecific.com | www.92/vbapi/ref/g/getkeystate. Windows NT: Requires Windows NT 3. and determines if the key is currently toggled.1 or later.26. 2000: This could also be one of the following flags which distinguish between the left and right Ctrl.0 or later.com . Alt.168. Windows 98: Supported.

Private Sub Command1_Click() Dim keystate As Integer ' state of the Q key ' Get the state of the Q key as returned by the function.168. ' The code runs when button Command1 is pressed. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetKeyState Lib "user32. If keystate And &H8000 Then Debug.dll" (ByVal nVirtKey As Long) As Integer ' Determine whether the Q key is currently being pressed. VK_RCONTROL The right Ctrl key.html (2 of 3) [9/1/2002 5:24:44 PM] .92/vbapi/ref/g/getkeystate. VK_RMENU The right Alt key.Windows API Guide: GetKeyState Function VK_LCONTROL The left Ctrl key. ' (vbKeyQ is a VB-defined constant for Q's virtual-key code) keystate = GetKeyState(vbKeyQ) ' Check the &H8000 bit of the return value. GetKeyboardState http://216." End If End Sub See Also GetAsyncKeyState.Print "The Q key is currently up.Print "The Q key is currently down." Else Debug. VK_LMENU The left Alt key.26. Constant Definitions Const Const Const Const Const Const VK_LSHIFT = &HA0 VK_RSHIFT = &HA1 VK_LCONTROL = &HA2 VK_RCONTROL = &HA3 VK_LMENU = &HA4 VK_RMENU = &HA5 Example ' This code is licensed according to the terms and conditions listed here.

92/vbapi/ref/g/getkeystate.html http://216. Go back to the Reference section index. 2000 This page is copyright © 2000 Paul Kuliniewicz.html (3 of 3) [9/1/2002 5:24:44 PM] . Last Modified: July 30.168.com/ref/g/getkeystate.Windows API Guide: GetKeyState Function Category Keyboard Go back to the alphabetical Function listing.vbapi.26.com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.

vbforums.part of the VB-World Network | www.dll" () As Long Platforms q q q q q Windows 95: Supported. Windows CE: Requires Windows CE 1.LastDllError instead of the GetLastError function to debug failed API function calls.168.vbworld. be sure to check this error code immediately after an error is found. Example http://216.vbshop.1 or later. Windows 2000: Supported. Most API functions merely return a number saying if an error occured. This is because Visual Basic implicitly uses the API frequently to perform tasks which are seemingly intrinsic to the language.92/vbapi/ref/g/getlasterror. Windows 98: Supported. the LastDllError property of the Err object.26. Description & Usage GetLastError obtains the error code returned by the last API function called. Therefore. caches the error code from the last API function explicitly called by your program. These hidden API function calls will usually overwrite the error code which your code may be trying to read.com | www.vbsquare.html (1 of 2) [9/1/2002 5:24:51 PM] . Note that most functions set the code to 0 (success) if the function completes successfully. To compensate for this.Windows API Guide: GetLastError Function vbapi. Parameters None. it will sometimes not appear to work.com . Return Value The function returns the error code of the last API function called by the program.com | www. Windows NT: Requires Windows NT 3. This function gets a universal error code identifying the type of error that last occured.com | GetLastError Function Declare Function GetLastError Lib "kernel32. erasing the previous error code. predefined in Visual Basic.0 or later.com | www. Visual Basic-Specific Issues Although GetLastError works perfectly in Visual Basic. but not specifying exactly which error occured.com | www. You should use the expression Err.vbapi.

E-mail: vbapi@vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz. Dim retval As Long ' return value of function Dim errorcode As Long ' error code ' Make an invalid call to the following function by giving it an invalid handle retval = CloseHandle(-1) ' there is no handle -1! If retval = 0 Then ' the return value will be 0 if an error occured errorcode = GetLastError() ' find the error code If errorcode = 6 Then Debug.168. ' Demonstrate catching an invalid handle error.com Send Encrypted E-Mail This page is at http://www. 2000 Go back to the Windows API Guide home page. Go back to the Reference section index.LastDllError. ' If this code does not work. SetLastError.92/vbapi/ref/g/getlasterror. Copyright Information Revised October 29. SetLastErrorEx Category Errors Go back to the alphabetical Function listing. try replacing "GetLastError()" with Err.html (2 of 2) [9/1/2002 5:24:51 PM] .Print "ERROR: Invalid Handle Specified" ' error 6 = invalid handle End If See Also CommDlgExtendedError.com/ref/g/getlasterror.vbapi.Windows API Guide: GetLastError Function ' This code is licensed according to the terms and conditions listed here.26.html http://216. Last Modified: January 5.

Windows API Guide: GetLocalTime Function vbapi. Go back to the Windows API Guide home page.168.com . The various features of the time and date (month. second. Copyright Information.com | www.vbforums.vbapi. localtime. "-".). minute. This page is copyright © 2000 Paul Kuliniewicz.wMonth.com | www. are sorted in the variable passed as lpSystemTime! Windows considers "local time" to be the system's current time.vb-shop. "-". Go back to the Reference section index. etc.com | www.com | www. localtime.html (1 of 2) [9/1/2002 5:24:56 PM] . lpSystemTime Variable that receives the computer's date and time.dll" (lpSystemTime As SYSTEMTIME) Platforms: Win 95/98. hour.wYear See Also: GetSystemTime Category: Time Go back to the alphabetical Function listing.26. Example: ' Print the current date in mm-dd-yyyy format Dim localtime As SYSTEMTIME ' receives the computer's time and date GetLocalTime localtime ' read the computer's time and date ' Display the date Debug.com | GetLocalTime Function Declare Sub GetLocalTime Lib "kernel32. E-mail: vbapi@vbapi. day.com Send Encrypted E-Mail http://216.vbworld. Win NT GetLocalTime returns the system's time and date.Print localtime.wDay. down to the millisecond.92/vbapi/ref/g/getlocaltime.part of the VB-World Network | www.vbsquare.

com/ref/g/getlocaltime.html (2 of 2) [9/1/2002 5:24:56 PM] .168.vbapi.92/vbapi/ref/g/getlocaltime.Windows API Guide: GetLocalTime Function This page is at http://www.26.html http://216.

.com | GetLogicalDrives Function Declare Function GetLogicalDrives Lib "kernel32.dll" () As Long Platforms: Win 32s. Win 95/98.) Example: ' Tell the user which drives exist on the computer.Print "Drive B: exists. 4 for C:. Logical drives are any drives assigned a oneletter name (such as A: or C:)." If (driveflags And 4) = 4 Then Debug. If (driveflags And 1) = 1 Then Debug." ' And so on.vbapi.com | www. For example.com/ref/g/getlogicaldrives. but it does establish the necessary pattern to use in general." If (driveflags And 8) = 8 Then Debug. with 2 for B:. This page is copyright © 2000 Paul Kuliniewicz.Print "Drive A: exists. Note how this example ' only checks up to drive D:.. E-mail: vbapi@vbapi.vbapi. Perform a binary And between the return value and increasing powers of 2 to determine all of the drives.Print "Drive D: exists.html [9/1/2002 5:25:03 PM] .vbworld.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getlogicaldrives.com . Dim driveflags As Long ' receives the flags identifying valid drives ' Get the valid logical drives on the computer. Go back to the Reference section index.vbforums.vbshop.. (See the example for a demonstration. 8 for D:. See Also: GetLogicalDriveStrings Category: Files Go back to the alphabetical Function listing." If (driveflags And 2) = 2 Then Debug.Windows API Guide: GetLogicalDrives Function vbapi.26.com | www. The return value is a collection of single-bit flags identifying the drives found.Print "Drive C: exists.vbsquare.com | www. Copyright Information.html http://216.com | www. driveflags = GetLogicalDrives() ' Test the returned value to see if drives A: through D: exist. Win NT GetLogicalDrives determines all the valid logical drives on the computer. And it with 1 to see if drive A: exists.part of the VB-World Network | www. Go back to the Windows API Guide home page. etc.168.

drivenames) ' drivenames now holds the list ' Count by fours to extract the names of each drive. Win NT GetLogicalDriveStrings determines the valid logical drives on the computer and places the names of their root directories into the string passed as lpBuffer. This frees us from worrying about nulls. nBufferLength The size of the buffer string passed as lpBuffer.com | www. if only drives A: and C: exist.Windows API Guide: GetLogicalDriveStrings Function vbapi. where (null) represents the null character. For example.html (1 of 2) [9/1/2002 5:25:18 PM] .vbapi. Example: ' List the names of all the root directories. Since each entry in the string takes ' four characters (three for the name and one for the null). lpBufferA string which receives the names of all the logical drives.com | GetLogicalDriveStrings Function Declare Function GetLogicalDriveStrings Lib "kernel32.com .part of the VB-World Network | www. the string will be "a:\(null)c:\(null)(null)".168.dll" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long.vbsquare. and the entire string ends in two null characters.26.92/vbapi/ref/g/getlogicaldrivestrings. slength = GetLogicalDriveStrings(255.com | www.com | www. 3) ' extract a 3-character string X:\ (X is the drive letter) Debug.vbshop.vbworld. Dim drivenames As String ' receives list of root names Dim thisdrive As String ' buffer for one extracted root directory name Dim c As Long ' counter variable Dim slength As Long ' receives length of returned string ' Make enough room in the buffer to receive the drive names. or the length of the string placed in lpBuffer if successful. we can "count by fours" going ' through the string until we reach the end. drivenames = Space(255) ' more than enough room ' Get the root directory names of all logical drives.vbforums. c.com | www. This must have enough room to receive the string. For c = 1 To slength Step 4 ' loop with an increment of 4 thisdrive = Mid(drivenames. The function returns 0 if an error occured. Each root directory name in the buffer is separated by a null character.Print thisdrive ' display the drive name Next c See Also: GetLogicalDrives Category: Files http://216. ByVal lpBuffer As String) As Long Platforms: Win 95/98.

html (2 of 2) [9/1/2002 5:25:18 PM] . Go back to the Windows API Guide home page. Copyright Information.26. Go back to the Reference section index. E-mail: vbapi@vbapi.html http://216.Windows API Guide: GetLogicalDriveStrings Function Go back to the alphabetical Function listing.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getlogicaldrivestrings.com/ref/g/getlogicaldrivestrings. This page is copyright © 2000 Paul Kuliniewicz.vbapi.168.

com | www.com | www. This menu appears as the window's menu bar.Windows API Guide: GetMenu Function vbapi.html (1 of 4) [9/1/2002 5:25:25 PM] . ' This code is licensed according to the terms and conditions listed here. Return Value The function returns a handle to the menu assigned to the specified window.part of the VB-World Network | www.vbworld. If the window has no menu.com | www. the function returns 0.com .com | www. but some sort of menus are necessary. the function's return value is meaningless. although programatically the menu bar is just the top menu in the menu heirarchy.26.com | GetMenu Function Declare Function GetMenu Lib "user32. Description & Usage GetMenu identifies what menu is assigned to a given window.vbsquare. Windows 98: Supported. use the Menu Editor utility to create a small menu system on Form1. Windows CE: Not Supported.168. Example Before running this example.vbshop.1 or later. Windows NT: Requires Windows NT 3. It doesn't matter what the menus look like. Windows 2000: Supported.92/vbapi/ref/g/getmenu.dll" (ByVal hWnd As Long) As Long Platforms q q q q q Windows 95: Supported. Visual Basic-Specific Issues None. Parameters hWnd A handle to the window to get the menu of.vbapi. ' Declarations and such needed for the example: http://216. If the window specified in the parameter list is a child window.vbforums.

Public Sub IterateThroughItems(ByVal hMenu As Long.168. lpmii As _ MENUITEMINFO) As Long ' When button Command1 is pressed.dll" Alias "GetMenuItemInfoA" (ByVal _ hMenu As Long. With mii .dll" (ByVal hWnd As Long) As Long Public Declare Function GetMenuItemCount Lib "user32.fMask = MIIM_STATE Or MIIM_TYPE Or MIIM_SUBMENU For c = 0 To itemcount . *** ' This function performs the recursive output of the menu structure.cbSize = Len(mii) .1 http://216. ByVal level As Long) ' hMenu is a handle to the menu to output ' level is the level of recursion. getting information about each one.92/vbapi/ref/g/getmenu.26.dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_SUBMENU = &H4 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFS_CHECKED = &H8 Public Declare Function GetMenuItemInfo Lib "user32. A recursive subroutine is used to output the contents ' of each individual menu. used to indent submenu items Dim itemcount As Long ' the number of items in the specified menu Dim c As Long ' loop counter variable Dim mii As MENUITEMINFO ' receives information about each item Dim retval As Long ' return value ' Count the number of items in the menu passed to this subroutine. calling itself whenever a submenu is found.html (2 of 4) [9/1/2002 5:25:25 PM] . ByVal fByPosition As Long. and any items ' that are checked are identified. ' *** Place the following code inside a module. The entire menu heirarchy is displayed.Windows API Guide: GetMenu Function ' (Copy them to the (declarations) section of a module.) Public Declare Function GetMenu Lib "user32. output the structure of the entire menu system ' of Form1 to the Debug window. ByVal uItem As Long. itemcount = GetMenuItemCount(hMenu) ' Loop through the items.

IterateThroughItems hMenu.Windows API Guide: GetMenu Function ' Make room in the string buffer. "(X)". display (X) in the margin. Debug. Private Sub Command1_Click() Dim hMenu As Long ' handle to the menu bar of Form1 ' Get a handle to Form1's menu bar. 0 End Sub See Also GetSystemMenu Category Menus Back to the Function list. display its contents. hMenu = GetMenu(Form1. *** ' When Command1 is clicked.hWnd) ' Use the above function to output its contents. c.cch) ' If this item opens a submenu.hSubMenu <> 0 Then IterateThroughItems .cch = 256 ' Get information about the item.Print IIf(.html (3 of 4) [9/1/2002 5:25:25 PM] . level + 1 End If End If Next c End With End Sub ' *** Place the following code inside Form1. retval = GetMenuItemInfo(hMenu. 1.dwTypeData. " "). . Back to the Reference section.dwTypeData = Space(256) .168.") & Left(.fType = MFT_SEPARATOR Then ' This is a separator bar. . http://216. mii) ' Output a line of information about this item. If .26. ". ' Display the text of the item.92/vbapi/ref/g/getmenu.fState And MFS_CHECKED. ' If this is checked.Print " " & String(3 * level. ". If mii. output the entire contents of Form1's menu system.") & "-----" Else ' This is a text item. Debug.Print String(3 * level. Debug.hSubMenu.

html (4 of 4) [9/1/2002 5:25:25 PM] .vbapi. Copyright Information Revised October 29.html http://216. 2000 This page is copyright © 2000 Paul Kuliniewicz.com/ref/g/getmenu.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.168.Windows API Guide: GetMenu Function Last Modified: June 4. 2000 Go back to the Windows API Guide home page.92/vbapi/ref/g/getmenu.26.

vbworld.dll" (ByVal hMenu As Long) As Long Platforms q q q q q Windows 95: Supported.26. Keep in mind that the position indexes of menu items are zero based.168. their position indexes go from 0 to n . Windows 2000: Supported. If an error occured.com | GetMenuItemCount Function Declare Function GetMenuItemCount Lib "user32. ByVal http://216.com | www. Parameters hMenu A handle to the menu to count the items of.part of the VB-World Network | www.Windows API Guide: GetMenuItemCount Function vbapi. the function returns the number of items in the menu.vbsquare. the function returns -1 (use GetLastError to get the error code). but it's worth it! Public Declare Function GetSystemMenu Lib "user32.vbapi. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. Return Value If successful.vbforums. Example ' This code is licensed according to the terms and conditions listed here. Visual Basic-Specific Issues None.com | www.1. Windows NT: Requires Windows NT 3.92/vbapi/ref/g/getmenuitemcount.com .vbshop.) ' There's quite a few declarations for this example.dll" (ByVal hWnd As Long.html (1 of 5) [9/1/2002 5:25:33 PM] . Description & Usage GetMenuItemCount counts the number of items in a menu. This means that if there are n items in the menu. Windows 98: Supported.com | www.com | www. Windows CE: Not Supported.1 or later.

dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_ID = &H2 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFT_STRING = &H0 Public Const MFS_ENABLED = &H0 Public Const MFS_CHECKED = &H8 Public Declare Function InsertMenuItem Lib "user32.26. ByVal lParam As Long) As Long Public Const WM_SYSCOMMAND = &H112 Public Const WM_INITMENU = &H116 http://216. ByVal _ hWndInsertAfter As Long. ByVal nIndex As Long. ByVal hWnd As Long. ByVal wFlags As Long) As Long Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Declare Function SetWindowLong Lib "user32. ByVal y As Long.dll" Alias "SetMenuItemInfoA" (ByVal _ hMenu As Long. ByVal uItem As Long.dll" (ByVal hWnd As Long.dll" Alias "SetWindowLongA" (ByVal hWnd _ As Long.dll" Alias "CallWindowProcA" (ByVal _ lpPrevWndFunc As Long.dll" Alias "InsertMenuItemA" (ByVal _ hMenu As Long.html (2 of 5) [9/1/2002 5:25:33 PM] . ByVal wParam _ As Long.92/vbapi/ref/g/getmenuitemcount. ByVal uItem As Long. lpmii _ As MENUITEMINFO) As Long Public Declare Function SetWindowPos Lib "user32. ByVal fByPosition As Long.Windows API Guide: GetMenuItemCount Function bRevert _ As Long) As Long Public Declare Function GetMenuItemCount Lib "user32. ByVal x As Long. ByVal dwNewLong As Long) As Long Public Const GWL_WNDPROC = -4 Public Declare Function CallWindowProc Lib "user32. ByVal cx As Long. ByVal _ cy As Long.168. ByVal Msg As Long. lpmii _ As MENUITEMINFO) As Long Public Declare Function SetMenuItemInfo Lib "user32. ByVal fByPosition As Long.

168. Public Function WindowProc (ByVal hwnd As Long. HWND_TOPMOST. The menu item acts as toggle.cbSize = Len(mii) ' Only use what needs to be changed. MFS_CHECKED. check the item. 0. _ 0.fMask = MIIM_STATE ' If Form1 is now always on top. make sure that the Always On Top ' option is properly checked. 1. lParam) End If http://216. . 0. ByVal wParam _ As Long. ontop = Not ontop retval = SetWindowPos(hwnd. 0) With mii ' Size of the structure. A check mark appears next to this option when active.html (3 of 5) [9/1/2002 5:25:33 PM] . mii) WindowProc = 0 Case WM_SYSCOMMAND ' If Always On Top (ID = 1) was selected. ByVal lParam As Long) As Long Dim hSysMenu As Long ' handle to Form1's system menu Dim mii As MENUITEMINFO ' menu item information for Always On Top Dim retval As Long ' return value Select Case uMsg Case WM_INITMENU ' Before displaying the system menu. hwnd.fState = MFS_ENABLED Or IIf(ontop. *** Public pOldProc As Long Public ontop As Boolean ' pointer to Form1's previous window procedure ' identifies if Form1 is always on top or not ' The following function acts as Form1's window procedure to process messages. hSysMenu = GetSystemMenu(hwnd. HWND_NOTOPMOST). 0) End With retval = SetMenuItemInfo(hSysMenu.Windows API Guide: GetMenuItemCount Function ' ' a ' ' Add an option to make window Form1 "Always On Top" to the bottom of its system menu. Let the previous window procedure ' process it. . change the on top/not on top ' setting of Form1 to match. If wParam = 1 Then ' Reverse the setting and make it the current one. 0. 0. ByVal uMsg As Long. Note how subclassing the window is necessary to process the two messages needed to give the added system menu item its full functionality. uMsg. wParam. IIf(ontop. ' *** Place the following code in a module.92/vbapi/ref/g/getmenuitemcount. .26. SWP_NOMOVE Or SWP_NOSIZE) WindowProc = 0 Else ' Some other item was selected. WindowProc = CallWindowProc(pOldProc.

26. hwnd.dwTypeData = "&Always On Top" .wID = 1 ' The text to place in the menu item. *** ' When Form1 loads. 1.hWnd. . mii) http://216. add the Always On Top command.wID = 0 End With ' Add the separator to the end of the system menu.html (4 of 5) [9/1/2002 5:25:33 PM] . retval = InsertMenuItem(hSysMenu. WindowProc = CallWindowProc(pOldProc. . With mii .dwTypeData) End With ' Add this to the bottom of the system menu. . . 0) ' See how many items are currently in it.fState = MFS_ENABLED ' It has an ID of 1 (this identifies it in the window procedure).Windows API Guide: GetMenuItemCount Function Case Else ' If this is some other message.fType = MFT_SEPARATOR ' It has an ID of 0.92/vbapi/ref/g/getmenuitemcount. count + 1.cbSize = Len(mii) ' What parts of the structure to use. retval = InsertMenuItem(hSysMenu. With mii ' The size of the structure. 1.cch = Len(. wParam.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE ' This is a regular text item.168. . add Always On Top to the system menu and set up the ' new window procedure. uMsg. let the previous procedure handle it. hSysMenu = GetSystemMenu(Form1. Private Sub Form_Load() Dim hSysMenu As Long ' handle to the system menu Dim count As Long ' the number of items initially on the menu Dim mii As MENUITEMINFO ' describes a menu item to add Dim retval As Long ' return value ' Get a handle to the system menu. . count. . lParam) End Select End Function ' *** Place the following code inside Form1.fType = MFT_STRING ' The option is enabled. . mii) ' Likewise. count = GetMenuItemCount(hSysMenu) ' Add a separator bar and then Always On Top to the system menu.fMask = MIIM_ID Or MIIM_TYPE ' This is a separator.

AddressOf WindowProc) End Sub ' Before unloading. Back to the Reference section.hWnd. ontop = False pOldProc = SetWindowLong(Form1. E-mail: vbapi@vbapi. pOldProc) ' Remove the modifications made to the system menu. retval = SetWindowLong(Form1.hWnd. restore the default system menu and remove the ' custom window procedure. Last Modified: June 4. Copyright Information Revised October 29. 1) End Sub Category Menus Back to the Function list.com/ref/g/getmenuitemcount.com Send Encrypted E-Mail This page is at http://www.html http://216.vbapi.92/vbapi/ref/g/getmenuitemcount.Windows API Guide: GetMenuItemCount Function ' Set the custom window procedure to process Form1's messages.168. 2000 Go back to the Windows API Guide home page.html (5 of 5) [9/1/2002 5:25:33 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz. GWL_WNDPROC. retval = GetSystemMenu(Form1.26.hWnd. GWL_WNDPROC. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value ' Replace the previous window procedure to prevent crashing.

http://216.html vbapi. ByVal fByPosition As Long.26.vbshop. ByVal uItem As Long.vbsquare. the first item in the menu has a position of 0. uItem Identifies the menu item to get information about. the function returns 0 (use GetLastError to get the error code).part of the VB-World Network | www. depending on fByPosition.0 or later. (For example.vbworld.com | www. lpmii As MENUITEMINFO) As Long Platforms q q q q q Windows 95: Supported.vbapi.vbforums. The type of information retrieved is determined by the flags specified by the fMask data member of the structure passed as the lpmii parameter. Windows CE: Requires Windows CE 1. the cbSize and fMask data members of http://216.92/vbapi/ref/g/getmenuiteminfo.com | www.html (1 of 4) [9/1/2002 5:25:37 PM] . the function returns a non-zero value.com | www. Windows 2000: Supported. Windows 98: Supported.0 or later. Before calling GetMenuItemInfo.92/vbapi/ref/g/getmenuiteminfo. If an error occured.168. This could be either a position or a menu item identifier. Windows NT: Requires Windows NT 4.com | GetMenuItemInfo Function Declare Function GetMenuItemInfo Lib "user32.) If this is zero. Return Value If successful. fByPosition If this is a non-zero value.com | www. Parameters hMenu A handle to the menu that contains the item to get information about. Description & Usage GetMenuItemInfo retrieves information about an item on a menu.26. uItem indicates the item by using its zero-based position. lpmii Receives information about the menu item.com . then uItem is the unique menu item identifier of the item. Visual Basic-Specific Issues None.168.dll" Alias "GetMenuItemInfoA" (ByVal hMenu As Long.

Public Sub IterateThroughItems(ByVal hMenu As Long.html (2 of 4) [9/1/2002 5:25:37 PM] .dll" (ByVal hWnd As Long) As Long Public Declare Function GetMenuItemCount Lib "user32. calling itself whenever a submenu is found.dll" Alias "GetMenuItemInfoA" (ByVal _ hMenu As Long. lpmii As _ MENUITEMINFO) As Long ' When button Command1 is pressed.26. ' This code is licensed according to the terms and conditions listed here. *** ' This function performs the recursive output of the menu structure. A recursive subroutine is used to output the contents ' of each individual menu. the dwTypeData and cch data members must also be initialized to receive the string.92/vbapi/ref/g/getmenuiteminfo. ' *** Place the following code inside a module. ByVal level As Long) ' hMenu is a handle to the menu to output ' level is the level of recursion.168. and any items ' that are checked are identified.dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_SUBMENU = &H4 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFS_CHECKED = &H8 Public Declare Function GetMenuItemInfo Lib "user32.html this structure must be initialized to specify what information about the item to retrieve. The entire menu heirarchy is displayed.92/vbapi/ref/g/getmenuiteminfo. ByVal fByPosition As Long. ByVal uItem As Long. It doesn't matter what the menus look like.26. but some sort of menus are necessary. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetMenu Lib "user32. used to indent submenu items http://216. If getting the text of the menu item. use the Menu Editor utility to create a small menu system on Form1.) Example Before running this example. output the structure of the entire menu system ' of Form1 to the Debug window.168.http://216. (See the example below for a demonstration of this.

html (3 of 4) [9/1/2002 5:25:37 PM] . display its contents. If .hSubMenu <> 0 Then IterateThroughItems . level + 1 End If End If Next c End With End Sub ' *** Place the following code inside Form1.Print " " & String(3 * level. "(X)". mii) ' Output a line of information about this item.cch) ' If this item opens a submenu. hMenu = GetMenu(Form1. " "). *** ' When Command1 is clicked. itemcount = GetMenuItemCount(hMenu) ' Loop through the items. ' Display the text of the item.26.") & "-----" Else ' This is a text item. ".Print IIf(.fType = MFT_SEPARATOR Then ' This is a separator bar. IterateThroughItems hMenu. 1. 0 End Sub See Also http://216.hWnd) ' Use the above function to output its contents. Debug.") & Left(. ".dwTypeData = Space(256) . If mii. .92/vbapi/ref/g/getmenuiteminfo. ' If this is checked. Debug.1 ' Make room in the string buffer. With mii .hSubMenu.dwTypeData.Print String(3 * level. display (X) in the margin.fState And MFS_CHECKED. output the entire contents of Form1's menu system. retval = GetMenuItemInfo(hMenu.fMask = MIIM_STATE Or MIIM_TYPE Or MIIM_SUBMENU For c = 0 To itemcount . c.168.cch = 256 ' Get information about the item.http://216. Debug.26. getting information about each one. Private Sub Command1_Click() Dim hMenu As Long ' handle to the menu bar of Form1 ' Get a handle to Form1's menu bar.cbSize = Len(mii) . .168.92/vbapi/ref/g/getmenuiteminfo.html Dim Dim Dim Dim itemcount As Long c As Long mii As MENUITEMINFO retval As Long ' ' ' ' the number of items in the specified menu loop counter variable receives information about each item return value ' Count the number of items in the menu passed to this subroutine.

Back to the Reference section.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/g/getmenuiteminfo.92/vbapi/ref/g/getmenuiteminfo.26.http://216.168.26.html http://216.168.html (4 of 4) [9/1/2002 5:25:37 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz.html SetMenuItemInfo Category Menus Back to the Function list. Copyright Information Revised October 29. E-mail: vbapi@vbapi.com/ref/g/getmenuiteminfo. 2000 Go back to the Windows API Guide home page. Last Modified: June 4.vbapi.

ByVal lpNumberStr As String. Windows 98: Supported. the expression ByVal CLng(0) must be used. this could be one of the following flags specifying a locale: LOCALE_SYSTEM_DEFAULT The system's default locale. ByVal lpValue As String.dll" Alias "GetNumberFormatA" (ByVal Locale As Long. Windows NT: Requires Windows NT 3.5 or later.com .vbforums. Visual Basic-Specific Issues When passing 0 for the lpFormat parameter.vbsquare.html (1 of 3) [9/1/2002 5:25:45 PM] .com | www.com | www. This identifier could be generated by the MAKELCID macro. custom formatting preferences can instead be used. Windows 2000: Supported.com | www. ByVal dwFlags As Long. not including the terminating null character. Parameters Locale The locale identifier of the locale to format the number according to.part of the VB-World Network | www. Description & Usage GetNumberFormat formats a number for display.0 or later. the function returns 0 (use GetLastError to get the error code). Windows CE: Requires Windows CE 1. the function formats the number according to the specified locale's settings. Return Value If an error occured.vbworld.vbapi.Windows API Guide: GetNumberFormat Function vbapi. lpFormat As Any.26.vbshop. If successful. dwFlags http://216. ByVal cchNumber As Long) As Long Platforms q q q q q Windows 95: Supported.168. However. the function returns the number of characters copied into the string passed as lpNumberStr.com | GetNumberFormat Function Declare Function GetNumberFormat Lib "kernel32. The end result of GetNumberFormat is a number displayed according to the user's preferences. LOCALE_USER_DEFAULT The user's default locale. See the example code for a demonstration of this. Alternatively.92/vbapi/ref/g/getnumberformat.com | www. By default.

567. ByVal dwFlags As Long. lpNumberStr String that receives the null-terminated formatted number string.92/vbapi/ref/g/getnumberformat. Any other characters are invalid. ' 2.dll" Alias "GetNumberFormatA" _ (ByVal Locale As Long.) Public Type NUMBERFMT NumDigits As Long LeadingZero As Long Grouping As Long lpDecimalSep As String lpThousandSep As String NegativeOrder As Long End Type Public Declare Function GetNumberFormat Lib "kernel32. this could be the following flag: LOCALE_NOUSEROVERRIDE Use the system's default settings for the locale.234. ByVal lpNumberStr As String. If this is 0. the first character in the string must be a minus sign character (-).Windows API Guide: GetNumberFormat Function If no structure is passed as lpFormat. lpFormat To override the locale's formatting settings. Use a custom format specified by a structure passed to the function. Constant Definitions Const LOCALE_SYSTEM_DEFAULT = &H400 Const LOCALE_USER_DEFAULT = &H800 Const LOCALE_NOUSEROVERRIDE = &H80000000 Example ' This code is licensed according to the terms and conditions listed here.168. ByVal cchNumber As Long) As Long Const LOCALE_USER_DEFAULT = &H800 ' Display the number -1.26.). ' custom formatting settings Dim nft As NUMBERFMT Dim formatted As String ' receives the formatted number strings Dim strlen As Long ' the length of the formatted string http://216. regardless of any modifications the user may have made to it. the current locale settings are used. If the number is negative.89 according to two formatting rules. To use the locale's settings instead. lpValue A string containing the number to format. Or. ByVal lpValue As String. This string must have enough room to receive the string. The only allowable characters in this string are the digits 0-9 and at most a single decimal point character (. ' 1. pass 0 for this parameter. Use the format specified by the current user locale. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. cchNumber The number of characters in the string passed as lpNumberStr. lpFormat _ As Any.html (2 of 3) [9/1/2002 5:25:45 PM] . this parameter determines the settings used to format the number. pass a NUMBERFMT structure that contains the appropriate formatting information.

. .com/ref/g/getnumberformat. .Print "Custom format: ". 0.92/vbapi/ref/g/getnumberformat. "-1234567.lpThousandSep = ".LeadingZero = 1 ' Group every three digits to the left of the decimal. 2000 Go back to the Windows API Guide home page. .26. _ formatted." ' Put the negative sign immediately after the number. Len(formatted)) formatted = Left(formatted.NumDigits = 3 ' Display zeros after the decimal point. . Back to the Reference section.168.lpDecimalSep = ". strlen) Debug. 0.Print "User locale format: ". ByVal CLng(0). strlen) Debug. Last Modified: April 16. use a period as the grouping separator.Windows API Guide: GetNumberFormat Function ' Display the number formatted according to the current locale. formatted.html (3 of 3) [9/1/2002 5:25:45 PM] .89"." ' Likewise.vbapi. formatted = Space(256) strlen = GetNumberFormat(LOCALE_USER_DEFAULT. nft. With nft ' Display three digits after the decimal point. E-mail: vbapi@vbapi. "-1234567.html http://216. 2000 This page is copyright © 2000 Paul Kuliniewicz. formatted See Also GetCurrencyFormat Category National Language Support Back to the Function list.com Send Encrypted E-Mail This page is at http://www. . Len(formatted)) formatted = Left(formatted.Grouping = 3 ' Use a comma to as the decimal point (like they do in France and Spain).NegativeOrder = 3 End With formatted = Space(256) strlen = GetNumberFormat(LOCALE_USER_DEFAULT. Copyright Information Revised October 29.89". formatted ' Now display according the format we specify below.

dll" Alias "GetOpenFileNameA" (lpofn As OPENFILENAME) As Long Platforms q q q q q Windows 95: Supported. Visual Basic-Specific Issues None. and those filenames are given to your program. Windows 98: Supported.0 or later. are placed into the structure passed as lpofn.vbsquare. Windows NT: Requires Windows NT 3.26. the function returns zero.txt file.92/vbapi/ref/g/getopenfilename. If an error occured.com | GetOpenFileName Function Declare Function GetOpenFileName Lib "comdlg32.vbapi.com | www. All of the settings for creating the dialog. The user's selection is then displayed (the filename.com | www. The dialog box opens when the user clicks button Command1. So. Windows 2000: Supported. to use this example. or if the user merely clicked Cancel.html (1 of 4) [9/1/2002 5:25:51 PM] . as well as the data returned from it.vbworld.vbforums.vb-shop. Parameters lpofn The parameters used to open the dialog box. Windows CE: Requires Windows CE 1. http://216.Windows API Guide: GetOpenFileName Function vbapi. not the file itself). Use CommDlgExtendedError to get the error code.168. Return Value If the user selects one or more files in the dialog box.com | www. Example Use the Open File common dialog box to prompt the user for a *. Note that this function does not actually open any file. Also receives the returned filename(s) and other information about what the user selected.com | www. it merely prompts the user for a file or files to open. place a command button named Command1 on a form window.com . the function returns a nonzero value. Description & Usage GetOpenFileName opens the Open File common dialog dialog box.1 or later.part of the VB-World Network | www.

) Public Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustomFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Public Const OFN_FILEMUSTEXIST = &H1000 Public Const OFN_HIDEREADONLY = &H4 Public Const OFN_PATHMUSTEXIST = &H800 Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (lpofn _ As OPENFILENAME) As Long ' *** Place the following code inside a form window.lStructSize = Len(filebox) ' Handle to window opening the dialog.*)" & vbNullChar & "*. Private Sub Dim Dim Dim Command1_Click() filebox As OPENFILENAME fname As String result As Long ' open file dialog structure ' filename the user selected ' result of opening the dialog ' Configure how the dialog box will look With filebox ' Size of the structure.hWnd ' Handle to calling instance (not needed).hwndOwner = Me.26.html (2 of 4) [9/1/2002 5:25:51 PM] . .txt)" & vbNullChar & "*. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.Windows API Guide: GetOpenFileName Function ' This code is licensed according to the terms and conditions listed here.lpstrFilter = "Text Files (*. . .*" & vbNullChar & vbNullChar http://216.168.txt" & vbNullChar & _ "All Files (*.92/vbapi/ref/g/getopenfilename.hInstance = 0 ' File filters to make available: Text Files and All Files .

lpstrFile) ' Make room for filename of the user's selection.92/vbapi/ref/g/getopenfilename.168. . . .Windows API Guide: GetOpenFileName Function '. InStr(filebox.lpstrFile. .nFileExtension = 0 '.lpstrFile.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY ' The rest of the options aren't needed. hide the read-only box. Also make room for received ' path and filename of the user's selection. Go back to the Reference section index.lpstrTitle = "Select a File" & vbNullChar ' The path and file must exist.Print "The selected file: ". 2000 http://216.html (3 of 4) [9/1/2002 5:25:51 PM] .lpstrFileTitle) ' Initial directory is C:\.lpstrInitialDir = "C:\" & vbNullChar ' Title of file dialog.lpTemplateName is ignored -.lpstrFileTitle = Space(256) & vbNullChar .unused string .26.nFilterIndex = 1 ' No default filename.lpstrDefExt is ignored -.nMaxFile = Len(.lpstrFile = Space(256) & vbNullChar . .unused string End With ' Display the dialog box. .lCustData = 0 . fname = Left(filebox. . fname End If End Sub See Also GetSaveFileName Category Common Dialog Go back to the Function listing. Last Modified: September 24.nMaxFileTitle = Len(.nFileOffset = 0 .lpfnHook = 0 '.lpstrCustomFilter is ignored -. vbNullChar) 1) Debug.unused string .nMaxCustomFilter = 0 ' Default filter is the first one (Text Files. in this case). result = GetOpenFileName(filebox) If result <> 0 Then ' Remove null space from the file name.

Windows API Guide: GetOpenFileName Function

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getopenfilename.html

http://216.26.168.92/vbapi/ref/g/getopenfilename.html (4 of 4) [9/1/2002 5:25:51 PM]

Windows API Guide: GetParent Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

GetParent Function
Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetParent returns the handle of the parent window of another window. For example, the parent of a button would normally be the form window it is in. If successful, the function returns a handle to the parent window. If it fails (for example, trying to find the parent of a non-window), it returns 0. hwnd The handle of the window to find the parent of. Example: ' Figure out which frame, Frame1 or Frame2, the button Command1 ' is located on -- it is considered the child of the frame it is in Dim parenthwnd As Long ' button's parent window parenthwnd = GetParent(Command1.hWnd) ' get the button's parent window If parenthwnd = Frame1.hWnd Then Debug.Print "The button is inside Frame 1." If parenthwnd = Frame2.hWnd Then Debug.Print "The button is inside Frame 2." See Also: SetParent Category: Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getparent.html

http://216.26.168.92/vbapi/ref/g/getparent.html [9/1/2002 5:25:56 PM]

Windows API Guide: GetPixel Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

GetPixel Function
Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXPos As Long, ByVal nYPos As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetPixel determines the color of a specific pixel on a device. The function finds the RGB value of the pixel which is checked.

Return Value
If an error occured, the function returns &HFFFF. If successful, the function returns the RGB value of the pixel which was checked.

Visual Basic-Specific Issues
None.

Parameters
hdc A handle to a device context to the device to check a pixel of. nXPos The x-coordinate of the pixel to determine the color of.

http://216.26.168.92/vbapi/ref/g/getpixel.html (1 of 3) [9/1/2002 5:26:06 PM]

Windows API Guide: GetPixel Function

nYPos The y-coordinate of the pixel to determine the color of.

Example
' This code is licensed according to the terms and conditions listed here. ' Fill all of window Form1 with the color which is located at ' coordinate (75,100). Fill the window by filling its rectangle using a ' brush derived from the color of the pixel. Dim rgbVal As Long ' RGB color of the pixel Dim hBrush As Long ' handle to the brush we'll create Dim winrect As RECT ' rectangle of Form1 Dim retval As Long ' return value ' Determine the color of the pixel on Form1 at (75,100). rgbVal = GetPixel(Form1.hDC, 75, 100) ' Get the dimensions of the rectangle of window Form1. retval = GetWindowRect(Form1.hWnd, winrect) ' Create a solid brush of that color. hBrush = CreateSolidBrush(rgbVal) ' Use that brush to fill in all of Form1 (its entire rectangle). retval = FillRect(Form1.hDC, winrect, hBrush) ' Delete the brush we created to save resources. retval = DeleteObject(hBrush)

See Also
SetPixel, SetPixelV

Category
Bitmaps Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: September 2, 1999

http://216.26.168.92/vbapi/ref/g/getpixel.html (2 of 3) [9/1/2002 5:26:06 PM]

Windows API Guide: GetPixel Function

This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getpixel.html

http://216.26.168.92/vbapi/ref/g/getpixel.html (3 of 3) [9/1/2002 5:26:06 PM]

Windows API Guide: GetPolyFillMode Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

GetPolyFillMode Function
Declare Function GetPolyFillMode Lib "gdi32.dll" (ByVal hdc As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetPolyFillMode determines how a given device fills polygonal areas and shapes. These two modes only differ in how they handle complex overlapping polygons (i.e., polygons whose boundaries crisscross themselves). The function returns 0 if an error occured, or exactly one of the following flags if successful: ALTERNATE = 1 The device alternates between filling and not filling contiguous sections whose boundaries are determined by the edge(s) of the polygon crossing through the polygon's interior. WINDING = 2 Any section inside the polygon is filled, regardless of any intra-polygonal boundaries and edges. hdc A device context to the device to find the polygon filling mode of. Example: ' Display the current polygon fill mode of window Form1. Dim fillmode As Long ' receives fill mode fillmode = GetPolyFillMode(Form1.hDC) ' get the polygon fill mode If fillmode = ALTERNATE Then Debug.Print "Form1 currently uses alternating filling." Else Debug.Print "Form1 currently uses winding filling." End If See Also: SetPolyFillMode Category: Regions

http://216.26.168.92/vbapi/ref/g/getpolyfillmode.html (1 of 2) [9/1/2002 5:26:11 PM]

Windows API Guide: GetPolyFillMode Function

Back to the index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getpolyfillmode.html

http://216.26.168.92/vbapi/ref/g/getpolyfillmode.html (2 of 2) [9/1/2002 5:26:11 PM]

Windows API Guide: GetPrivateProfileInt Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

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 Platforms: Win 32s, Win 95/98, Win NT GetPrivateProfileInt reads an integer value from any INI file. The parameters passed to the function specify which value will be read from. If successful, the function returns the value read. If the value you specify does not exist or is a string (i.e., not a number), the value specified as nDefault is returned. Note that INI file support is only provided in Windows for backwards compatibility; using the registry to store information is preferred. lpApplicationName The header of the INI file section the value is in. lpKeyName The name of the value to read. nDefault The value to return if a valid value cannot be read. Make it something that would definitely not be read, such as -1. lpFileName The filename of the INI file to read from. Example: ' Read the "version" value under the "[programinfo]" section ' of the INI file C:\MyProgram\config.ini Dim version As Long ' receives the value returned from the INI file ' Read the value from the INI file, returning -1 if it can't find the value version = GetPrivateProfileInt("programinfo", "version", -1, "C:\MyProgram\config.ini") ' Display the result If version = -1 Then ' failure Debug.Print "Could not read the information from the INI file." Else Debug.Print "Version number:"; version End If

http://216.26.168.92/vbapi/ref/g/getprivateprofileint.html (1 of 2) [9/1/2002 5:26:19 PM]

Windows API Guide: GetPrivateProfileInt Function

See Also: GetPrivateProfileString, GetProfileInt Category: INI Files Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getprivateprofileint.html

http://216.26.168.92/vbapi/ref/g/getprivateprofileint.html (2 of 2) [9/1/2002 5:26:19 PM]

Windows API Guide: GetPrivateProfileString Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

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 Platforms: Win 32s, Win 95/98, Win NT GetPrivateProfileString reads an string value from an INI file. The parameters passed to the function specify which value will be read from. The function always returns the length in characters of the string put into the variable passed as lpReturnedString. If the function was successful, the string read from the INI file will be put into lpReturnedString. If not, it will instead receive the string given as lpDefault. Note that INI file support is only provided in Windows for backwards compatibility; using the registry to store information is preferred. lpApplicationName The header of the INI file section the value is in. lpKeyName The name of the value to read. lpDefault The value to return if a valid value cannot be read. Make it something that would definitely not be read, such as "(error)". lpReturnedString A fixed-length string that will receive either the string read from the file or lpDefault. nSize The length in characters of lpReturnedString. lpFileName The filename of the INI file to read from. Example: ' Read the "username" value under the [default] section of ' the INI file C:\MyProgram\config.ini. The default value is "anonymous". Dim uname As String ' receives the value read from the INI file Dim slength As Long ' receives length of the returned string uname = Space(255) ' provide enough room for the function to put the value into the buffer ' Read from the INI file slength = GetPrivateProfileString("default", "username", "anonymous", uname, 255, "C:\MyProgram\config.ini") uname = Left(uname, slength) ' extract the returned string from the buffer Debug.Print "User's name: "; uname

http://216.26.168.92/vbapi/ref/g/getprivateprofilestring.html (1 of 2) [9/1/2002 5:26:32 PM]

Windows API Guide: GetPrivateProfileString Function

See Also: GetPrivateProfileInt, GetProfileString, WritePrivateProfileString Category: INI Files Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getprivateprofilestring.html

http://216.26.168.92/vbapi/ref/g/getprivateprofilestring.html (2 of 2) [9/1/2002 5:26:32 PM]

Windows API Guide: GetProfileInt Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

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

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Note: This function is primarily for backwards compatibility with 16-bit programs. 32-bit Windows programs should typically store data in the Registry instead.

Description & Usage
GetProfileInt reads an integer value from the WIN.INI file. The parameters passed to the function specify which value will be read from. This is basically a watered-down version of GetPrivateProfileInt because, unlike it, this function only works with WIN.INI.

Return Value
If successful, the function returns the integer value read from the INI file. If the specified key could not be found, the function returns the value passed as nDefault.

Visual Basic-Specific Issues
None.

Parameters
lpAppName The header of the WIN.INI file section the value is in. lpKeyName
http://216.26.168.92/vbapi/ref/g/getprofileint.html (1 of 3) [9/1/2002 5:26:46 PM]

Windows API Guide: GetProfileInt Function

The name of the value to read. nDefault The value to return if a valid value cannot be read. This should typically be a default setting for the value, or something that would indicate that the value could not be read.

Example
Read the value "WallpaperStyle" from the [Desktop] section of the WIN.INI file and display it. To use this example, place a command button named Command1 on a form window. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetProfileInt Lib "kernel32.dll" Alias "GetProfileIntA" (ByVal lpAppName _ As String, ByVal lpKeyName As String, ByVal nDefault As Long) As Long ' *** Place the following code inside the form window. *** Private Sub Command1_Click() Dim value As Long ' value read from WIN.INI ' Read the desired value. value = GetProfileInt("Desktop", "WallpaperStyle", -1) ' Display the result. If value = -1 Then Debug.Print "Could not read the value!" Else Debug.Print "WallpaperStyle ="; value End If End Sub

See Also
GetPrivateProfileInt, GetProfileString

Category
INI Files Go back to the Function listing. Go back to the Reference section index.

http://216.26.168.92/vbapi/ref/g/getprofileint.html (2 of 3) [9/1/2002 5:26:46 PM]

Windows API Guide: GetProfileInt Function

Last Modified: January 21, 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getprofileint.html

http://216.26.168.92/vbapi/ref/g/getprofileint.html (3 of 3) [9/1/2002 5:26:46 PM]

Windows API Guide: GetRgnBox Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

GetRgnBox Function
Declare Function GetRgnBox Lib "gdi32.dll" (ByVal hRgn As Long, lpRect As RECT) As Long Platforms: Win 32s, Win 95/98, Win NT GetRgnBox determines the bounding rectangle of a given region. The bounding rectangle is the smallest possible rectangle which fully encompases the region. The bounding rectangle is placed in the structure passed as lpRect. The function returns 0 if an error occured, or exactly one of the following flags specifying the shape of the input region: COMPLEXREGION = 3 The region is not empty but is not rectangular. NULLREGION = 1 The region is empty, i.e., null. SIMPLEREGION = 2 The region is rectangular in shape. hRgn A handle to the region to get the bounding rectangle of. lpRect Receives the coordinates of the region's bounding rectangle. Example: ' Fill a triangular region on Form1 in dark gray and fill its bounding ' rectangle (behind it) in light gray. Dim triangle(0 To 2) As POINT_TYPE ' vertices of triangular region Dim hRgn As Long ' handle to the triangular region Dim hLightBrush As Long, hDarkBrush As Long ' handles to the two brushes Dim bounding As RECT ' receives bounding rectangle of region Dim retval As Long ' generic return value ' Create the triangular region. triangle(0).x = 150: triangle(0).y = triangle(1).x = 200: triangle(1).y = triangle(2).x = 175: triangle(2).y = hRgn = CreatePolygonRgn(triangle(0),

100 ' point #1: 150 ' point #2: 200 ' point #3: 3, ALTERNATE) '

(150,100) (200,150) (175,200) create the region

http://216.26.168.92/vbapi/ref/g/getrgnbox.html (1 of 2) [9/1/2002 5:26:52 PM]

Windows API Guide: GetRgnBox Function

' Get handles to the light and dark gray solid stock brushes to use. hLightBrush = GetStockObject(LTGRAY_BRUSH) hDarkBrush = GetStockObject(DKGRAY_BRUSH) ' Calculate the triangular region's bounding rectangle. retval = GetRgbBox(hRgn, bounding) ' now bounding is the bounding rectangle ' Fill the bounding rectangle in ligh gray, the region in dark gray. retval = FillRect(Form1.hDC, bounding, hLightBrush) retval = FillRgn(Form1.hDC, hRgn, hDarkBrush) ' Delete the region to free up resources. retval = DeleteObject(hRgn) Category: Regions Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getrgnbox.html

http://216.26.168.92/vbapi/ref/g/getrgnbox.html (2 of 2) [9/1/2002 5:26:52 PM]

Windows API Guide: GetProfileString Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

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 Platforms: Win 32s, Win 95/98, Win NT GetProfileString reads an string value from the WIN.INI file. The parameters passed to the function specify which value will be read from. The function always returns the length in characters of the string put into the variable passed as lpReturnedString. If the function was successful, the string read from the INI file will be put into lpReturnedString. If not, it will instead receive the string given as lpDefault. This function is basically a watered-down version of GetPrivateProfileString because it, unlike this function, works with all INI files. Note that INI file support is only provided in Windows for backwards compatibility; using the registry to store information is preferred. lpAppName The header of the INI file section the value is in. lpKeyName The name of the value to read. lpDefault The value to return if a valid value cannot be read. Make it something that would definitely not be read, such as "(error)". lpReturnedString A fixed-length string that will receive either the string read from the file or lpDefault. nSize The length in characters of lpReturnedString. Example: ' Read the value "Wallpaper" from under the [Desktop] section ' of WIN.INI. If an error occurs, the function will return "(error)" Dim wallpaper As String ' receives string read from WIN.INI Dim slength As Long ' receives length of string read from WIN.INI wallpaper = Space(255) ' make room in the buffer to receive the string read from WIN.INI ' Read the string from WIN.INI slength = GetProfileString("Desktop", "Wallpaper", "(error)", buffer, 255) wallpaper = Left(wallpaper, slength) ' extract the returned string from the buffer If wallpaper = "(error)" Then Debug.Print "Could not read information from WIN.INI." Else Debug.Print "Wallpaper file: "; wallpaper

http://216.26.168.92/vbapi/ref/g/getprofilestring.html (1 of 2) [9/1/2002 5:27:10 PM]

Windows API Guide: GetProfileString Function

End If See Also: GetPrivateProfileString, GetProfileInt, WriteProfileString Category: INI Files Go back to the alphabetical Function listing. Go back to the Reference section index.

Go back to the Windows API Guide home page. E-mail: rogue953@st-louis.crosswinds.net This page is at http://www.vbapi.com/ref/g/getprofilestring.html

http://216.26.168.92/vbapi/ref/g/getprofilestring.html (2 of 2) [9/1/2002 5:27:10 PM]

Windows API Guide: GetProp Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetProp Function
Declare Function GetProp Lib "user32.dll" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
GetProp retrieves the value of one of the window properties of a window. The function obtains a handle to whatever object was associated with the window property.

Return Value
If successful, the function returns a handle to the object associated with the window property. If the desired window property could not be found, the function returns 0.

Visual Basic-Specific Issues
None.

Parameters
hWnd A handle to the window to read a window property of. lpString The name of the window property to read.

Example
' This code is licensed according to the terms and conditions listed here.

http://216.26.168.92/vbapi/ref/g/getprop.html (1 of 2) [9/1/2002 5:27:25 PM]

Windows API Guide: GetProp Function

' Read the "LookupFile" property of window Form1 and display it. ' This property is set by the example for the SetProp function -' the value is a string specifying a filename. Dim hData As Long, pData As Long ' handle and pointer to the property's data Dim strvalue As String ' receives the value of the window property (in this case) Dim retval As Long ' return value ' Get a handle to the window property's data. hData = GetProp(Form1.hWnd, "LookupFile") ' If that property didn't exist, alert the user. If hData = 0 Then Debug.Print "There is no property called 'LookupFile'." Else ' Get a pointer to the data retrieved. pData = GlobalLock(hData) ' Copy the string data into the string. strvalue = Space(lstrlen(pData)) retval = lstrcpy(strvalue, pData) ' Unlock the data block. retval = GlobalUnlock(hData) ' Display the string gotten from the data block. Debug.Print "LookupFile = "; strvalue End If

See Also
SetProp

Category
Window Properties Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: December 24, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getprop.html

http://216.26.168.92/vbapi/ref/g/getprop.html (2 of 2) [9/1/2002 5:27:25 PM]

Windows API Guide: GetSaveFileName Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

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

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetSaveFileName opens the Save File common dialog dialog box. All of the settings for creating the dialog, as well as the data returned from it, are placed into the structure passed as lpofn. Note that this function does not actually save any file; it merely prompts the user for a file to save, and that filename is given to your program.

Return Value
If the user selects a file in the dialog box, the function returns a nonzero value. If an error occured, or if the user merely clicked Cancel, the function returns zero. Use CommDlgExtendedError to get the error code.

Visual Basic-Specific Issues
None.

Parameters
lpofn The parameters used to open the dialog box. Also receives the returned filename and other information about what the user selected.

Example
Use the Save File common dialog box to prompt the user for a *.txt file. The user's selection is then displayed (the filename, not the file itself). The dialog box opens when the user clicks button Command1. So, to use this example, place a command button named Command1 on a form window.

http://216.26.168.92/vbapi/ref/g/getsavefilename.html (1 of 4) [9/1/2002 5:27:43 PM]

Windows API Guide: GetSaveFileName Function

' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustomFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Public Const OFN_HIDEREADONLY = &H4 Public Const OFN_OVERWRITEPROMPT = &H2 Public Const OFN_PATHMUSTEXIST = &H800 Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (lpofn _ As OPENFILENAME) As Long ' *** Place the following code inside a form window. Private Sub Dim Dim Dim Command1_Click() filebox As OPENFILENAME fname As String result As Long

' save file dialog structure ' filename the user selected ' result of opening the dialog

' Configure how the dialog box will look With filebox ' Size of the structure. .lStructSize = Len(filebox) ' Handle to window opening the dialog. .hwndOwner = Me.hWnd ' Handle to calling instance (not needed). .hInstance = 0 ' File filters to make available: Text Files and All Files .lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt" & vbNullChar & _ "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
http://216.26.168.92/vbapi/ref/g/getsavefilename.html (2 of 4) [9/1/2002 5:27:43 PM]

Windows API Guide: GetSaveFileName Function

'.lpstrCustomFilter is ignored -- unused string .nMaxCustomFilter = 0 ' Default filter is the first one (Text Files, in this case). .nFilterIndex = 1 ' No default filename. Also make room for received ' path and filename of the user's selection. .lpstrFile = Space(256) & vbNullChar .nMaxFile = Len(.lpstrFile) ' Make room for filename of the user's selection. .lpstrFileTitle = Space(256) & vbNullChar .nMaxFileTitle = Len(.lpstrFileTitle) ' Initial directory is C:\. .lpstrInitialDir = "C:\" & vbNullChar ' Title of file dialog. .lpstrTitle = "Select a File" & vbNullChar ' The path must exist. Hide the read-only box. ' Warn if an existing file is selected. .flags = OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT ' The rest of the options aren't needed. .nFileOffset = 0 .nFileExtension = 0 '.lpstrDefExt is ignored -- unused string .lCustData = 0 .lpfnHook = 0 '.lpTemplateName is ignored -- unused string End With ' Display the dialog box. result = GetSaveFileName(filebox) If result <> 0 Then ' Remove null space from the file name. fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) 1) Debug.Print "The selected file: "; fname End If End Sub

See Also
GetOpenFileName

Category
Common Dialog Go back to the Function listing. Go back to the Reference section index.

http://216.26.168.92/vbapi/ref/g/getsavefilename.html (3 of 4) [9/1/2002 5:27:43 PM]

Windows API Guide: GetSaveFileName Function

Last Modified: December 17, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getsavefilename.html

http://216.26.168.92/vbapi/ref/g/getsavefilename.html (4 of 4) [9/1/2002 5:27:43 PM]

Windows API Guide: GetShortPathName Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetShortPathName Function
Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.5 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
GetShortPathName converts a long filename into the old-style 8.3 filenames. Although Windows allows the use of long filenames, DOS programs and 16-bit Windows programs must use the 8.3 equivalent. For example, the equivalent of ReallyLongFile.txt could be REALLY~1.TXT.

Return Value
If successful, the function returns the length of the string copied into lpszShortPath, not including the terminating null character. If an error occured, the function returns 0 (use GetLastError to get the error code).

Visual Basic-Specific Issues
None.

Parameters
lpszLongPath The complete long path and filename to convert. lpszShortPath Receives the 8.3 form of the filename, terminated by a null character. This string must already be sufficiently large to receive the 8.3 filename. cchBuffer The length of the string passed as lpszShortPath.

http://216.26.168.92/vbapi/ref/g/getshortpathname.html (1 of 2) [9/1/2002 5:27:50 PM]

Windows API Guide: GetShortPathName Function

Example
' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" _ (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer _ As Long) As Long ' Find the short filename equivalent of "C:\My Documents\ReadMeFirst.txt" Private Sub Command1_Click() Dim shortname As String ' receives short-filename equivalent Dim slength As Long ' receives length of short-filename equivalent ' Make room in the buffer to receive the 8.3 form of the filename. shortname = Space(256) ' Get the 8.3 form of the filename specified. slength = GetShortPathName("C:\My Documents\ReadMeFirst.txt", shortname, 256) ' Remove the trailing null and display the result. shortname = Left(shortname, slength) Debug.Print "Equivalent: "; shortname End Sub

See Also
GetFullPathName

Category
Files Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: July 4, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getshortpathname.html

http://216.26.168.92/vbapi/ref/g/getshortpathname.html (2 of 2) [9/1/2002 5:27:50 PM]

Windows API Guide: GetStockObject Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetStockObject Function
Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetStockObject accesses one of Windows's stock pens, brushes, fonts, or palettes. This function provides fast access to these commonly used objects, instead of having to use more complicated functions. The function returns a handle to the pen, brush, font, or palette which the function accesses. Although the program isn't required to delete the handle using DeleteObject, doing so doesn't have any adverse effects. nIndex Exactly one of the following flags specifying which of the stock objects to create a handle to: ANSI_FIXED_FONT = 11 The system's normal monospaced font. ANSI_VAR_FONT = 12 The system's normal proportional-width font. BLACK_BRUSH = 4 A solid black brush. BLACK_PEN = 7 A solid black pen. DEFAULT_GUI_FONT = 17 Win 95/98 only: The default font for user objects under Windows. DEFAULT_PALETTE = 15 The default system palette. DEVICE_DEFAULT_FONT = 14 Win NT only: a device-dependent font. DKGRAY_BRUSH = 3 A solid dark gray brush. GRAY_BRUSH = 2 A solid gray brush. HOLLOW_BRUSH = 5 Same as NULL_BRUSH. LTGRAY_BRUSH = 1 A solid light gray brush. NULL_BRUSH = 5 A null brush; i.e., a brush that does not draw anything on the device. NULL_PEN = 8 A null pen; i.e., a pen that does not draw anything on the device. OEM_FIXED_FONT = 10 The Original Equipment Manufacturer's default monospaced font. SYSTEM_FIXED_FONT = 16 The system monospaced font under pre-3.x versions of Windows. SYSTEM_FONT = 13 The system font (used for most system objects under Windows).
http://216.26.168.92/vbapi/ref/g/getstockobject.html (1 of 2) [9/1/2002 5:27:58 PM]

Windows API Guide: GetStockObject Function

WHITE_BRUSH = 0 A solid white brush. WHITE_PEN = 6 A solid white pen. Example: ' Draw a rectangle with a black border and light gray filled interior ' on window Form1. Use stock pens and brushes to do this. Dim hbrush As Long, holdbrush As Long ' handles to stock brush & default brush Dim hpen As Long, holdpen As Long ' handles to stock pen & default pen Dim retval As Long ' return value ' Load the stock pen and brush needed for this operation hpen = GetStockObject(BLACK_PEN) ' load the black solid pen hbrush = GetStockObject(LTGRAY_BRUSH) ' load the light gray solid brush ' Select the two objects in Form1 and save the defaults holdpen = SelectObject(Form1.hDC, hpen) ' select the pen holdbrush = SelectObject(Form1.hDC, hbrush) ' select the brush ' Draw the rectangle using the pen and brush. The rectangle has corners (20,25)(200,175) retval = Rectangle(Form1.hDC, 20, 25, 200, 175) ' Restore Form1's previously selected pen and brush retval = SelectObject(Form1.hDC, holdpen) ' reselect old pen retval = SelectObject(Form1.hDC, holdbrush) ' reselect old brush ' Note that it is not necessary to delete hpen and hbrush, but we could if we wanted. Category: Devices Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getstockobject.html

http://216.26.168.92/vbapi/ref/g/getstockobject.html (2 of 2) [9/1/2002 5:27:58 PM]

Windows API Guide: GetSysColor Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetSysColor Function
Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetSysColor returns the RGB value of one of the system colors. The system colors are the ones Windows uses to draw the typical widgets in the graphical user interface. For example, this includes the colors of title bars, scroll bars, the desktop, window borders, etc.

Return Value
If successful, the function returns the RGB value of the requested system color. If an error occured, the function returns zero (use GetLastError to get the error code).

Visual Basic-Specific Issues
None.

Parameters
nIndex One of the following flags specifying which system color to get: COLOR_3DDKSHADOW The dark shadow color for 3D objects. COLOR_3DFACE, COLOR_BTNFACE The face color for 3D objects. COLOR_3DHILIGHT, COLOR_3DHIGHLIGHT, COLOR_BTNHILIGHT, COLOR_BTNHIGHLIGHT The highlight (opposite of shadow) color for 3D objects. COLOR_3DLIGHT The light (opposite of shadow) color for 3D objects. COLOR_3DSHADOW, COLOR_BTNSHADOW
http://216.26.168.92/vbapi/ref/g/getsyscolor.html (1 of 5) [9/1/2002 5:28:05 PM]

Windows API Guide: GetSysColor Function

The shadow color for 3D objects. COLOR_ACTIVEBORDER The active window border color. COLOR_ACTIVECAPTION The active window title bar color. Windows 98, 2000: The color of the left side of the active window title bar gradient, if the gradient effect is used. COLOR_APPWORKSPACE The background color of multiple document interface (MDI) windows. COLOR_BACKGROUND, COLOR_DESKTOP The desktop color. COLOR_BTNTEXT The text color for pushbuttons. COLOR_CAPTIONTEXT The color of window caption text, size boxes, and scroll bar arrow boxes. COLOR_GRADIENTACTIVECAPTION Windows 98, 2000: The color of the right side of the active window title bar gradient, if the gradient effect is used. COLOR_GRADIENTINACTIVECAPTION Windows 98, 2000: The color of the right side of an inactive window's title bar gradient, if the gradient effect is used. COLOR_GRAYTEXT The color for disabled (grayed-out) text. COLOR_HIGHLIGHT The color used to highlight selected items. COLOR_HIGHLIGHTTEXT The color used for the text of highlighted items. COLOR_HOTLIGHT Windows 98, 2000: The color of a hot-tracked item, which is executed with a single click. COLOR_INACTIVEBORDER The color of an inactive window's border. COLOR_INACTIVECAPTION The color of an inactive window's caption. Windows 98, 2000: The color of the right side of an inactive window's title bar gradient, if the gradient effect is used. COLOR_INACTIVECAPTIONTEXT The color of an inactive window's caption text. COLOR_INFOBK The background color for tooltop controls. COLOR_INFOTEXT The text color for tooltip controls. COLOR_MENU The background color of menus. COLOR_MENUTEXT The color of menu text. COLOR_SCROLLBAR The color of a scroll bar's gray area. COLOR_WINDOW The background color of a window. COLOR_WINDOWFRAME The color of a window frame. COLOR_WINDOWTEXT The color of text in a window.

http://216.26.168.92/vbapi/ref/g/getsyscolor.html (2 of 5) [9/1/2002 5:28:05 PM]

Windows API Guide: GetSysColor Function

Constant Definitions
Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const COLOR_3DDKSHADOW = 21 COLOR_3DFACE = COLOR_BTNFACE COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT COLOR_3DLIGHT = 22 COLOR_3DSHADOW = COLOR_BTNSHADOW COLOR_ACTIVEBORDER = 10 COLOR_ACTIVECAPTION = 2 COLOR_APPWORKSPACE = 12 COLOR_BACKGROUND = 1 COLOR_BTNFACE = 15 COLOR_BTNHIGHLIGHT = 20 COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT COLOR_BTNSHADOW = 16 COLOR_BTNTEXT = 18 COLOR_CAPTIONTEXT = 9 COLOR_DESKTOP = COLOR_BACKGROUND COLOR_GRADIENTACTIVECAPTION = 27 COLOR_GRADIENTINACTIVECAPTION = 28 COLOR_GRAYTEXT = 17 COLOR_HIGHLIGHT = 13 COLOR_HIGHLIGHTTEXT = 14 COLOR_HOTLIGHT = 26 COLOR_INACTIVEBORDER = 11 COLOR_INACTIVECAPTION = 3 COLOR_INACTIVECAPTIONTEXT = 19 COLOR_INFOBK = 24 COLOR_INFOTEXT = 23 COLOR_MENU = 4 COLOR_MENUTEXT = 7 COLOR_SCROLLBAR = 0 COLOR_WINDOW = 5 COLOR_WINDOWFRAME = 6 COLOR_WINDOWTEXT = 8

Example
Reverse the gradient colors in windows' title bars. In other words, the left-side gradient color is swapped with the right-side gradient color, for both active and inactive windows. Of course, this example won't work properly on Windows 95 or Windows NT 3.1 through 4.0, but you can still see how these two functions are used by looking at the source code. This example runs when the user clicks command button Command1. So, to use this example, you must first place a command button named Command1 on a form window. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.)
http://216.26.168.92/vbapi/ref/g/getsyscolor.html (3 of 5) [9/1/2002 5:28:05 PM]

Windows API Guide: GetSysColor Function

Public Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long Public Declare Function SetSysColors Lib "user32.dll" (ByVal cElements As Long, lpaElements As Long, _ lpaRgbValues As Long) As Long Public Const COLOR_ACTIVECAPTION = 2 Public Const COLOR_GRADIENTACTIVECAPTION = 27 Public Const COLOR_GRADIENTINACTIVECAPTION = 28 Public Const COLOR_INACTIVECAPTION = 3 ' *** Place the following code inside a form window. *** Private Sub Command1_Click() Dim activeLeftColor As Long window title bar Dim activeRightColor As Long window title bar Dim inactiveLeftColor As Long window title bar Dim inactiveRightColor As Long inactive window title bar Dim colorNames(0 To 3) As Long Dim colorRGBs(0 To 3) As Long Dim retval As Long

' color of left-side gradient of active ' color of right-side gradient of active ' color of the left-side gradient of inactive ' color of the right-side gradient of ' identifiers of the system colors to change ' RGB values of the system colors to change ' generic return value

' Get the RGB values of the colors used in title bars. activeLeftColor = GetSysColor(COLOR_ACTIVECAPTION) activeRightColor = GetSysColor(COLOR_GRADIENTACTIVECAPTION) inactiveLeftColor = GetSysColor(COLOR_INACTIVECAPTION) inactiveRightColor = GetSysColor(COLOR_GRADIENTINACTIVECAPTION) ' Load the arrays with the new values to assign. Note how we're switching ' the values used on the left and right sides of the two gradients. colorNames(0) = COLOR_ACTIVECAPTION colorRGBs(0) = activeRightColor colorNames(1) = COLOR_GRADIENTACTIVECAPTION colorRGBs(1) = activeLeftColor colorNames(2) = COLOR_INACTIVECAPTION colorRGBs(2) = inactiveRightColor colorNames(3) = COLOR_GRADIENTINACTIVECAPTION colorRGBs(3) = inactiveLeftColor ' Change the system color settings as specified above. retval = SetSysColors(4, colorNames(0), colorRGBs(0)) End Sub

See Also
SetSysColors

http://216.26.168.92/vbapi/ref/g/getsyscolor.html (4 of 5) [9/1/2002 5:28:05 PM]

Windows API Guide: GetSysColor Function

Category
System Information Back to the Function list. Back to the Reference section.

Last Modified: September 24, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getsyscolor.html

http://216.26.168.92/vbapi/ref/g/getsyscolor.html (5 of 5) [9/1/2002 5:28:05 PM]

http://216.26.168.92/vbapi/ref/g/getsystemdirectory.html

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetSystemDirectory Function
Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetSystemDirectory reads the path of Windows's System directory. This is where many important files for Windows are stored, including the API DLLs. Never assume this is "C:\Windows\System" because the Windows directory doesn't have to be called Windows. The path of the system directory is put into the string variable passed as lpBuffer. The function returns the length of the string returned if it is successful, or 0 if it failed. lpBuffer A string which receives the path of the system directory. nSize The length in characters of lpBuffer. Example: ' Display the path of the system directory Dim sysdir As String ' receives path of system directory Dim slength As Long ' receives length of returned string sysdir = Space(255) ' make room in the buffer to receive the string slength = GetSystemDirectory(sysdir, 255) ' determine the system directory's path sysdir = Left(sysdir, slength) ' extract the returned string from the buffer Debug.Print "System directory path: "; sysdir See Also: GetWindowsDirectory Category: System Information Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getsystemdirectory.html

http://216.26.168.92/vbapi/ref/g/getsystemdirectory.html [9/1/2002 5:28:10 PM]

the function obtains a handle to the window's system menu. Return Value If the bRevert parameter is zero.0 or later.com | www.com | www.92/vbapi/ref/g/getsystemmenu.vbshop. the function instead reverts the system menu back to its default appearance.Windows API Guide: GetSystemMenu Function vbapi.vbworld. Windows NT: Requires Windows NT 3. this function returns 0.vbsquare.dll" (ByVal hWnd As Long. Description & Usage GetSystemMenu obtains a handle to a window's system menu (also known as its control menu).html (1 of 5) [9/1/2002 5:28:19 PM] . bRevert If zero. However. you can use the other menu functions to add or remove items from it. Visual Basic-Specific Issues None.com | GetSystemMenu Function Declare Function GetSystemMenu Lib "user32. If nonzero.vbforums. Parameters hWnd A handle to the window to locate the system menu of. ByVal bRevert As Long) As Long Platforms q q q q q Windows 95: Supported.1 or later.26. GetSystemMenu could also be used to restore the system menu to its default appearance.com . Alternately. Windows 2000: Supported. This menu is what appears when the application icon on the title bar is clicked. Windows 98: Supported. Once you get a handle to a window's system menu.vbapi.168. note that all items on a system menu send the WM_SYSCOMMAND message to the parent window instead of the usual WM_COMMAND message. If bRevert is nonzero.part of the VB-World Network | www. removing any modifications done to it. Windows CE: Requires Windows CE 1. GetSystemMenu returns a handle to the window's system menu.com | www. http://216.com | www. or when the title bar itself is right-clicked.

) ' There's quite a few declarations for this example. ByVal fByPosition As Long. ByVal uItem As Long.html (2 of 5) [9/1/2002 5:28:19 PM] . ByVal bRevert _ As Long) As Long Public Declare Function GetMenuItemCount Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd _ http://216. ByVal _ cy As Long.26.dll" Alias "InsertMenuItemA" (ByVal _ hMenu As Long. ByVal cx As Long. ByVal fByPosition As Long.dll" Alias "SetMenuItemInfoA" (ByVal _ hMenu As Long.dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_ID = &H2 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFT_STRING = &H0 Public Const MFS_ENABLED = &H0 Public Const MFS_CHECKED = &H8 Public Declare Function InsertMenuItem Lib "user32.dll" (ByVal hWnd As Long.168. ByVal wFlags As Long) As Long Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Declare Function SetWindowLong Lib "user32.Windows API Guide: GetSystemMenu Function Example ' This code is licensed according to the terms and conditions listed here. ByVal _ hWndInsertAfter As Long. lpmii _ As MENUITEMINFO) As Long Public Declare Function SetMenuItemInfo Lib "user32.dll" (ByVal hWnd As Long. but it's worth it! Public Declare Function GetSystemMenu Lib "user32. ByVal x As Long.92/vbapi/ref/g/getsystemmenu. ByVal y As Long. ByVal uItem As Long. lpmii _ As MENUITEMINFO) As Long Public Declare Function SetWindowPos Lib "user32. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.

make sure that the Always On Top ' option is properly checked. ByVal Msg As Long.html (3 of 5) [9/1/2002 5:28:19 PM] . HWND_TOPMOST. ByVal uMsg As Long. 0) With mii ' Size of the structure. If wParam = 1 Then ' Reverse the setting and make it the current one. ByVal nIndex As Long. HWND_NOTOPMOST). mii) WindowProc = 0 Case WM_SYSCOMMAND ' If Always On Top (ID = 1) was selected. ByVal lParam As Long) As Long Public Const WM_SYSCOMMAND = &H112 Public Const WM_INITMENU = &H116 ' ' a ' ' Add an option to make window Form1 "Always On Top" to the bottom of its system menu. . ByVal wParam _ As Long. hSysMenu = GetSystemMenu(hwnd. change the on top/not on top ' setting of Form1 to match. ' *** Place the following code in a module.168. A check mark appears next to this option when active. check the item. Public Function WindowProc (ByVal hwnd As Long. 0. Note how subclassing the window is necessary to process the two messages needed to give the added system menu item its full functionality. _ 0. .Windows API Guide: GetSystemMenu Function As Long. MFS_CHECKED. 1. *** Public pOldProc As Long Public ontop As Boolean ' pointer to Form1's previous window procedure ' identifies if Form1 is always on top or not ' The following function acts as Form1's window procedure to process messages. 0. The menu item acts as toggle.cbSize = Len(mii) ' Only use what needs to be changed. . ByVal wParam _ As Long.fMask = MIIM_STATE ' If Form1 is now always on top. ByVal lParam As Long) As Long Dim hSysMenu As Long ' handle to Form1's system menu Dim mii As MENUITEMINFO ' menu item information for Always On Top Dim retval As Long ' return value Select Case uMsg Case WM_INITMENU ' Before displaying the system menu. 0) End With retval = SetMenuItemInfo(hSysMenu.dll" Alias "CallWindowProcA" (ByVal _ lpPrevWndFunc As Long. 0. ByVal hWnd As Long.26.fState = MFS_ENABLED Or IIf(ontop.92/vbapi/ref/g/getsystemmenu. IIf(ontop. SWP_NOMOVE Or SWP_NOSIZE) http://216. 0. ontop = Not ontop retval = SetWindowPos(hwnd. ByVal dwNewLong As Long) As Long Public Const GWL_WNDPROC = -4 Public Declare Function CallWindowProc Lib "user32.

lParam) End Select End Function ' *** Place the following code inside Form1. . add Always On Top to the system menu and set up the ' new window procedure. 0) ' See how many items are currently in it.hWnd. wParam. hwnd.168.26.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE ' This is a regular text item. add the Always On Top command. . hSysMenu = GetSystemMenu(Form1. Let the previous window http://216. With mii ' The size of the structure.wID = 0 End With ' Add the separator to the end of the system menu. Private Sub Form_Load() Dim hSysMenu As Long ' handle to the system menu Dim count As Long ' the number of items initially on the menu Dim mii As MENUITEMINFO ' describes a menu item to add Dim retval As Long ' return value ' Get a handle to the system menu.html (4 of 5) [9/1/2002 5:28:19 PM] . let the previous procedure handle it. retval = InsertMenuItem(hSysMenu.fType = MFT_SEPARATOR ' It has an ID of 0. count = GetMenuItemCount(hSysMenu) ' Add a separator bar and then Always On Top to the system menu. .92/vbapi/ref/g/getsystemmenu. 1. uMsg. mii) ' Likewise. hwnd.Windows API Guide: GetSystemMenu Function WindowProc = 0 Else ' Some other item was selected. . count. WindowProc = CallWindowProc(pOldProc. uMsg. procedure ' process it. .fMask = MIIM_ID Or MIIM_TYPE ' This is a separator.cbSize = Len(mii) ' What parts of the structure to use.fType = MFT_STRING ' The option is enabled. wParam. . *** ' When Form1 loads.fState = MFS_ENABLED ' It has an ID of 1 (this identifies it in the window procedure). WindowProc = CallWindowProc(pOldProc. With mii . lParam) End If Case Else ' If this is some other message.

html http://216.168. restore the default system menu and remove the ' custom window procedure. 2000 Go back to the Windows API Guide home page.dwTypeData) End With ' Add this to the bottom of the system menu. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value ' Replace the previous window procedure to prevent crashing. count + 1. .com/ref/g/getsystemmenu. ontop = False pOldProc = SetWindowLong(Form1.vbapi. mii) ' Set the custom window procedure to process Form1's messages. Copyright Information Revised October 29. GWL_WNDPROC.26. AddressOf WindowProc) End Sub ' Before unloading.wID = 1 ' The text to place in the menu item. retval = InsertMenuItem(hSysMenu.92/vbapi/ref/g/getsystemmenu. 1. Last Modified: June 4.hWnd. pOldProc) ' Remove the modifications made to the system menu.dwTypeData = "&Always On Top" .html (5 of 5) [9/1/2002 5:28:19 PM] .Windows API Guide: GetSystemMenu Function . Back to the Reference section. retval = GetSystemMenu(Form1. GWL_WNDPROC. 1) End Sub See Also GetMenu Category Menus Back to the Function list. 2000 This page is copyright © 2000 Paul Kuliniewicz.hWnd.hWnd.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi. retval = SetWindowLong(Form1.cch = Len(.

The return value is a combination of two of the following flags. http://216.26. ARW_TOPLEFT = 2 Start placing the icons in the top-left corner of the screen.168. Most of these deal with the sizes of various objects. ARW_LEFT = 0 Add new icons to the left of existing ones.html (1 of 5) [9/1/2002 5:28:26 PM] .e. ARW_STARTTOP = 2 Same as ARW_TOPLEFT. cursors. 1 means a fail-safe (a.com | www.com | www. Win NT GetSystemMetrics returns information about various things in Windows.com | www. such as the screen.com | GetSystemMetrics Function Declare Function GetSystemMetrics Lib "user32.vbshop.vbforums. SM_CLEANBOOT = 67 Win 95/98 only: Return a value specifying how the computer was booted up. ARW_TOPRIGHT = 3 Start placing the icons in the top-right corner of the screen. icons.k.a. SafeBoot) bootup. ARW_RIGHT = 4 Add new icons to the right of existing ones.vbworld. hide them). etc.vbapi. ARW_UP = 0 Add new icons above existing ones. Also note that some of the metrics have slightly different meanings between Win NT and Win 95/98. nIndex Exactly one of the following flags specifying which piece of information to return: SM_ARRANGE = 56 Win 95/98 only: Return the method used to display minimized windows. SM_CMETRICS = 44 Win 95/98 only: Return the number of system metrics. ARW_DOWN = 4 Add new icons below existing ones. 0 means a normal bootup. and 2 means a fail-safe bootup with the network installed. one specifying a starting position for the minimized icons and another specifying the direction in which new ones are added: ARW_BOTTOMLEFT = 0 Start placing the icons in the bottom-left corner of the screen.Windows API Guide: GetSystemMetrics Function vbapi.dll" (ByVal nIndex As Long) As Long Platforms: Win 32s..92/vbapi/ref/g/getsystemmetrics. ARW_HIDE = 8 Do not place the icons anywhere on the screen (i.com | www. ARW_STARTRIGHT = 1 Same as ARW_BOTTOMRIGHT. ARW_BOTTOMRIGHT = 1 Start placing the icons in the bottom-right corner of the screen. Keep in mind that all sizes (such as widths and heights) are measured in pixels.part of the VB-World Network | www. The return value of the function depends on the value specified for nIndex. Win 95/98. This function provides information about the system.com .vbsquare.

Windows API Guide: GetSystemMetrics Function SM_CMOUSEBUTTONS = 43 Return the number of mouse buttons on the installed mouse. SM_CXICON = 11 Return the default width of an icon. SM_CXSCREEN = 0 Return the width of the screen. SM_CXMENUCHECK = 71 Win 95/98 only: Return the width of the default menu check-mark bitmap. Win 95/98: Return the width of the grid cell for items in a large icon view. SM_CXBORDER = 5 Win NT: Return the width of a window border. SM_CXSMICON = 49 Win 95/98 only: Return the recommended width for small icons. SM_CXMENUSIZE = 54 Win 95/98 only: Return the width of a menu bar button. SM_CXFULLSCREEN = 16 Return the width of the client area of a full-screen window. http://216. or 0 if no mouse is installed.26. SM_CXICONSPACING = 38 Win NT: Return the width of the cell used to position icons.92/vbapi/ref/g/getsystemmetrics. SM_CXFRAME = 32 Win NT only: Return the width of the border of a resizable window. SM_CXEDGE = 45 Win 95/98 only: Return the width of a 3D window border. SM_CXMAXIMIZED = 61 Win 95/98 only: Return the default width of a maximized window. Win 95/98: Return the width of the standard cursor bitmap. Win 95/98: Return the width of a single window border. SM_CXSIZEFRAME = 32 Win 95/98 only: Return the width of a thick window frame. SM_CXDLGFRAME = 7 Win NT only: Return the width of a window frame having a dialog frame style. SM_CXMAXTRACK = 59 Win 95/98 only: Return the default maximum width the user is allowed to resize a window to. SM_CXDRAG = 68 Return the minimum width the cursor must move to begin a drag-and-drop operation. SM_CXMINSPACING = 47 Win 95/98 only: Return the width of the grid cell rectangle used to position minimized windows. SM_CXCURSOR = 13 Win NT: Return the width of the cursor. SM_CXDOUBLECLK = 36 The width of the rectangle within which both mouse clicks must be to recognize a double-click. SM_CXMINIMIZED = 57 Win 95/98 only: Return the width of a normal minimized window.168.html (2 of 5) [9/1/2002 5:28:26 PM] . SM_CXMIN = 28 Return the minimum width of a window. SM_CXHSCROLL = 21 Win 95/98 only: Return the width of an arrow bitmap on a horizontal scrollbar. SM_CXHTHUMB = 10 Return the width of the horizontal scrollbar thumb. Win 95/98: Return the width of a caption button. SM_CXSIZE = 30 Win NT: Return the width of a title bar bitmap. SM_CXMINTRACK = 34 Win 95/98 only: Return the default minimum width the user is allowed to resizea window to.

SM_CYMINSPACING = 48 Win 95/98 only: Return the height of the grid cell rectangle used to position minimized windows. SM_CYMAXIMIZED = 62 Win 95/98 only: Return the default height of a maximized window. SM_CYMIN = 29 Return the minimum height of a window. SM_CYDRAG = 69 Return the minimum height the cursor must move to begin a drag-and-drop operation. SM_CYKANJIWINDOW = 18 Return the height of the Kanji window (for double-byte character set versions of Windows). SM_CYMENUSIZE = 55 Win 95/98 only: Return the height of a menu bar button.168. Win 95/98: Return the height of the standard cursor bitmap. SM_CYSCREEN = 1 Return the height of the screen. SM_CYFRAME = 33 Win NT only: Return the height of the border of a resizable window. SM_CYMAXTRACK = 60 Win 95/98 only: Return the default maximum height the user is allowed to resize a window to. SM_CYDOUBLECLK = 37 Return the height of the rectangle within which both mouse clicks must be to recognize a double-click.html (3 of 5) [9/1/2002 5:28:26 PM] . SM_CYHSCROLL = 3 Win 95/98 only: Return the height of a horizontal scrollbar. SM_CYMENU = 15 Return the height of a single menu bar. SM_CYFULLSCREEN = 17 Return the height of the client area of a full-screen window. SM_CYEDGE = 46 Win 95/98 only: Return the height of a 3D window border. SM_CYBORDER = 6 Win NT: Return the height of a window border. http://216. Win 95/98: Return the height of a single window border. Win 95/98: Return the height of the grid cell for items in a large icon view. SM_CYMINIMIZED = 58 Win 95/98 only: Return the height of a normal minimized window. SM_CYMENUCHECK = 72 Win 95/98 only: Return the height of the default menu check-mark bitmap. SM_CYMINTRACK = 35 Win 95/98 only: Return the default minimum height the user is allowed to resize a window to. SM_CYICON = 12 Return the default height of an icon. SM_CYCAPTION = 4 Return the height of a normal caption area.26. SM_CYDLGFRAME = 8 Win NT only: Return the height of a window frame having a dialog frame style.Windows API Guide: GetSystemMetrics Function SM_CXSMSIZE = 52 Win 95/98 only: Return the width of a small caption button. SM_CXVSCROLL = 2 Win 95/98 only: Return the width of a vertical scrollbar. SM_CYCURSOR = 14 Win NT: Return the height of the cursor.92/vbapi/ref/g/getsystemmetrics. SM_CYICONSPACING = 39 Win NT: Return the height of the cell used to position icons.

SM_SHOWSOUNDS = 70 Return a non-zero value if the application should show a visual cue for all sounds. SM_CYSIZEFRAME = 33 Win 95/98 only: Return the height of a thick window frame. the width and height of the screen.. yres.i. All other bits of the return value are reserved and undefined. SM_DEBUG = 22 Return a non-zero value if the debugging version of USER. 0 if not. SM_MOUSEPRESENT = 19 Return a non-zero value if a mouse is installed and present.Print "The display is". 0 if not. 0 if not. SM_DBCSENABLED = 42 Return a non-zero value if the double-byte character set version of USER. numbuttons As Long ' receive presense of mouse and number of buttons Dim hasnetwork As Long ' receives info on availability of network ' Display the screen resolution -. xres.Windows API Guide: GetSystemMetrics Function SM_CYSIZE = 31 Win NT: Return the height of a title bar bitmap. SM_PENWINDOWS = 41 Return a non-zero value if the Microsoft Windows for Pen computing extensions are installed. 0 if not.92/vbapi/ref/g/getsystemmetrics. Example: ' Display the screen resolution (size) and some information about the ' configuration of windows. Win 95/98: Return the height of a caption button. SM_CYVSCROLL = 20 Win 95/98 only: Return the height of an arrow bitmap on a vertical scrollbar.26. SM_NETWORK = 63 Set the &H1 bit of the return value if a network is installed. 0 if not. "pixels high. 0 if not. low-end processor. SM_CYSMSIZE = 53 Win 95/98 only: Return the height of a small caption button. SM_MIDEASTENABLED = 74 Return a non-zero value if the system is enabled to use Hebrew and Arabic languages. SM_MENUDROPALIGNMENT = 40 Return a non-zero value if popup menus appear to the right.EXE is installed. xres = GetSystemMetrics(SM_CXSCREEN) yres = GetSystemMetrics(SM_CYSCREEN) Debug." http://216. 0 if to the left.e. yres As Long ' receive x and y resolutions of the display Dim hasmouse As Long. SM_CYSMICON = 50 Win 95/98 only: Return the recommended height for small icons. "pixels wide and". SM_SECURE = 44 Return a non-zero value if security is present and active. SM_SLOWMACHINE = 73 Return a non-zero value if the system has a slow.EXE is installed. SM_CYVTHUMB = 9 Return the height of a vertical scrollbar thumb. SM_SWAPBUTTON = 23 Return a non-zero value if the left and right mouse buttons are swapped. Dim xres As Long. 0 if not. 0 if not. SM_CYSMCAPTION = 51 Win 95/98 only: Return the height of a small caption area.168. 0 if not.html (4 of 5) [9/1/2002 5:28:26 PM] .

"buttons is installed. Go back to the Windows API Guide home page." End If ' Display whether the system has a network connection installed. hasmouse = GetSystemMetrics(SM_MOUSEPRESENT) numbuttons = GetSystemMetrics(SM_CMOUSEBUTTONS) If hasmouse = 0 Then Debug. E-mail: vbapi@vbapi. numbuttons.com Send Encrypted E-Mail This page is at http://www. This page is copyright © 2000 Paul Kuliniewicz.Windows API Guide: GetSystemMetrics Function ' Display the number of buttons on the mouse." Else Debug.Print "No network is currently configured.html http://216.vbapi. hasnetwork = GetSystemMetrics(SM_NETWORK) If (hasnetwork And &H1) = &H1 Then ' check only the information bit Debug.168. Go back to the Reference section index.92/vbapi/ref/g/getsystemmetrics.Print "No mouse is installed on the system." End If See Also: SystemParametersInfo Category: Accessibility Go back to the alphabetical Function listing.26.Print "A network is configured to be used by Windows." Else Debug.Print "A mouse with".html (5 of 5) [9/1/2002 5:28:26 PM] . Copyright Information.com/ref/g/getsystemmetrics. if a mouse is present.

Return Value GetSystemTime does not return a value.com | www.168.92/vbapi/ref/g/getsystemtime.com | www.html vbapi.com | www.vbsquare.168.vbforums. Times are always reported in UTC time (Coordinated Universal Time. Windows 98: Supported.dll" (lpSystemTime As SYSTEMTIME) Platforms q q q q q Windows 95: Supported.com | www. Visual Basic-Specific Issues None. Example http://216.vbapi.0 or later.1 or later.vbworld.k.26.com | GetSystemTime Function Declare Sub GetSystemTime Lib "kernel32.http://216. Windows CE: Requires Windows CE 1. Windows 2000: Supported.vb-shop. Parameters lpSystemTime Receives the current system date and time. Description & Usage GetSystemTime retrieves the current system date and time and places it into a SYSTEMTIME structure.part of the VB-World Network | www.html (1 of 2) [9/1/2002 5:28:32 PM] . Greenwich Mean Time (GMT)). a.a.com .92/vbapi/ref/g/getsystemtime. not in the system's local time. Windows NT: Requires Windows NT 3.26.

168.26. ":". E-mail: vbapi@vbapi. Go back to the Reference section index.html (2 of 2) [9/1/2002 5:28:32 PM] .com Send Encrypted E-Mail This page is at http://www.wHour. England. 1999 This page is copyright © 1999 Paul Kuliniewicz.html http://216.http://216.Print "In Greenwich. utctime. ' Display the current time in UTC time (along the Prime Meridian). SetSystemTime Category Time Go back to the alphabetical Function listing.168. utctime.vbapi. Copyright Information Revised October 29.html ' This code is licensed according to the terms and conditions listed here.26.wMinute. Dim utctime As SYSTEMTIME ' receives time and date GetSystemTime utctime ' put the time and date in UTC time into utctime Debug. GetSystemTimeAsFileTime. ":". Last Modified: October 2.com/ref/g/getsystemtime.92/vbapi/ref/g/getsystemtime.wSecond See Also GetLocalTime.92/vbapi/ref/g/getsystemtime. the time is". utctime. 2000 Go back to the Windows API Guide home page.

html (1 of 3) [9/1/2002 5:28:38 PM] . Return Value GetSystemTimeAsFileTime does not return a value.168.com | www.Windows API Guide: GetSystemTimeAsFileTime Function vbapi. Windows 98: Supported.vbsquare. Example http://216.a. Parameters lpSystemTimeAsFileTime Receives the current system date and time.com | www.dll" (lpSystemTimeAsFileTime As FILETIME) Platforms q q q q q Windows 95: Supported.vbworld.part of the VB-World Network | www.com | www.92/vbapi/ref/g/getsystemtimeasfiletime.vbforums.26. Description & Usage GetSystemTimeAsFileTime retrieves the current system date and time and places it into a FILETIME structure. Visual Basic-Specific Issues None. Windows NT: Requires Windows NT 3. Windows CE: Not Supported. Greenwich Mean Time (GMT)).vb-shop.com .vbapi. The system time is always reported in UTC time (Coordinated Universal Time.com | GetSystemTimeAsFileTime Function Declare Sub GetSystemTimeAsFileTime Lib "kernel32. a.com | www.5 or later. Windows 2000: Supported.k.

html (2 of 3) [9/1/2002 5:28:38 PM] .txt".txt for both read-level and ' write-level access.26. mtime) ' Get the system time (already in UTC) as a FILETIME structure. ctime. GENERIC_READ Or GENERIC_WRITE. ByVal CLng(0).txt to ' the current system date and time. retval = GetFileTime(hFile. OPEN_EXISTING. open the file C:\MyApp\test.Windows API Guide: GetSystemTimeAsFileTime Function ' This code is licensed according to the terms and conditions listed here.168. Leave the other times as they ' were before calling the function. get the creation. and last-modification times. hFile = CreateFile("C:\MyApp\test. mtime) ' Close the file to free up resources. atime. GetSystemTimeAsFileTime mtime ' Set the retrieved creation and access times and the new modification ' time as the file's times. last-access. ' Set the modification time of C:\MyApp\test. http://216. 0) If hFile = -1 Then Debug. ctime.Print "Could not open the file successfully -. retval = CloseHandle(hFile) See Also GetSystemTime Category Time Go back to the alphabetical Function listing. atime. FILE_SHARE_READ.aborting. retval = SetFileTime(hFile. Dim hFile As Long ' handle to the opened file Dim ctime As FILETIME ' the time of creation Dim atime As FILETIME ' the time of last access Dim mtime As FILETIME ' the time of last modification Dim retval As Long ' return value ' First. FILE_ATTRIBUTE_ARCHIVE." End ' terminate the program End If ' Next.92/vbapi/ref/g/getsystemtimeasfiletime. since we need to do both.

92/vbapi/ref/g/getsystemtimeasfiletime.com/ref/g/getsystemtimeasfiletime. 2000 Go back to the Windows API Guide home page.vbapi. E-mail: vbapi@vbapi. 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29.html http://216.168. Last Modified: October 2.26.Windows API Guide: GetSystemTimeAsFileTime Function Go back to the Reference section index.com Send Encrypted E-Mail This page is at http://www.html (3 of 3) [9/1/2002 5:28:38 PM] .

tempfile) ' get a unique temporary http://216.vbapi.html (1 of 2) [9/1/2002 5:28:45 PM] . where (path) ' is Windows's temporary file directory and ???? is a randomly assigned unique value. is put into the string variable passed as lpTempFileName. and the file is not created.com | www. lpPrefixString The first three characters of the filename. uuuu is a random number generated by Windows. preferably the temporary directory supplied by Windows. uuuu is the rightmost four digits of the number (in hexadecimal). If zero.vbsquare. The function returns the value used for uuuu if successful.TMP extension. temppath) ' read the path name temppath = Left(temppath. Win 95/98.26. If wUnique is non-zero. This is preferably the same path gotten from GetTempPath. The format of the generated filename is path\xxxuuuu.TMP. Win NT GetTempFileName generates a filename for a temporary file and optionally creates it for you.92/vbapi/ref/g/gettempfilename. "api". slength) ' extract data from the variable ' Get a uniquely assigned random file tempfile = Space(255) ' initialize buffer to receive the filename lastfour = GetTempFileName(temppath. If wUnique is zero. uuuu is a hexadecimal number between 0000 and FFFF. Example: ' Generate a temporary file (path)\api????.dll" Alias "GetTempFileNameA" (ByVal lpszPath As String. The full filename. and the file is created. lpszPath The path to put the temporary file into. xxx is the string specified in lpPrefixString. Temporary files are used to store data for short periods of time on the hard drive.TMP.part of the VB-World Network | www. path is the path to put the file in. this number's last four digits in hexidecimal are the last four characters in the filename. 0.vbforums.com | www.168. lpTempFileName A string that receives the path and filename of the temporary file.com | www. This method will work even if a file with that name already exists.com | GetTempFileName Function Declare Function GetTempFileName Lib "kernel32. ByVal wUnique As Long. Dim temppath As String ' receives name of temporary file path Dim tempfile As String ' receives name of temporary file Dim slength As Long ' receives length of string returned for the path Dim lastfour As Long ' receives hex value of the randomly assigned ???? ' Get Windows's temporary file path temppath = Space(255) ' initialize the buffer to receive the path slength = GetTempPath(255. or 0 if an error occured.com . ByVal lpPrefixString As String. which can be gotten through GetTempPath.vbshop. and the file is not created. including the path. and the file is created. the last four characters are generated by Windows.Windows API Guide: GetTempFileName Function vbapi. Temporary files always have a .com | www. ' Then display the name of the created file on the screen. wUnique If non-zero.vbworld. ByVal lpTempFileName As String) As Long Platforms: Win 32s.

Go back to the Reference section index.Print "Temporary filename: ". vbNullChar) .net This page is at http://www.Windows API Guide: GetTempFileName Function file name ' (Note that the file is also created for you in this case.html (2 of 2) [9/1/2002 5:28:45 PM] . InStr(tempfile.1) ' extract data from the variable Debug.vbapi. Go back to the Windows API Guide home page.26. E-mail: rogue953@st-louis.92/vbapi/ref/g/gettempfilename.168.) tempfile = Left(tempfile.html http://216. tempfile See Also: GetTempPath Category: Files Go back to the alphabetical Function listing.com/ref/g/gettempfilename.crosswinds.

tempfile See Also: GetTempFileName Category: System Information http://216.168.dll" Alias "GetTempPathA" (ByVal nBufferLength As Long.TMP.com | www. Win NT GetTempPath determines Windows's default Temp directory.vbforums. slength) ' extract data from the variable ' Get a uniquely assigned random file tempfile = Space(255) ' initialize buffer to receive the filename lastfour = GetTempFileName(temppath. The Temp directory is where temporary files made and used by Windows-based programs should be put. Example: ' Generate a temporary file (path)\api????.Windows API Guide: GetTempPath Function vbapi. InStr(tempfile. "api". but not necessarily.part of the VB-World Network | www. where (path) ' is Windows's temporary file directory and ???? is a randomly assigned unique value.com | GetTempPath Function Declare Function GetTempPath Lib "kernel32. or 0 if it fails. Dim temppath As String ' receives name of temporary file path Dim tempfile As String ' receives name of temporary file Dim slength As Long ' receives length of string returned for the path Dim lastfour As Long ' receives hex value of the randomly assigned ???? ' Get Windows's temporary file path temppath = Space(255) ' initialize the buffer to receive the path slength = GetTempPath(255. The path of the directory is put into the string variable passed as lpBuffer. Win 95/98.26.Print "Temporary filename: ". ByVal lpBuffer As String) As Long Platforms: Win 32s.com | www. Usually this will be the \Temp subdirectory under the Windows directory.1) ' extract data from the variable Debug. The function returns the length of the string returned by the function if it succeeds. nBufferLength The length in characters of lpBuffer lpBuffer A string that will receive the path of the Temp directory. ' Then display the name of the created file on the screen.) tempfile = Left(tempfile.vbshop. 0.com | www. temppath) ' read the path name temppath = Left(temppath.com | www. vbNullChar) .vbworld.92/vbapi/ref/g/gettemppath.html (1 of 2) [9/1/2002 5:28:54 PM] .vbsquare. tempfile) ' get a unique temporary file name ' (Note that the file is also created for you in this case.vbapi.com .

Go back to the Reference section index.net This page is at http://www.crosswinds.Windows API Guide: GetTempPath Function Go back to the alphabetical Function listing. E-mail: rogue953@st-louis.168. Go back to the Windows API Guide home page.com/ref/g/gettemppath.html (2 of 2) [9/1/2002 5:28:54 PM] .vbapi.26.92/vbapi/ref/g/gettemppath.html http://216.

com .168.vbapi.hDC) ' get the text alignment setting of the window If (refpoint And TA_RIGHT) = TA_RIGHT Then ' ref. one determines current point updating): TA_BASELINE = 24 The reference point will be on the baseline of the text. TA_TOP = 0 The reference point will be on the top edge of the bounding rectangle of the text.vbsquare.Windows API Guide: GetTextAlign Function vbapi. TA_LEFT = 0 The reference point will be on the left edge of the bounding rectangle of the text. TA_BOTTOM = 8 The reference point will be on the bottom edge of the bounding rectangle of the text. Example: ' Display whether window Form1 will display text left-justified. Win NT GetTextAlign determines how a device displays a line of text relative to a given reference point.part of the VB-World Network | www.com | www. hdc The device context of the device to find the reference point settings of. TA_UPDATECP = 1 Set the current point to the reference point.com | www.com | GetTextAlign Function Declare Function GetTextAlign Lib "gdi32." ElseIf (refpoint And TA_CENTER) = TA_CENTER Then ' ref.vbworld. point on right edge Debug. The reference point is the point used to specify where the device should display a line of text.dll" (ByVal hdc As Long) As Long Platforms: Win 32s.vbshop. TA_NOUPDATECP = 0 Do not set the current point to the reference point. The function returns exactly three of the following flags specifying where this reference point will be relative to the text (one flag specifies horizontal position. ' centered. one specifies vertical position.vbforums. Dim refpoint As Long ' receives reference point settings refpoint = GetTextAlign(Form1.Print "Text will be displayed right-justified. TA_RIGHT = 2 The reference point will be on the right edge of the bounding rectangle of the text. TA_CENTER = 6 The reference point will be horizontally centered along the bounding rectangle of the text. point horizontally centered Debug.92/vbapi/ref/g/gettextalign.26. Win 95/98.com | www. TA_RTLREADING = 256 Win 95/98 only:Display the text right-to-left (if the font is designed for right-to-left reading).Print "Text will be displayed centered horizontally.html (1 of 2) [9/1/2002 5:29:04 PM] ." http://216. or right-justified relative to a given reference point.com | www.

TextOut Category: Fonts & Text Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz.html http://216.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:29:04 PM] .26. point on left edge Debug. Copyright Information." End If See Also: SetTextAlign.vbapi. Go back to the Reference section index.92/vbapi/ref/g/gettextalign.168.Print "Text will be displayed left-justified.Windows API Guide: GetTextAlign Function Else ' assume ref.com/ref/g/gettextalign. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page.

Windows CE: Not Supported. they are switched. The sorting method simply compares each possible ' pair of words. Windows NT: Requires Windows NT 3. Parameters None.part of the VB-World Network | www. ' Use a case-senitive.com | GetThreadLocale Function Declare Function GetThreadLocale Lib "kernel32.e.com | www.vbshop.26. Example ' This code is licensed according to the terms and conditions listed here.vbsquare.dll" () As Long Platforms q q q q q Windows 95: Supported. if a pair is out of alphabetical order.vbforums. This locale determines the default preferences for display of various data for the program and may be different than that of other threads..com | www. Windows 98: Supported. Dim words(1 To 9) As String ' the words to sort Dim tempstr As String ' buffer used to swap strings Dim oc As Integer. Return Value The function returns the identifier of the calling thread's locale. Visual Basic-Specific Issues None.92/vbapi/ref/g/getthreadlocale. your program's thread). ic As Integer ' counter variables http://216.vbapi.1 or later.com | www.html (1 of 3) [9/1/2002 5:29:12 PM] .168.com | www.vbworld. Windows 2000: Supported. Description & Usage GetThreadLocale identifies the locale of the thread which called the function (i.Windows API Guide: GetThreadLocale Function vbapi.com . string sort comparison method to alphabetically ' sort nine words.

Go back to the Reference section index. threadlocale = GetThreadLocale() ' Load the words(1) = words(2) = words(3) = words(4) = words(5) = words(6) = words(7) = words(8) = words(9) = nine strings into the array. "can't" "cant" "cannot" "pants" "co-op" "coop" "Denver" "denver" "denveR" ' Sort the strings.. For oc = 1 To 8 ' first string of the pair For ic = oc + 1 To 9 ' second string of the pair ' Compare the two strings.26. If compval = CSTR_GREATER_THAN Then tempstr = words(oc) words(oc) = words(ic) words(ic) = tempstr End If Next ic Next oc ' Display the list of sorted words. swap them.html (2 of 3) [9/1/2002 5:29:12 PM] . Len(words(oc)). of this program).e. Len(words(ic))) ' If words(oc) is greater. For oc = 1 To 9 Debug.168. words(ic). SORT_STRINGSORT. http://216. compval = CompareString(threadlocale.92/vbapi/ref/g/getthreadlocale. swapping any pairs which are out of order. words(oc).Print words(oc) Next oc See Also SetThreadLocale Category National Language Support Go back to the alphabetical Function listing.Windows API Guide: GetThreadLocale Function Dim compval As Long ' result of comparison Dim threadlocale As Long ' locale ID of this thread ' Get the locale of this thread (i.

2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.92/vbapi/ref/g/getthreadlocale.Windows API Guide: GetThreadLocale Function Last Modified: January 4.html (3 of 3) [9/1/2002 5:29:12 PM] . Copyright Information Revised October 29.168.com/ref/g/getthreadlocale.26. 2000 This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.vbapi.html http://216.

168.dll" () As Long Platforms q q q q q Windows 95: Supported.vbworld. although the actual resolution of the function's output depends on that of the system timer itself.com | www.vbforums.vbsquare.vb-shop.7 days of continuous operation.com . http://216.com | www. it may not be perfectly accurate to the millisecond. Windows NT: Requires Windows NT 3.html (1 of 2) [9/1/2002 5:29:19 PM] .com | www.part of the VB-World Network | www. The time is measured in milliseconds. Description & Usage GetTickCount determines how much time has elapsed since Windows was last started.vbapi.1 or later.com | www. Windows 2000: Supported. the reported elapsed time wraps back to zero after about 49. Example ' This code is licensed according to the terms and conditions listed here. Because of the limitations of the 32-bit integer data type.com | GetTickCount Function Declare Function GetTickCount Lib "kernel32.Windows API Guide: GetTickCount Function vbapi. Windows 98: Supported. Therefore.92/vbapi/ref/g/gettickcount. Parameters None. Return Value The function returns the number of milliseconds that have passed since Windows was last started. Visual Basic-Specific Issues None. Windows CE: Unknown.26.

92/vbapi/ref/g/gettickcount. Last Modified: March 19.168.26. 2000 Go back to the Windows API Guide home page. endtime = GetTickCount() ' The difference between starttime and endtime is the time it took ' to calculate the square root. Debug." Category Time Back to the Function list. E-mail: vbapi@vbapi.Print "The calculation took".com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29. Dim starttime As Long ' timer value before the calculation Dim endtime As Long ' timer value after the calculation Dim result As Double ' receives result of square root operation ' Find how much time has passed since Windows was started. result = Sqr(54761) ' Find how much time has now passed since startup.vbapi. (endtime . Back to the Reference section. starttime = GetTickCount() ' Calculate the square root of a large number.starttime) / 1000.html (2 of 2) [9/1/2002 5:29:19 PM] .com/ref/g/gettickcount.Windows API Guide: GetTickCount Function ' Determine about how much time it takes for Visual ' Basic to compute the square root of a large number.html http://216. 2000 This page is copyright © 2000 Paul Kuliniewicz. The elapsed ' time for that operation is displayed in seconds. "seconds.

com | www. LOCALE_USER_DEFAULT http://216. Return Value If an error occured. Windows 98: Supported.part of the VB-World Network | www. ByVal dwFlags As Long.html (1 of 4) [9/1/2002 5:29:35 PM] .92/vbapi/ref/g/gettimeformat.com | www. The time can be formatted using either a predefined format or a custom format specified in the parameter list.Windows API Guide: GetTimeFormat Function vbapi.168. the function returns the size in bytes of the string placed into the variable passed as lpTimeStr. Parameters Locale The identifier of the locale to use to format the string as necessary.dll" Alias "GetTimeFormatA" (ByVal Locale As Long.vbforums. the locale of the calling thread is used.26.vbworld. Visual Basic-Specific Issues When passing 0 for the lpFormat parameter.vbsquare. This can also be one of the following flags specifying a default locale: LOCALE_SYSTEM_DEFAULT The system's default locale.0 or later. the expression CLng(0) must be used. lpTime As SYSTEMTIME.com .com | GetTimeFormat Function Declare Function GetTimeFormat Lib "kernel32. ByVal cchTime As Long) As Long Platforms q q q q q Windows 95: Supported.vbapi.vbshop.com | www. Description & Usage GetTimeFormat formats a string to display a time according to a locale's settings. ByVal lpFormat As Any. Windows NT: Requires Windows NT 3. ByVal lpTimeStr As String. Windows CE: Requires Windows CE 1.5 or later. The string generated by this function can be used to present a more human-readable way to display a time. the function returns 0 (use GetLastError to get the error code).com | www. Windows 2000: Supported. If successful. If this is 0.

hh Hours with a leading zero for single-digit hours. TIME_FORCE24HOURFORMAT Use a 24-hour time format. To use one of the predefined formats.168. t A one-character AM/PM indicator. this parameter must be 0. this parameter must be set to 0. s Seconds without a leading zero for single-digit seconds. ss Seconds with a leading zero for single-digit seconds. lpTime The time to format as a string. the following series of characters stand for the following components of the time: h Hours without a leading zero for single-digit hours. m Minutes without a leading zero for single-digit minutes. If a format string is passed as lpFormat. lpTimeStr Receives the formatted time string. mm Minutes with a leading zero for single-digit minutes. HH Hours with a leading zero for single-digit hours. using a 12-hour clock. H Hours without a leading zero for single-digit hours. In a format template string. To place any other "fixed" characters or text in the format string. dwFlags A combination of the following flags specifying how to format the time string. you must enclose the literal text in single quotation marks. TIME_NOTIMEMARKER Do not display an AM/PM marker. LOCALE_NOUSEROVERRIDE Use the system's default time format for the specified locale. using a 24-hour clock. This must initally be sufficiently long to receive the string. ignoring any changes to those defaults which the user may have selected. LOCALE_USE_CP_ACP Use the system's ANSI code page for string translation instead of the locale's code page. TIME_NOMINUTESORSECONDS Do not display minutes or seconds. lpFormat The format template string used to generate the time string. using a 12-hour clock.26. tt A two-character AM/PM indicator. using a 24-hour clock.92/vbapi/ref/g/gettimeformat. Any spaces appearing in the template string appear verbatim in the formatted string.html (2 of 4) [9/1/2002 5:29:35 PM] . http://216. cchTime The length of the string passed as lpTimeStr. The members of the structure which specify the date are ignored. TIME_NOSECONDS Do not display seconds.Windows API Guide: GetTimeFormat Function The user's default locale.

strlen = GetTimeFormat(0. strlen) ' Display today's time using that format. timestr. strlen) ' Display today's time in aforementioned format. strlen = GetTimeFormat(0. Debug.26. Debug.92/vbapi/ref/g/gettimeformat. timestr.Print "It is currently ". timestr = Left(timestr. Len(timestr)) ' Remove the empty space from the formatted string.g. 8:27 AM is 0827 hours).Windows API Guide: GetTimeFormat Function Constant Definitions Const Const Const Const Const Const Const Const LOCALE_SYSTEM_DEFAULT = &H400 LOCALE_USER_DEFAULT = &H800 LOCALE_NOUSEROVERRIDE = &H80000000 LOCALE_USE_CP_ACP = &H40000000 TIME_NOMINUTESORSECONDS = &H1 TIME_NOSECONDS = &H2 TIME_NOTIMEMARKER = &H4 TIME_FORCE24HOURFORMAT = &H8 Example ' This code is licensed according to the terms and conditions listed here. CLng(0)..168. Dim today As SYSTEMTIME ' today's date and time Dim timestr As String ' receives the formatted time string Dim strlen As Long ' length of the buffer for the formatted time string ' Get today's date and time in the local time zone.html (3 of 4) [9/1/2002 5:29:35 PM] . "HHmm 'hours'".Print "It is currently ". GetLocalTime today ' Make sufficient room in the buffer to receive the time string. today. timestr = Space(255) ' Format today's time as hours-minutes-AM/PM. today. timestr ' Now make sufficient room once again. ' Display today's time first using a "regular" hours-minutes' AM/PM string and then using a "military hours" format (e. 0. timestr = Space(255) ' Format today's time in the military-esque format. Len(timestr)) ' Remove the empty space from the formatted time string. timestr See Also GetDateFormat http://216. TIME_NOSECONDS. timestr = Left(timestr.

html http://216. Last Modified: January 3.92/vbapi/ref/g/gettimeformat. 2000 Go back to the Windows API Guide home page.26.com/ref/g/gettimeformat. Copyright Information Revised October 29. E-mail: vbapi@vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz.Windows API Guide: GetTimeFormat Function Category National Language Support Go back to the alphabetical Function listing.com Send Encrypted E-Mail This page is at http://www. Go back to the Reference section index.html (4 of 4) [9/1/2002 5:29:35 PM] .168.vbapi.

Since Windows handles all of the system clock settings.vbshop. http://216. instead of being stored in a string.Print "The computer's time zone is: ".StandardName(c) = 0 Then Exit For ' abort if the terminating null character is reached Debug. The information is put into the variable passed as lpTimeZoneInformation. or a 1 if successful.vbsquare. This page is copyright © 2000 Paul Kuliniewicz.StandardName(c)) ' convert the ASCII code into a character and display it Next c Debug.168.vbapi.dll" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long Platforms: Win 95/98. lpTimeZoneInformation Variable which receives the information about the system time zone. ' This loop converts the array into a readable string.com | www. The function returns 0 if an error occured. Example: ' Display the name of the time zone the computer is set to.Print Chr(tzi. Debug.html (1 of 2) [9/1/2002 5:29:41 PM] .com .Print "" ' end the line being displayed Category: Time Go back to the alphabetical Function listing.vbforums.vbworld.com | www.com | www. the time zone name is stored in a ' 32-element array.com | GetTimeZoneInformation Function Declare Function GetTimeZoneInformation Lib "kernel32. there usually isn't a need for other programs to use this information.26. For c = 0 To 31 ' the array's range is from 0 to 31 If tzi.com | www. each element holding the ASCII code of one of the characters.Windows API Guide: GetTimeZoneInformation Function vbapi. Dim tzi As TIME_ZONE_INFORMATION ' receives information on the time zone Dim retval As Long ' return value Dim c As Long ' counter variable needed to display time zone name retval = GetTimeZoneInformation(tzi) time zone ' read information on the computer's selected ' Oddly.92/vbapi/ref/g/gettimezoneinformation.part of the VB-World Network | www. Win NT GetTimeZoneInformation reads the computer's current time zone settings. Go back to the Reference section index. Copyright Information.

168.html http://216.vbapi.html (2 of 2) [9/1/2002 5:29:41 PM] .92/vbapi/ref/g/gettimezoneinformation. E-mail: vbapi@vbapi.com/ref/g/gettimezoneinformation.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: GetTimeZoneInformation Function Go back to the Windows API Guide home page.26.

vbsquare. ' (In VB.92/vbapi/ref/g/gettopwindow. 1): Sleep 250 retval = FlashWindow(active. If an error occurs or the window has no children. the function instead returns 0.Windows API Guide: GetTopWindow Function vbapi. Go back to the Windows API Guide home page. http://216.part of the VB-World Network | www.26.hWnd) ' get the handle of MDIForm1's active child window If active <> 0 Then ' don't try to flash if there is no child window ' The next three lines flags the window once. retval = FlashWindow(active. This page is copyright © 2000 Paul Kuliniewicz. This function works even if the parent window is not active. The active child window is the one that has the focus. Example: ' Flash the MDI form window MDIForm1's active child once. Copyright Information. Go back to the Reference section index. This function is identical to calling GetWindow using the GW_CHILD relationship.168.com | www.vbworld.com | www. hwnd The handle of the parent window.dll" (ByVal hwnd As Long) As Long Platforms: Win 32s. 1): Sleep 250 retval = FlashWindow(active.com . The function will return its active child window. 0) End If See Also: GetWindow Category: Windows Go back to the alphabetical Function listing.vbforums.html (1 of 2) [9/1/2002 5:29:53 PM] . Win 95/98.com | GetTopWindow Function Declare Function GetTopWindow Lib "user32.com | www.com | www. a MDI form has child windows).vbapi. Win NT GetTopWindow returns a handle to the currently active child window of a window.vbshop. and it is usually at the top of all the other children in the Z-order. Dim active As Long ' receives handle to the MDI form's active window Dim retval As Long ' return value used for flashing the child window active = GetTopWindow(MDIForm1.

Windows API Guide: GetTopWindow Function

E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/gettopwindow.html

http://216.26.168.92/vbapi/ref/g/gettopwindow.html (2 of 2) [9/1/2002 5:29:53 PM]

Windows API Guide: GetUserName Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetUserName Function
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Platforms: Win 95/98, Win NT GetUserName retrieves the name of the user who is logged on to Windows. This user's saved settings are the ones used during the current Windows session. The name of the user is placed in the string passed as lpBuffer. The function puts the size of the returned string into the variable passed as nSize. The function returns 0 if an error occured, or a non-zero value if successful. lpBuffer String which receives the name of the user logged on to Windows. The string passed must have sufficient room to receive the string the function will give it. nSize The size of the string passed to the function. The variable passed as this parameter also receives the size of the returned string (including the terminating null character). Example: ' Display the name of the user currently logged on. Dim username As String ' receives name of the user Dim slength As Long ' length of the string Dim retval As Long ' return value ' Create room in the buffer to receive the returned string. username = Space(255) ' room for 255 characters slength = 255 ' initialize the size of the string ' Get the user's name and display it. retval = GetUserName(username, slength) ' slength is now the length of the returned string username = Left(username, slength - 1) ' extract the returned info from the buffer ' (We subtracted one because we don't want the null character in the trimmed string.) Debug.Print "The name of the current user is "; username Category: System Information Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page.
http://216.26.168.92/vbapi/ref/g/getusername.html (1 of 2) [9/1/2002 5:30:04 PM]

Windows API Guide: GetUserName Function

E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getusername.html

http://216.26.168.92/vbapi/ref/g/getusername.html (2 of 2) [9/1/2002 5:30:04 PM]

Windows API Guide: GetVersionEx Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetVersionEx Function
Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Platforms: Win 32s, Win 95/98, Win NT GetVersionEx reads information about the version of Windows running as the operating system. This information includes the strict version number and platform (3.x with Win32s, Windows 95, Windows NT, Windows 98, etc.). The information is put into the variable passed as lpVersionInformation. The function returns 0 if an error occured, or a 1 if successful. lpVersionInformation Receives the version information for the operating system. Example: ' Display the major and minor version numbers of Windows. ' For example, 4.0 could represent Windows 95. Dim os As OSVERSIONINFO ' receives version information Dim retval As Long ' return value os.dwOSVersionInfoSize = Len(os) ' set the size of the structure retval = GetVersionEx(os) ' read Windows's version information Debug.Print "Windows version number:"; os.dwMajorVersion; "."; os.dwMinorVersion Category: System Information Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getversionex.html

http://216.26.168.92/vbapi/ref/g/getversionex.html [9/1/2002 5:30:12 PM]

Windows API Guide: GetVolumeInformation Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetVolumeInformation Function
Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
GetVolumeInformation retrieves information describing a disk volume and the file system it uses. This information includes things such as the volume label and the disk's serial number.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a nonzero value.

Visual Basic-Specific Issues
None.

Parameters
lpRootPathName The root directory of the disk volume to be described. This directory must include a trailing backslash character. For example, to describe the C: drive, this would be "C:\". lpVolumeNameBuffer Receives the null-terminated volume label of the volume. This string must be large enough to receive the text. nVolumeNameSize The length of the string passed as lpVolumeNameBuffer. lpVolumeSerialNumber
http://216.26.168.92/vbapi/ref/g/getvolumeinformation.html (1 of 4) [9/1/2002 5:30:22 PM]

Windows API Guide: GetVolumeInformation Function

Receives the serial number of the volume. When displayed, this value should be shown in hexadecimal with a dash before the last four hex digits. Windows 95/98: If the volume is a netword drive, the serial number will not be retrieved. lpMaximumComponentLength Receives the maximum length of a file name component supported by the file system. A file name component is any portion of a file name between backslashes. This value is used primarily to determine if the volume supports long file names or if it is limited to the old 8.3 system. lpFileSystemFlags A combination of the following flags describing other features of the file system used by the volume: FS_CASE_IS_PRESERVED The file system preserves the case of file names. FS_CASE_SENSITIVE The file system uses case-sensitive file names. FS_UNICODE_STORED_ON_DISK The file system supports Unicode in file names as they appear on disk. FS_PERSISTENT_ACLS The file system preserves and enforces access control lists (ACLs). FS_FILE_COMPRESSION The file system supports file-based compression, where individual files can be compressed while others are not. FS_VOL_IS_COMPRESSED The entire volume is compressed; for example, DoubleSpace has been used on the disk. FILE_NAMED_STREAMS The file system supports named streams. FILE_SUPPORTS_ENCRYPTION The file system supports the Encrypted File System (EFS). FILE_SUPPORTS_OBJECT_IDS The file system supports object identifiers. FILE_SUPPORTS_REPARSE_POINTS The file system supports reparse points. FILE_SUPPORTS_SPARSE_FILES The file system supports sparse files. FILE_VOLUME_QUOTAS The file system supports disk quotas. lpFileSystemNameBuffer Receives the null-terminated name of the file system. This string must be long enough to receive the text. nFileSystemNameSize The length of the string passed as lpFileSystemNameBuffer.

Constant Definitions
Const Const Const Const Const Const Const Const Const FS_CASE_IS_PRESERVED = &H2 FS_CASE_SENSITIVE = &H1 FS_UNICODE_STORED_ON_DISK = &H4 FS_PERSISTENT_ACLS = &H8 FS_FILE_COMPRESSION = &H10 FS_VOLUME_IS_COMPRESSED = &H8000 FILE_NAMED_STREAMS = &H40000 FILE_SUPPORTS_ENCRYPTION = &H20000 FILE_SUPPORTS_OBJECT_IDS = &H10000

http://216.26.168.92/vbapi/ref/g/getvolumeinformation.html (2 of 4) [9/1/2002 5:30:22 PM]

Windows API Guide: GetVolumeInformation Function

Const FILE_SUPPORTS_REPARSE_POINTS = &H80 Const FILE_SUPPORTS_SPARSE_FILES = &H40 Const FILE_VOLUME_QUOTAS = &H20

Example
' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetVolumeInformation Lib "kernel32.dll" Alias _ "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer _ As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _ lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal _ lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long ' Display the volume label, serial number, and file system name ' of the C: drive. Note how the serial number value is manipulated to ' display it properly. Dim volname As String ' receives volume name of C: Dim sn As Long ' receives serial number of C: Dim snstr As String ' display form of serial number Dim maxcomplen As Long ' receives maximum component length Dim sysflags As Long ' receives file system flags Dim sysname As String ' receives the file system name Dim retval As Long ' return value ' Initialize string buffers. volname = Space(256) sysname = Space(256) ' Get information about the C: drive's volume. retval = GetVolumeInformation("C:\", volname, Len(volname), sn, maxcomplen, _ sysflags, sysname, Len(sysname)) ' Remove the trailing nulls from the two strings. volname = Left(volname, InStr(volname, vbNullChar) - 1) sysname = Left(sysname, InStr(sysname, vbNullChar) - 1) ' Format the serial number properly. snstr = Trim(Hex(sn)) snstr = String(8 - Len(snstr), "0") & snstr snstr = Left(snstr, 4) & "-" & Right(snstr, 4) ' Display the volume name, serial number, and file system name. Debug.Print "Volume Name: "; volname Debug.Print "Serial Number: "; snstr Debug.Print "File System: "; sysname

See Also
SetVolumeLabel

http://216.26.168.92/vbapi/ref/g/getvolumeinformation.html (3 of 4) [9/1/2002 5:30:22 PM]

Windows API Guide: GetVolumeInformation Function

Category
File System Back to the Function list. Back to the Reference section.

Last Modified: June 4, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getvolumeinformation.html

http://216.26.168.92/vbapi/ref/g/getvolumeinformation.html (4 of 4) [9/1/2002 5:30:22 PM]

Windows API Guide: GetWindow Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

GetWindow Function
Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetWindow returns the handle of a window related to a given window. The relations generally deal with childparent relationships or relationships among children of the same parent window. The exact relation is specified by wCmd. If an error occurs or there is no window having the specified relation, the function instead returns 0. hwnd The handle of the first window in the relation. wCmd Exactly one of the following flags specifying which relationship the returned window has to the given window: GW_HWNDFIRST = 0 The highest window in the Z-order having the same parent as the given window. GW_HWNDLAST = 1 The lowest window in the Z-order having the same parent as the given window. GW_HWNDNEXT = 2 The window below the given window in the Z-order. GW_HWNDPREV = 3 The window above the given window in the Z-order. GW_OWNER = 4 The window that owns the given window (not to be confused with the parent window). GW_CHILD = 5 The topmost of the given window's child windows. This has the same effect as using the GetTopWindow function. Example: ' Flash the application's window that is below Form1 in the Z-order ' once. Dim next As Long ' receives handle of next window in the Z-order Dim retval As Long ' return value for flashing the window next = GetWindow(Form1.hWnd, GW_HWNDNEXT) ' get the handle of the next window If next <> 0 Then ' don't try to flags if no such window exists ' The next three lines flags the window once.

http://216.26.168.92/vbapi/ref/g/getwindow.html (1 of 2) [9/1/2002 5:30:28 PM]

Windows API Guide: GetWindow Function

retval = FlashWindow(next, 1): Sleep 250 retval = FlashWindow(next, 1): Sleep 250 retval = FlashWindow(next, 0) End If See Also: GetActiveWindow, GetTopWindow Category: Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindow.html

http://216.26.168.92/vbapi/ref/g/getwindow.html (2 of 2) [9/1/2002 5:30:28 PM]

Windows API Guide: GetWindowLong Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetWindowLong Function
Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetWindowLong retrieves a 32-bit value from the information about a window. This function can also read a 32-bit value from the block of extra memory given to the window, if one exists.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the 32bit value which was retrieved.

Visual Basic-Specific Issues
None.

Parameters
hWnd A handle to the window to retrieve a 32-bit value from. nIndex To get a 32-bit value from the window's extra memory block, this is the zero-based offset of the byte to begin reading from. Valid values range from 0 to the size of the extra memory block in bytes minus four. To get a 32-bit value from the properties of the window, this is one of the following flags specifying which piece of information to retieve: GWL_EXSTYLE Retrieve the extended window styles of the window. GWL_HINSTANCE Retrieve a handle to the owning application's instance.

http://216.26.168.92/vbapi/ref/g/getwindowlong.html (1 of 3) [9/1/2002 5:30:34 PM]

Windows API Guide: GetWindowLong Function

GWL_HWNDPARENT Retrieve a handle to the parent window, if any. GWL_ID Retrieve the identifier of the window. GWL_USERDATA Retrieve the application-defined 32-bit value associated with the window. GWL_STYLE Retrieve the window styles of the window. GWL_WNDPROC Retrieve a pointer to the WindowProc hook function acting as the window's procedure. If the window happens to be a dialog box, this could also be one of the following flags: DWL_DLGPROC Retrieve a handle to the WindowProc hook function acting as the dialog box procedure. DWL_MSGRESULT Retrieve the return value of the last message processed by the dialog box. DWL_USER Retrieve the application-defined 32-bit value associated with the dialog box.

Constant Definitions
Const Const Const Const Const Const Const Const Const Const GWL_EXSTYLE = -20 GWL_HINSTANCE = -6 GWL_HWNDPARENT = -8 GWL_ID = -12 GWL_STYLE = -16 GWL_USERDATA = -21 GWL_WNDPROC = -4 DWL_DLGPROC = 4 DWL_MSGRESULT = 0 DWL_USER = 8

Example
When the user clicks button Command1, determine if its parent window has a maximize button or not by checking its window style. To use this example, you must first place a command button named Command1 on a form window. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Public Const GWL_STYLE = -16 Public Const WS_MAXIMIZEBOX = &H10000 ' *** Place the following code inside a form window. *** Private Sub Command1_Click ()

http://216.26.168.92/vbapi/ref/g/getwindowlong.html (2 of 3) [9/1/2002 5:30:34 PM]

Windows API Guide: GetWindowLong Function

Dim styles As Long

' receives window styles of Form1

' Get the window styles of Form1. styles = GetWindowLong(Me.hWnd, GWL_STYLE) ' Determine if a maximize box exists or not. If (styles And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then Debug.Print "The form window has a maximize box." Else Debug.Print "The form window does not have a maximize box." End If End Sub

See Also
GetClassLong, SetWindowLong

Category
Window Classes Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: October 29, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowlong.html

http://216.26.168.92/vbapi/ref/g/getwindowlong.html (3 of 3) [9/1/2002 5:30:34 PM]

Windows API Guide: GetWindowRect Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetWindowRect Function
Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long Platforms: Win 32s, Win 95/98, Win NT GetWindowRect reads the size and position of a window. This information is put into the variable passed as lpRect. The rectangle receives the coordinates of the upper-left and lower-right corners of the window. If the window is past one of the edges of the screen, the values will reflect that (for example, if the left edge of a window is off the screen, the rectangle's .Left property will be negative). The function returns 0 if an error occured, or 1 if successful. hwnd The handle of the window to read the position and width of. lpRect Variable that receives the coordinates of the upper-left and lower-right corners of the window. Example: ' Display the width and height of window Form1 ' Width and height can be calculated from the coordinates returned in the rectangle. Dim r As RECT ' receives window rectangle Dim retval As Long ' return value retval = GetWindowRect(Form1.hWnd, r) ' set r equal to Form1's rectangle Debug.Print "Width ="; r.Right - r.Left Debug.Print "Height ="; r.Bottom - r.Top See Also: MoveWindow, SetWindowPos Category: Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowrect.html

http://216.26.168.92/vbapi/ref/g/getwindowrect.html [9/1/2002 5:30:41 PM]

Windows API Guide: GetWindowsDirectory Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetWindowsDirectory Function
Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetWindowsDirectory reads the path of the Windows directory. This is where Windows itself is stored, along will all of the little applets that come with it. Never assume this is "C:\Windows" because it doesn't necessarily have to be there. The directory is put into the string variable passed as lpBuffer. The function returns the length of the returned string if successful, or 0 if an error occured. lpBuffer String variable that receives the path. nSize The length in characters of lpBuffer. Example: ' Display the location of the Windows directory Dim windir As String ' receives path of Windows directory Dim slength As Long ' receives length of the string returned windir = Space(255) ' initialize buffer to receive the string slength = GetWindowsDirectory(windir, 255) ' read the path of the Windows directory windir = Left(windir, slength) ' extract the returned string from the buffer Debug.Print "The Windows directory is at: "; windir See Also: GetSystemDirectory Category: System Information Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowsdirectory.html

http://216.26.168.92/vbapi/ref/g/getwindowsdirectory.html [9/1/2002 5:30:49 PM]

Windows API Guide: GetWindowRgn Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetWindowRgn Function
Declare Function GetWindowRgn Lib "user32.dll" (ByVal hWnd As Long, ByVal hRgn As Long) As Long

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.51 or later. Windows 2000: Supported. Windows CE: Not Supported.

Description & Usage
GetWindowRgn obtains a copy of a window's current region. If a non-empty region is applied to a window, it resticts the area of the window that is visible, effectively changing its shape as far as the user is concerned. This function copies a window's region into a second region passed to the function.

Return Value
The function returns one of the following flags specifying the result of the region combination operation: ERROR An error occured while trying to combine the regions. NULLREGION The combined region is empty, i.e., null. SIMPLEREGION The combined region forms a rectangle. COMPLEXREGION The combined region is not empty but is also not a rectangle.

Visual Basic-Specific Issues
None.

Parameters
hWnd A handle to the window to get the region of.
http://216.26.168.92/vbapi/ref/g/getwindowrgn.html (1 of 4) [9/1/2002 5:30:58 PM]

Windows API Guide: GetWindowRgn Function

hRgn A handle to a region that receives a copy of the window's region. It doesn't matter what the region passed to the function happens to be, because it is overwritten by the function.

Constant Definitions
Const Const Const Const ERROR = 0 NULLREGION = 1 SIMPLEREGION = 2 COMPLEXREGION = 3

Example
Use an elliptic region to make window Form1 appear elliptical. Notice how, as this example is written, a portion of the title bar is still visible after applying the region. This allows us to move the window without adding any special code providing a different way for the user to move the window. Normally, in a real program, you would not want the title bar to be displayed, but after all, this is just an example. At least it shows you that the region only changes what part of the window you can see -it doesn't change anything else about the window. To run this example, make two windows Form1 and Form2. The latter will be used to illustrate GetWindowRgn. Place the following three buttons on Form1: a button labeled "Apply Region" and named cmdApplyRegion, a button labeled "Remove Region" and named cmdRemoveRegion, and a button labeled "Show Region" and named cmdShowRegion. Place these buttons near the center of Form1 to make sure parts of them won't be hidden when the region is applied. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetWindowRgn Lib "user32.dll" (ByVal hWnd As Long, ByVal hRgn As Long) As Long Public Declare Function SetWindowRgn Lib "user32.dll" (ByVal hWnd As Long, ByVal hRgn As Long, _ ByVal bRedraw As Boolean) As Long Public Declare Function CreateEllipticRgn Lib "gdi32.dll" (ByVal nLeftRect As Long, ByVal nTopRect _ As Long, ByVal nRightRect As Long, ByVal nBottomRect As Long) As Long Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Public Declare Function InvertRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hrgn As Long) As Long ' *** Place the following code inside Form1. *** ' Stores a handle to the special window region, if it exists. Private hRgnWindow As Long Private Sub Form_Load() ' Open Form2 when this loads. Form2 is used to display a sort of ' "shadow" of the region used by Form1, although it really isn't a shadow effect. Form2.Show
http://216.26.168.92/vbapi/ref/g/getwindowrgn.html (2 of 4) [9/1/2002 5:30:58 PM]

Windows API Guide: GetWindowRgn Function

' Initially disable the "Remove Region" button, sice one hasn't ' yet been applied. cmdRemoveRegion.Enabled = False End Sub Private Sub cmdApplyRegion_Click() ' Create an elliptic region slightly smaller than the current size of ' Form1, and make that the window region. This makes the previously ' rectangular Form1 appear to be an ellipse. Dim retval As Long ' return value

' First, make the elliptical region, slightly smaller than Form1. hRgnWindow = CreateEllipticRgn(5, 5, (Form1.Width / Screen.TwipsPerPixelX) 5, _ (Form1.Height / Screen.TwipsPerPixelY) - 5) ' Apply this region to Form1 and show the change immediately. retval = SetWindowRgn(Form1.hWnd, hRgnWindow, True) ' To make sure that multiple regions aren't created, disable ' this button and enable the "Remove Region" button. cmdApplyRegion.Enabled = False cmdRemoveRegion.Enabled = True End Sub Private Sub cmdRemoveRegion_Click() ' Remove the window region from Form1, returning it to its ' normal rectangular shape. Dim retval As Long ' return value

' Set a null window region, which removes the current one entirely. retval = SetWindowRgn(Form1.hWnd, 0, True) ' Delete the region object because it is no longer needed. retval = DeleteObject(hRgnWindow) ' Since the region no longer exists, enable "Apply Region" and ' disable this button. cmdApplyRegion.Enabled = True cmdRemoveRegion.Enabled = False End Sub Private Sub cmdShowRegion_Click() ' Show the region currently applied to Form1 by inverting that region on ' Form2. Note that if no region is applied, nothing appears to happen because ' the actual window region is empty. Dim hRgnCopy As Long Dim retval As Long ' region that receives copy of Form1's region ' return value

' Create a region. It doesn't matter what, since it will be overwritten ' when GetWindowRgn is called. We just need to have some region.
http://216.26.168.92/vbapi/ref/g/getwindowrgn.html (3 of 4) [9/1/2002 5:30:58 PM]

Windows API Guide: GetWindowRgn Function

hRgnCopy = CreateEllipticRgn(0, 0, 0, 0) ' Copy Form1's region to hRgnCopy. The actual value of the handle ' does not change, but the information it "points" to does. retval = GetWindowRgn(Form1.hWnd, hRgnCopy) ' Invert the colors on Form2 that lie within this region. retval = InvertRgn(Form2.hDC, hRgnCopy) ' Delete the copied region, since we no longer need it. retval = DeleteObject(hRgnCopy) End Sub

See Also
SetWindowRgn

Category
Painting & Drawing Back to the Function list. Back to the Reference section.

Last Modified: September 24, 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowrgn.html

http://216.26.168.92/vbapi/ref/g/getwindowrgn.html (4 of 4) [9/1/2002 5:30:58 PM]

Windows API Guide: GetWindowText Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

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

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetWindowText retrieves the text of a window. For regular windows, this is the text which appears in the title bar. For controls, this is the text in the control. Note that GetWindowText cannot retrieve the text in a control owned by another program. To get that text, use the WM_GETTEXT message instead.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the number of characters copied into the string passed as lpString, not counting the terminating null character.

Visual Basic-Specific Issues
None.

Parameters
hWnd

http://216.26.168.92/vbapi/ref/g/getwindowtext.html (1 of 3) [9/1/2002 5:31:02 PM]

Windows API Guide: GetWindowText Function

A handle to the window to read the title of. lpString String variable that receives the window's text. This must already have enough room to receive the string. nMaxCount The length in characters of lpString.

Example
' This code is licensed according to the terms and conditions listed here. ' Display the text displayed in the title bar of window Form1 Dim textlen As Long ' receives length of text of the window Dim wintext As String ' receives the text of the window Dim slength As Long ' receives the length of the returned string ' Find out how many characters are in the window's text. ' Add 1 to compensate for the terminating null. textlen = GetWindowTextLength(Form1.hWnd) + 1 ' Make sufficient room in the buffer. wintext = Space(textlen) ' Retrieve the text of window Form1. slength = GetWindowText(Form1.hWnd, wintext, textlen) ' Remove the empty space from the string, if any. wintext = Left(wintext, slength) ' Display the result. Debug.Print "The title bar of window Form1 is: "; wintext

See Also
GetWindowTextLength, SetWindowText, WM_GETTEXT

Category
Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: February 11, 2000
http://216.26.168.92/vbapi/ref/g/getwindowtext.html (2 of 3) [9/1/2002 5:31:02 PM]

Windows API Guide: GetWindowText Function

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowtext.html

http://216.26.168.92/vbapi/ref/g/getwindowtext.html (3 of 3) [9/1/2002 5:31:02 PM]

Windows API Guide: GetWindowTextLength Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vb-shop.com |

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

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported. Windows CE: Requires Windows CE 1.0 or later.

Description & Usage
GetWindowTextLength returns the length in characters of a window's text. You can use this function in conjunction with GetWindowText to create a string just long enough to receive the text. However, this function does not include the terminating null character in the window's text in the character count. In some instances, this function might report a larger text length than actually exists; however, it will never report fewer than the actual number of characters. GetWindowTextLength does not work with controls owned by other programs. To get the window text length of these controls, use the WM_GETTEXTLENGTH message instead.

Return Value
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the number of characters in the window's text, not including the terminating null character.

Visual Basic-Specific Issues
None.
http://216.26.168.92/vbapi/ref/g/getwindowtextlength.html (1 of 3) [9/1/2002 5:31:09 PM]

Windows API Guide: GetWindowTextLength Function

Parameters
hWnd A handle to the window to retrieve the length of the window text of.

Example
' Display the text displayed in the title bar of window Form1 Dim textlen As Long ' receives length of text of the window Dim wintext As String ' receives the text of the window Dim slength As Long ' receives the length of the returned string ' Find out how many characters are in the window's text. ' Add 1 to compensate for the terminating null. textlen = GetWindowTextLength(Form1.hWnd) + 1 ' Make sufficient room in the buffer. wintext = Space(textlen) ' Retrieve the text of window Form1. slength = GetWindowText(Form1.hWnd, wintext, textlen) ' Remove the empty space from the string, if any. wintext = Left(wintext, slength) ' Display the result. Debug.Print "The title bar of window Form1 is: "; wintext

See Also
GetWindowText, WM_GETTEXTLENGTH

Category
Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

Last Modified: February 12, 2000.
http://216.26.168.92/vbapi/ref/g/getwindowtextlength.html (2 of 3) [9/1/2002 5:31:09 PM]

Windows API Guide: GetWindowTextLength Function

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowtextlength.html

http://216.26.168.92/vbapi/ref/g/getwindowtextlength.html (3 of 3) [9/1/2002 5:31:09 PM]

Windows API Guide: GetWindowThreadProcessId Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GetWindowThreadProcessId Function
Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GetWindowThreadProcessId finds identifiers for the thread which owns a given window and the process which created it. These identifiers can be used to later get information about the program controlling the window. Note that these two values are not handles but just numerical identifiers. The process identifier is put into the variable passed as lpdwProcessId, while the function returns the thread identifier. hwnd A handle to the window to find the identifers of the owning thread and creating process. lpdwProcessId Receives the identifer for the process which created the window. Example: ' ' ' ' Display the title bar text of all windows controlled by the thread which the window Form1 is in. This task is given to the callback function, which will receive each handle individually. Note that if the window has no title bar text, it will not be displayed (for clarity's sake).

' *** Place this code in a module. This is the callback function. *** ' This function displays the title bar text of the window identified by hwnd. Public Function EnumThreadWndProc (ByVal hwnd As Long, ByVal lParam As Long) As Long Dim slength As Long, wintext As String ' title bar text length and buffer Dim retval As Long ' return value Static winnum As Integer ' counter keeps track of how many windows have been enumerated winnum = winnum + 1 ' one more window enumerated.... slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text If slength > 1 ' if return value refers to non-empty string buffer = Space(slength) ' make room in the buffer retval = GetWindowText(hwnd, buffer, slength) ' get title bar text Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window End If EnumThreadWndProc = 1 End Function ' return value of 1 means continue enumeration

http://216.26.168.92/vbapi/ref/g/getwindowthreadprocessid.html (1 of 2) [9/1/2002 5:31:18 PM]

Windows API Guide: GetWindowThreadProcessId Function

' *** Place this code wherever you want to enumerate the windows. *** Dim threadid As Long, processid As Long ' receive id to thread and process of Form1 Dim retval As Long ' return value ' Determine the thread which owns the window Form1. threadid = GetWindowThreadProcessId(Form1.hWnd, processid) ' Use the callback function to list all of the enumerated thrad windows. Note that lParam ' is set to 0 because we don't need to pass any additional information to the function. retval = EnumThreadWindows(threadid, AddressOf EnumThreadWndProc, 0) Category: Windows Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/getwindowthreadprocessid.html

http://216.26.168.92/vbapi/ref/g/getwindowthreadprocessid.html (2 of 2) [9/1/2002 5:31:18 PM]

Windows API Guide: GlobalAlloc Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GlobalAlloc Function
Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GlobalAlloc allocates a series of bytes in the computer's global memory. The memory can be used for any purpose necessary. The function's return value, if successful, depends on the flags specified in wFlags. It will either be a pointer to the block of allocated memory or a handle to the block of allocated memory. Although they both identify the same thing, they will most likely not be equal and cannot be used interchangably! If the function fails, a value of 0 will be returned. Note that Windows will not allocate a memory block starting at base address 0. wFlags One or more of the following flags specifying how to allocate the block of memory: GHND = &H40 Same as combining GMEM_MOVEABLE with GMEM_ZEROINIT. GMEM_DDESHARE = &H2000 Optimize the allocated memory for use in DDE conversations. GMEM_DISCARDABLE = &H100 Allocate discardable memory. (Cannot be combined with GMEM_FIXED.) GMEM_FIXED = &H0 Allocate fixed memory. The function's return value is a pointer to the beginning of the memory block. (Cannot be combined with GMEM_DISCARDABLE or GMEM_MOVEABLE.) GMEM_MOVEABLE = &H2 Allocate moveable memory. The memory block's lock count is initialized at 0 (unlocked). The function's return value is a handle to the beginning of the memory block. (Cannot be combined with GMEM_FIXED.) GMEM_NOCOMPACT = &H10 Do not compact any memory or discard any discardable memory to allocate the requested block. GMEM_NODISCARD = &H20 Do not discard any discardable memory to allocate the requested block. GMEM_SHARE = &H2000 Same as GMEM_DDESHARE. GMEM_ZEROINIT = &H40 Initialize the contents of the memory block to 0. GPTR = &H42 Same as combining GMEM_FIXED with GMEM_ZEROINIT. dwBytes The number of bytes to allocate; i.e., the size of the memory block to allocate. Example:
http://216.26.168.92/vbapi/ref/g/globalalloc.html (1 of 2) [9/1/2002 5:31:24 PM]

Windows API Guide: GlobalAlloc Function

' Use a block of memory as an intermediary step to copy ' the contents of array s() to array t(). Yes, you could copy them directly, ' but this demonstrates a few different memory functions. Dim s(0 To 255) As Integer, t(0 To 255) As Integer ' arrays to copy from/to Dim c As Integer, retval As Long ' counter variable & return value Dim hMem As Long, pMem As Long ' handle and pointer to memory block ' Initialize the source array s()'s data For c = 0 To 255 s(c) = 2 * c ' each element equals double its index Next c ' Allocate a moveable block of memory (returns a handle) (Integer type = 2 bytes) hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, 256 * 2) ' Lock the memory block, returning a pointer to it pMem = GlobalLock(hMem) ' Copy the entire contents of s() to the memory block ' Note that pMem is ByVal because we want its contents, not a pointer to it CopyMemory ByVal pMem, s(0), 256 * 2 ' Copy the contents of the memory block to t() (we could have just copied s() to t()) CopyMemory t(0), ByVal pMem, 256 * 2 ' Unlock the memory block, destroying the pointer and freeing resources x = GlobalUnlock(hMem) ' Free the memory block (de-allocate it) x = GlobalFree(hMem) ' Verify that t() = s(), which it should For c = 0 To 255 If s(c) <> t(c) Then Debug.Print "Copy attempt failed." End If See Also: GlobalFree Category: Memory Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/globalalloc.html

http://216.26.168.92/vbapi/ref/g/globalalloc.html (2 of 2) [9/1/2002 5:31:24 PM]

http://216.26.168.92/vbapi/ref/g/globalfree.html

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GlobalFree Function
Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GlobalFree frees up the resources associated with a memory block, including of course the memory itself. This function should be used to deallocate any memory blocks allocated by GlobalAlloc after you are finished using it. The function returns 0 if successful, or the value passed as hMem if an error occured. hMem The handle to the block of memory to free. Example: ' Use a block of memory as an intermediary step to copy ' the contents of array s() to array t(). Yes, you could copy them directly, ' but this demonstrates a few different memory functions. Dim s(0 To 255) As Integer, t(0 To 255) As Integer ' arrays to copy from/to Dim c As Integer, retval As Long ' counter variable & return value Dim hMem As Long, pMem As Long ' handle and pointer to memory block ' Initialize the source array s()'s data For c = 0 To 255 s(c) = 2 * c ' each element equals double its index Next c ' Allocate a moveable block of memory (returns a handle) (Integer type = 2 bytes) hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, 256 * 2) ' Lock the memory block, returning a pointer to it pMem = GlobalLock(hMem) ' Copy the entire contents of s() to the memory block ' Note that pMem is ByVal because we want its contents, not a pointer to it CopyMemory ByVal pMem, s(0), 256 * 2 ' Copy the contents of the memory block to t() (we could have just copied s() to t()) CopyMemory t(0), ByVal pMem, 256 * 2 ' Unlock the memory block, destroying the pointer and freeing resources x = GlobalUnlock(hMem) ' Free the memory block (de-allocate it) x = GlobalFree(hMem)

http://216.26.168.92/vbapi/ref/g/globalfree.html (1 of 2) [9/1/2002 5:31:36 PM]

http://216.26.168.92/vbapi/ref/g/globalfree.html

' Verify that t() = s(), which it should For c = 0 To 255 If s(c) <> t(c) Then Debug.Print "Copy attempt failed." End If See Also: GlobalAlloc Category: Memory Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/globalfree.html

http://216.26.168.92/vbapi/ref/g/globalfree.html (2 of 2) [9/1/2002 5:31:36 PM]

Windows API Guide: GlobalLock Function

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GlobalLock Function
Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long Platforms: Win 32s, Win 95/98, Win NT GlobalLock locks a moveable block of memory into its current physical position. The block's internal lock count is incremented by one; a memory block is considered locked if its lock counter is greater than zero. Memory blocks cannot be moved or discarded while locked. The function returns a pointer to the beginning of the memory block if successful, or 0 if the function fails. hMem The handle to the moveable memory block to lock. Example: ' Use a block of memory as an intermediary step to copy ' the contents of array s() to array t(). Yes, you could copy them directly, ' but this demonstrates a few different memory functions. Dim s(0 To 255) As Integer, t(0 To 255) As Integer ' arrays to copy from/to Dim c As Integer, retval As Long ' counter variable & return value Dim hMem As Long, pMem As Long ' handle and pointer to memory block ' Initialize the source array s()'s data For c = 0 To 255 s(c) = 2 * c ' each element equals double its index Next c ' Allocate a moveable block of memory (returns a handle) (Integer type = 2 bytes) hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, 256 * 2) ' Lock the memory block, returning a pointer to it pMem = GlobalLock(hMem) ' Copy the entire contents of s() to the memory block ' Note that pMem is ByVal because we want its contents, not a pointer to it CopyMemory ByVal pMem, s(0), 256 * 2 ' Copy the contents of the memory block to t() (we could have just copied s() to t()) CopyMemory t(0), ByVal pMem, 256 * 2 ' Unlock the memory block, destroying the pointer and freeing resources x = GlobalUnlock(hMem) ' Free the memory block (de-allocate it) x = GlobalFree(hMem)
http://216.26.168.92/vbapi/ref/g/globallock.html (1 of 2) [9/1/2002 5:31:43 PM]

Windows API Guide: GlobalLock Function

' Verify that t() = s(), which it should For c = 0 To 255 If s(c) <> t(c) Then Debug.Print "Copy attempt failed." End If See Also: GlobalUnlock Category: Memory Go back to the alphabetical Function listing. Go back to the Reference section index.

This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/g/globallock.html

http://216.26.168.92/vbapi/ref/g/globallock.html (2 of 2) [9/1/2002 5:31:43 PM]

http://216.26.168.92/vbapi/ref/g/globalmemorystatus.html

vbapi.com - part of the VB-World Network | www.vbworld.com | www.vbforums.com | www.vbsquare.com | www.vbapi.com | www.vbshop.com |

GlobalMemoryStatus Function
Declare Sub GlobalMemoryStatus Lib "kernel32.dll" (lpBuffer As MEMORYSTATUS)

Platforms
q q q q q

Windows 95: Supported. Windows 98: Supported. Windows NT: Requires Windows NT 3.1 or later. Windows 2000: Supported but Obsolete; use GlobalMemoryStatusEx instead. Windows CE: Unknown.

Description & Usage
GlobalMemoryStatus retrieves the current status of the computer's memory. It reports both the total memory available and the amount of unused memory. This function only works properly on computers with no more than 4 GB of memory. If the computer has more than 4 GB of memory, the values reported by GlobalMemoryStatus are the actual values modulo 4 (for example, a computer with 5 GB total memory would be reported as having only 1 GB of memory). For computers with more than 4 GB of memory, use the GlobalMemoryStatusEx function instead.

Return Value
GlobalMemoryStatusEx does not return a value.

Visual Basic-Specific Issues
None.

Parameters
lpBuffer Receives the current status of the computer's memory. The dwLength member of the structure does not have to be set before calling the function.

Example
' This code is licensed according to the terms and conditions listed here. ' Display the amounts of total and available physical memory
http://216.26.168.92/vbapi/ref/g/globalmemorystatus.html (1 of 2) [9/1/2002 5:31:50 PM]

com Send Encrypted E-Mail This page is at http://www. "KB" Debug.html ' on the computer.com/ref/g/globalmemorystatus.dwAvailPhys \ 1024. Copyright Information Revised October 29. Debug. GlobalMemoryStatus ms ' Display total and available physical memory.dwAvailPhys \ ms. Back to the Reference section.html (2 of 2) [9/1/2002 5:31:50 PM] .26. E-mail: vbapi@vbapi. 100 .92/vbapi/ref/g/globalmemorystatus. 2000 Go back to the Windows API Guide home page. in KB.dwTotalPhys. "%" See Also GlobalMemoryStatusEx Category Memory Back to the Function list.100 * ms.Print "Available Physical Memory:".html http://216.92/vbapi/ref/g/globalmemorystatus. Last Modified: March 19.http://216.vbapi. ms. Debug.dwTotalPhys \ 1024. ms.26. Dim ms As MEMORYSTATUS ' Get the current memory status.168. 2000 This page is copyright © 2000 Paul Kuliniewicz.Print "Total Physical Memory:". "KB" ' Calculate percentage of physical memory in use.168. Also calculate the percentage of used physical memory.Print "Used Physical Memory:".

Windows NT: Not Supported. Windows CE: Not Supported. Visual Basic-Specific Issues None.com | www.92/vbapi/ref/g/globalmemorystatusex. Parameters lpBuffer Receives the current status of the computer's memory.vbapi.vbsquare. the function returns a non-zero value. Description & Usage GlobalMemoryStatusEx retrieves the current status of the computer's memory.com | www. Windows 2000: Supported.vbforums.html (1 of 3) [9/1/2002 5:31:57 PM] . If successful.com .26.com | www. Example http://216.part of the VB-World Network | www.168. the function returns 0 (call GetLastError to get the error code).com | www.vbworld.vb-shop.Windows API Guide: GlobalMemoryStatusEx Function vbapi.com | GlobalMemoryStatusEx Function Declare Function GlobalMemoryStatusEx Lib "kernel32.dll" (lpBuffer As MEMORYSTATUSEX) As Long Platforms q q q q q Windows 95: Not Supported. Return Value If an error occured. It reports both the total memory available and the amount of unused memory. Windows 98: Not Supported.

Back to the Reference section. bytes to kilobytes ' Get the current memory status. Copyright Information Revised October 29. Last Modified: March 19. in KB.Print temp * mult. Dim ms As MEMORYSTATUSEX Dim temp As Currency ' pseudo-64-bit integer buffer Dim retval As Long ' return value Dim mult As Long ' conversion multiplier ' Calculate the multiplier necessary to convert bytes in a Currency variable ' to kilobytes properly displayed: mult = 10000 / 1024 ' move decimal point. 2000 Go back to the Windows API Guide home page.ullTotalPhys. "KB" ' Display available physical memory.92/vbapi/ref/g/globalmemorystatusex. Use the Currency data type to allow VB to display ' the 64-bit values reported by GlobalMemoryStatusEx. CopyMemory temp.168. E-mail: vbapi@vbapi. ms. ms.Print "Total Physical Memory:".ullAvailPhys.Windows API Guide: GlobalMemoryStatusEx Function ' This code is licensed according to the terms and conditions listed here.Print "Available Physical Memory:". retval = GlobalMemoryStatusEx(ms) ' Display total physical memory. ' Display the amounts of total and available physical memory ' on the computer.26. CopyMemory temp. Debug.Print temp * mult. in KB. "KB" See Also GlobalMemoryStatus Category Memory Back to the Function list. Debug. Len(temp) Debug.html (2 of 3) [9/1/2002 5:31:57 PM] .com Send Encrypted E-Mail http://216. Len(temp) Debug. 2000 This page is copyright © 2000 Paul Kuliniewicz.

com/ref/g/globalmemorystatusex.Windows API Guide: GlobalMemoryStatusEx Function This page is at http://www.168.92/vbapi/ref/g/globalmemorystatusex.html http://216.html (3 of 3) [9/1/2002 5:31:57 PM] .vbapi.26.

The function returns 1 if. Yes. after decrementing the lock count. hMem A handle to the moveable memory block to decrement the lock count of. pMem As Long ' handle and pointer to memory block ' Initialize the source array s()'s data For c = 0 To 255 s(c) = 2 * c ' each element equals double its index Next c ' Allocate a moveable block of memory (returns a handle) (Integer type = 2 bytes) hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT.vbforums.Windows API Guide: GlobalUnlock Function vbapi.26.vbapi.168.com | www. retval As Long ' counter variable & return value Dim hMem As Long. destroying the pointer and freeing resources x = GlobalUnlock(hMem) ' Free the memory block (de-allocate it) http://216. Win 95/98.92/vbapi/ref/g/globalunlock. s(0). it is considered unlocked if its lock count is zero.dll" (ByVal hMem As Long) As Long Platforms: Win 32s. not a pointer to it CopyMemory ByVal pMem.com | www.com | www. you could copy them directly. after decrementing the lock count.com | www. the memory block is still locked. Win NT GlobalUnlock decrements the lock count of a moveable memory block by one. The function returns 0 if. returning a pointer to it pMem = GlobalLock(hMem) ' Copy the entire contents of s() to the memory block ' Note that pMem is ByVal because we want its contents.com . t(0 To 255) As Integer ' arrays to copy from/to Dim c As Integer. Dim s(0 To 255) As Integer. The memory block is locked if its lock count is greater than zero. either the memory block is now unlocked or an error occured.vbworld. ' but this demonstrates a few different memory functions.html (1 of 2) [9/1/2002 5:32:03 PM] . A moveable memory block cannot be moved or discarded while it is locked. 256 * 2 ' Unlock the memory block.vbsquare.part of the VB-World Network | www. Example: ' Use a block of memory as an intermediary step to copy ' the contents of array s() to array t(). 256 * 2) ' Lock the memory block. 256 * 2 ' Copy the contents of the memory block to t() (we could have just copied s() to t()) CopyMemory t(0).com | GlobalUnlock Function Declare Function GlobalUnlock Lib "kernel32.vbshop. ByVal pMem.

92/vbapi/ref/g/globalunlock.26.com Send Encrypted E-Mail This page is at http://www." End If See Also: GlobalLock Category: Memory Go back to the alphabetical Function listing.Windows API Guide: GlobalUnlock Function x = GlobalFree(hMem) ' Verify that t() = s().vbapi. Go back to the Windows API Guide home page. which it should For c = 0 To 255 If s(c) <> t(c) Then Debug. Copyright Information. Go back to the Reference section index.168.Print "Copy attempt failed. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:32:03 PM] .com/ref/g/globalunlock. This page is copyright © 2000 Paul Kuliniewicz.html http://216.

htonl ensures that the proper byte order is being used in Winsock calls.Windows API Guide: htonl Function vbapi.com | www.vbforums. http://216.1 or later.92/vbapi/ref/h/htonl. Windows CE: Requires Windows CE 1.com | htonl Function Declare Function htonl Lib "wsock32.0 or later. Since Winsock uses network byte order for various values. Visual Basic-Specific Issues None.com . place a command button named cmdGetDomain on a form window. When the user clicks button cmdGetDomain.26.vbapi. regardless of whether the computer normally uses little-endian or big-endian ordering.vbworld.vbsquare. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand.com | www. Windows 2000: Supported. Windows 98: Supported. the program looks up the first domain name assigned to that address. Windows NT: Requires Windows NT 3. Description & Usage htonl converts a 32-bit value from host byte order to network byte order.html (1 of 5) [9/1/2002 5:32:13 PM] .dll" (ByVal hostlong As Long) As Long Platforms q q q q q Windows 95: Supported. To use this example.part of the VB-World Network | www.com | www.com | www. Example Create an IP Address control and use it to prompt the user for an IP address. Return Value The function returns the value converted to network byte order. Parameters hostlong A 32-bit value in host order to convert to network byte order.168.vbshop.

ByVal hWndParent As Long.26. ByVal length As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. ByVal dwStyle As Long. ByVal x _ As Long.dll" (addr As Long. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. ByVal nWidth As Long.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32.html (2 of 5) [9/1/2002 5:32:13 PM] .) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32. lpParam As Any) As Long http://216. ByVal lpWindowName As String. ByVal y As Long. Source _ As Any. ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (ByVal wVersionRequested As Integer. _ ByVal lpClassName As String.168.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32. ByVal nHeight As Long.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.92/vbapi/ref/h/htonl. ByVal hInstance As Long. _ ByVal hMenu As Long.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.Windows API Guide: htonl Function ' This code is licensed according to the terms and conditions listed here.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long.dll" Alias "RtlMoveMemory" (Destination As Any.

125. ByVal Msg _ As Long.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32.168. in network byte order ' information about the Winsock implementation Dim sockinfo As WSADATA Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT Dim domainName As String ' the primary domain name of the host computer Dim retval As Long ' generic return value http://216.hWnd. in host byte order Dim ipAddress_n As Long ' the IP address. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long ' the IP address. "". 0. ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes.dll" Alias "SendMessageA" (ByVal hWnd As Long. 0. App.26. 20.dwSize = Len(comctls) . Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control.92/vbapi/ref/h/htonl.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window. With comctls .Windows API Guide: htonl Function Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32. WC_IPADDRESS. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim retval As Long ' generic return value ' Register the IP Address control window class. wParam As Any.hInstance.html (3 of 5) [9/1/2002 5:32:13 PM] . _ Me. *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized. hIPControl = CreateWindowEx(0. WS_CHILD Or WS_VISIBLE. 0. create an IP Address control in the ' upper-left corner of the form.

ByVal pHostinfo.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2. domainName End If ' End the Winsock session. ipAddress_h) If retval < 4 Then Debug. CopyMemory hostinfo. ByVal CLng(0)) If retval <> 0 Then Debug.html (4 of 5) [9/1/2002 5:32:13 PM] . hostinfo. retval Exit Sub End If ' Convert the IP address into network byte order.Windows API Guide: htonl Function ' Verify that an IP address was entered.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered. retval = WSACleanup() End Sub See Also ntohl Category Winsock http://216. ByVal CLng(0). retval = SendMessage(hIPControl.92/vbapi/ref/h/htonl.2 session. AF_INET) If pHostInfo = 0 Then Debug. ByVal CLng(0). retval = SendMessage(hIPControl. retval = WSAStartup(&H202. sockinfo) If retval <> 0 Then Debug.Print "Could not find a host with the specified IP address.Print "ERROR: Attempt to open Winsock failed: error".168.h_name) Debug. Len(hostinfo) ' Copy the host domain name into a string. pHostinfo = gethostbyaddr(ipAddress_n. domainName = Space(lstrlen(hostinfo.h_name)) retval = lstrcpy(domainName. 4.Print "Domain name is: "." Else ' Copy the data into the structure. IPM_ISBLANK. IPM_GETADDRESS. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer.26.

html (5 of 5) [9/1/2002 5:32:13 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29.Windows API Guide: htonl Function Back to the Function list.com Send Encrypted E-Mail This page is at http://www.26.html http://216. 2000 Go back to the Windows API Guide home page. Last Modified: December 17. Back to the Reference section.168.92/vbapi/ref/h/htonl.vbapi. E-mail: vbapi@vbapi.com/ref/h/htonl.

To prevent the program from appearing to lock up in the event of a momentary interruption in the transfer. Windows NT: Requires Windows NT 3. Description & Usage htons converts a 16-bit value from host byte order to network byte order.com | htons Function Declare Function htons Lib "wsock32.com | www.26. Example Download the main page of this web site (http://www. Visual Basic-Specific Issues None.vbshop.92/vbapi/ref/h/htons. Parameters hostshort A 16-bit network address in host order to convert to network byte order. place a command button named cmdDownload on a form window. Return Value The function returns the value converted to network byte order.1 or later. The document downloaded.vbforums.com | www.0 or later. To use this example.com | www. regardless of whether the computer normally uses little-endian or big-endian ordering. sending a request to the server and receiving the document. Windows CE: Requires Windows CE 1.vbworld.168. htons ensures that the proper byte order is being used in Winsock calls. Windows 98: Supported. with HTTP headers removed. a nonblocking socket is used.vbapi.html (1 of 5) [9/1/2002 5:32:20 PM] .com | www.vbapi.com . Windows 2000: Supported.dll" (ByVal hostshort As Integer) As Integer Platforms q q q q q Windows 95: Supported.Windows API Guide: htons Function vbapi.part of the VB-World Network | www. is output to the Debug window.com).vbsquare. This example supports a very crude implementation of HyperText Transport Protocol (HTTP). http://216. Since Winsock uses network byte order for various values.

buf As Any. ByVal prototype As Long.dll" (ByVal s As Long. I would use that instead of GoTo.dll" (ByVal s As Long.dll" (ByVal wVersionRequested As Integer. argp As Long) As Long Public Const FIONBIO = &H8004667E Public Declare Function send Lib "wsock32.dll" (ByVal af As Long. the GoTo statements skip down to the end if an unrecoverable error occurs.dll" (ByVal s As Long.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.html (2 of 5) [9/1/2002 5:32:20 PM] .168.26. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. ByVal namelen _ As Long) As Long Declare Function ioctlsocket Lib "wsock32. _ http://216.92/vbapi/ref/h/htons.Windows API Guide: htons Function Note the careful use of GoTo in this example. ByVal cmd As Long. Since there are lots of things that can go wrong. ' This code is licensed according to the terms and conditions listed here. _ ByVal protocol As Long) As Long Public Type sockaddr sin_family As Integer sin_port As Integer sin_addr As Long sin_zero As String * 8 End Type Public Declare Function connect Lib "wsock32.dll" (ByVal hostshort As Integer) As Integer Public Declare Function socket Lib "wsock32. ByVal length As Long.dll" (ByVal name As String) As Long Public Type hostent h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Declare Function htons Lib "wsock32. and WSACleanup must be called at the end no matter what happens. name As sockaddr. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32. If VB had better exception handling.dll" () As Long Public Const AF_INET = 2 Public Const SOCK_STREAM = 1 Public Declare Function gethostbyname Lib "wsock32.

Public Function MAKEWORD(ByVal bLow As Byte. 4 http://216.com!" GoTo Cleanup End If ' Get the server's IP address out of the structure.Windows API Guide: htons Function ByVal flags As Long) As Long Public Declare Function recv Lib "wsock32. *** Private Sub Dim Dim Dim Dim Dim Dim Dim Dim Dim Dim cmdDownload_Click() wsockinfo As WSADATA sock As Long pHostinfo As Long hostinfo As hostent pIPAddress As Long ipAddress As Long sockinfo As sockaddr buffer As String reply As String retval As Long ' ' ' ' ' ' ' ' ' ' info about Winsock the socket descriptor pointer to info about the host computer info about the host computer pointer to host's IP address host's IP address settings for the socket buffer for sending and receiving data accumulates server's reply generic return value ' Begin a Winsock session.h_addr_list. buf As Any. CopyMemory hostinfo.vbapi.h_addrtype <> AF_INET Then Debug. Len(hostinfo) If hostinfo.vbapi. pHostinfo = gethostbyname("www. Source _ As Any. _ ByVal flags As Long) As Long Public Declare Function closesocket Lib "wsock32.html (3 of 5) [9/1/2002 5:32:20 PM] . 2)) End Function ' *** Place the following code inside the form window.168. CopyMemory pIPAddress.com") If pHostinfo = 0 Then Debug. wsockinfo) If retval <> 0 Then Debug. retval = WSAStartup(MAKEWORD(2. retval Exit Sub End If ' Get information about the server to connect to. 2). ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh). ByVal hostinfo.92/vbapi/ref/h/htons.Print "Couldn't get IP address of www. ByVal length As Long.dll" (ByVal s As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.26. 2) & Right("00" & Hex(bLow).dll" Alias "RtlMoveMemory" (Destination As Any.dll" (ByVal s As Long. ByVal pHostinfo.Print "Unable to initialize Winsock! --". ByVal Length As Long) Public Const SOCKET_ERROR = -1 ' Define a useful macro.Print "Unable to resolve host!" GoTo Cleanup End If ' Copy information about the server into the structure.

SOCK_STREAM..sin_zero = String(8.e. so calls to recv don't halt the program waiting for input. FIONBIO. if the connection is ' lost). 0) If sock = SOCKET_ERROR Then Debug. 0) Debug..Print "Attempting to connect. Len(buffer). sockinfo.com:80 (where the web server listens). vbNullChar) End With Debug. Do buffer = Space(4096) retval = recv(sock. .com" & vbCrLf & _ "User-Agent: HTTP-Test-Program" & vbCrLf & vbCrLf retval = send(sock.sin_family = AF_INET ' Connect to port 80. sock = socket(AF_INET. 1) ' Read the response from the other system." ' Make the socket non-blocking.Windows API Guide: htons Function CopyMemory ipAddress. ByVal buffer.Print "Unable to connect!" GoTo Cleanup End If ' Send an HTTP/GET request for the / document. ByVal pIPAddress..html (4 of 5) [9/1/2002 5:32:20 PM] .sin_addr = ipAddress ' Padding characters. 4 ' Create a socket.168. buffer = "GET / HTTP/1.Print "Unable to create socket!" GoTo Cleanup End If ' Make a connection to www. For brevity. Len(buffer). With sockinfo ' Use Internet Protocol (IP) . such code is omitted here... ByVal buffer.26. retval = ioctlsocket(sock. 0) If retval <> 0 And retval <> SOCKET_ERROR Then reply = reply & Left(buffer.. retval) End If ' Process background events so the program doesn't appear to freeze. Len(sockinfo)) If retval <> 0 Then Debug." retval = connect(sock.Print "Sent request.sin_port = htons(80) ' Connect to this IP address.vbapi.1" & vbCrLf & _ "Host: www.92/vbapi/ref/h/htons. . DoEvents Loop Until retval = 0 http://216. A more sophisticated program ' would watch to see if the connection ever times out (i. .vbapi. Waiting for reply.

Last Modified: January 21. 2001 This page is copyright © 2001 Paul Kuliniewicz.26. Cleanup: retval = closesocket(sock) retval = WSACleanup() End Sub See Also htonl Category Winsock Back to the Function list.com Send Encrypted E-Mail This page is at http://www.Print "Document Retrieved:" Debug.vbapi. Copyright Information Revised October 29.Print reply ' Perform the necessary cleanup at the end.92/vbapi/ref/h/htons. E-mail: vbapi@vbapi. 2000 Go back to the Windows API Guide home page.html (5 of 5) [9/1/2002 5:32:20 PM] . Debug.html http://216. Back to the Reference section.Windows API Guide: htons Function ' Print the response from the server.com/ref/h/htons.168.

com | www.b. Example Prompt the user for an IP address by using a regular text box.html (1 of 3) [9/1/2002 5:32:24 PM] .com . If an error occured.com | inet_addr Function Declare Function inet_addr Lib "wsock32. Return Value If successful.dll" (ByVal cp As String) As Long Platforms q q q q q Windows 95: Supported. Windows NT: Requires Windows NT 3. Also place a text box named txtIPAddress on the form window. http://216.vbforums.Windows API Guide: inet_addr Function vbapi.168. "a.c.d"). the function returns the IP address. the function returns &HFFFFFFFF.com | www.vbapi. Visual Basic-Specific Issues None. Windows 2000: Supported.1 or later.vbworld. if any.com | www. Take the IP address and determine the domain name.vbshop. Description & Usage inet_addr converts a string identifying an IP address into an actual IP address in network byte order.26. Windows 98: Supported. To use this example. The string must be in "dotted quad" format (for example.92/vbapi/ref/i/inet_addr.0 or later. Parameters cp The IP address string to convert. Windows CE: Requires Windows CE 1. associated with that address.com | www. This must be in "dotted quad" format. packed into a single 32-bit integer. place a command button named cmdGetDomain on a form window. in network byte order.part of the VB-World Network | www.vbsquare.

dll" (ByVal wVersionRequested As Integer.26.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function inet_addr Lib "wsock32.Windows API Guide: inet_addr Function ' This code is licensed according to the terms and conditions listed here.dll" (addr As Long.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.html (2 of 3) [9/1/2002 5:32:24 PM] . *** ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control. Source _ As Any.dll" Alias "RtlMoveMemory" (Destination As Any. ByVal length As Long. ByVal _ lpString2 As Any) As Long ' *** Place the following code in a form window.92/vbapi/ref/i/inet_addr.168. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" (ByVal cp As String) As Long Public Declare Function gethostbyaddr Lib "wsock32. in network byte order ' information about the Winsock implementation Dim sockinfo As WSADATA Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT Dim domainName As String ' the primary domain name of the host computer Dim retval As Long ' generic return value ' Get the IP address entered by the user. http://216.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32. Private Sub cmdGetDomain_Click() Dim ipAddress_n As Long ' the IP address. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.

sockinfo) If retval <> 0 Then Debug.Print "An incorrect IP address was entered!" Exit Sub End If ' Open up a Winsock v2. retval Exit Sub End If ' Get information about the host computer.com/ref/i/inet_addr.168.Text) If ipAddress_n = &HFFFFFFFF Then Debug. CopyMemory hostinfo.vbapi. retval = WSACleanup() End Sub See Also inet_ntoa Category Winsock Back to the Function list. 2000 This page is copyright © 2000 Paul Kuliniewicz. domainName = Space(lstrlen(hostinfo." Else ' Copy the data into the structure. Last Modified: October 29.Print "ERROR: Attempt to open Winsock failed: error". AF_INET) If pHostInfo = 0 Then Debug.h_name) Debug.com Send Encrypted E-Mail This page is at http://www.Windows API Guide: inet_addr Function ipAddress_n = inet_addr(txtIPAddress. Len(hostinfo) ' Copy the host domain name into a string. E-mail: vbapi@vbapi.26.Print "Could not find a host with the specified IP address. domainName End If ' End the Winsock session. hostinfo.Print "Domain name is: ". Back to the Reference section.2 session. 2000 Go back to the Windows API Guide home page. 4. pHostinfo = gethostbyaddr(ipAddress_n.html (3 of 3) [9/1/2002 5:32:24 PM] .92/vbapi/ref/i/inet_addr.html http://216. Copyright Information Revised October 29. ByVal pHostinfo.h_name)) retval = lstrcpy(domainName. retval = WSAStartup(&H202.

This string is in the standard "a. Return Value If successful. The user enters the domain name to resolve in text box txtDomain. Windows NT: Requires Windows NT 3. Windows CE: Requires Windows CE 1.com | www. the function returns a pointer to the string that contains the human-readable IP address.26. Windows 2000: Supported.part of the VB-World Network | www.168. Winsock is briefly used to resolve the domain name and format a printable IP address string.dll" (ByVal inaddr As Long) As Long Platforms q q q q q Windows 95: Supported.com | www. However.d" format.com | www. Visual Basic-Specific Issues To copy the returned string into a String variable.92/vbapi/ref/i/inet_ntoa. Description & Usage inet_ntoa converts an IP address packed in a 32-bit integer into a human-readable string. If an error occured.com | www. Windows 98: Supported. This function returns a pointer to the resulting string.com . the function returns zero. See the example below for a demonstration.html (1 of 4) [9/1/2002 5:32:30 PM] .vbforums.b.vbshop.1 or later. use the lstrlen and lstrcpy API functions.0 or later.Windows API Guide: inet_ntoa Function vbapi.vbworld.c. and the domain http://216. the pointer is only guaranteed to be valid until the next call to a Winsock function.com | inet_ntoa Function Declare Function inet_ntoa Lib "wsock32. Example Print the IP address associated with a domain name specified by the user. Parameters inaddr The IP address to convert to a human-readable string. The IP address is packed into a single 32-bit integer and must be in network byte order. so your program should make a copy of it immediately.vbsquare.vbapi.

lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.Windows API Guide: inet_ntoa Function name is resolved when the user clicks button cmdGetIP. *** Private Sub cmdGetIP_Click() http://216.26. ' This code is licensed according to the terms and conditions listed here.dll" (ByVal wVersionRequested As Integer.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function gethostbyname Lib "wsock32. 2)) End Function ' *** Place the following code inside the form window. Public Function MAKEWORD(ByVal bLow As Byte. To run this example. Source _ As Any. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh). place a text box named txtDomain and a command button named cmdGetIP on a form window.168.dll" (ByVal name As String) As Long Public Declare Function inet_ntoa Lib "wsock32. 2) & Right("00" & Hex(bLow).dll" (ByVal inaddr As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any. ByVal _ lpString2 As Any) As Long ' Define a relevant API macro.92/vbapi/ref/i/inet_ntoa.html (2 of 4) [9/1/2002 5:32:30 PM] . ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.

168. ipString = Space(lstrlen(pIPString)) retval = lstrcpy(ipString. 2).Print "A non-IP address was returned.Print "ERROR: Attempt to open Winsock failed: error". retval Exit Sub End If ' Get information about the domain specified in txtDomain. Len(hostinfo) If hostinfo. ByVal pIPAddress. CopyMemory hostinfo. pIPString) ' Print the result: a human-readable IP address. Debug.Print "Unable to resolve domain name. CopyMemory pIPAddress.h_addr_list.Text) If pHostinfo = 0 Then Debug." Else ' Copy the pointer to the first (and probably only) IP address in the structure." Else ' Copy the data into a HOSTENT structure.html (3 of 4) [9/1/2002 5:32:30 PM] .Windows API Guide: inet_ntoa Function Dim Dim Dim Dim Dim Dim Dim Dim sockinfo As WSADATA hostinfo As HOSTENT pHostinfo As Long pIPAddress As Long ipAddress As Long pIPString As Long ipString As String retval As Long ' ' ' ' ' ' ' ' information about Winsock information about an Internet host pointer to a HOSTENT structure pointer to an IP address dword an IP address. retval = WSAStartup(MAKEWORD(2.h_addrtype <> AF_INET Then Debug. pIPString = inet_ntoa(ipAddress) ' Copy the result into a string variable. ByVal pHostinfo. CopyMemory ipAddress. pHostinfo = gethostbyname(txtDomain. packed into a dword pointer to an IP address formatted as a string holds a human-readable IP address string generic return value ' Open up a Winsock session.26. ByVal hostinfo. 4 ' Copy the actual IP address.2.Print ipString End If End If ' Close the Winsock session. sockinfo) If retval <> 0 Then Debug.92/vbapi/ref/i/inet_ntoa. using version 2. 4 ' Convert the IP address into a human-readable string. retval = WSACleanup() End Sub See Also inet_addr http://216.

Windows API Guide: inet_ntoa Function Category Winsock Back to the Function list. Last Modified: October 29. 2000 Go back to the Windows API Guide home page. 2000 This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www. Back to the Reference section.html http://216. E-mail: vbapi@vbapi.92/vbapi/ref/i/inet_ntoa.26.html (4 of 4) [9/1/2002 5:32:30 PM] .com/ref/i/inet_ntoa.168. Copyright Information Revised October 29.vbapi.

while negative values decrease it. 0.com | www.92/vbapi/ref/i/inflaterect. negative values decrease it. x The value to expand the left and right sides by.com | InflateRect Function Declare Function InflateRect Lib "user32. lpRect The rectangle to change the size of.Windows API Guide: InflateRect Function vbapi. Win NT InflateRect increases or decreases the size of a rectangle. negative values decrease it. the left and right sides will both be extended by 20. Copyright Information. For example.part of the VB-World Network | www. 50. winrect. Positive values increase the height.hWnd.dll" (lpRect As RECT. Win 95/98.26. winrect.vbforums. ByVal x As Long.Top.Left. if you pass 20 as x. This page is copyright © 2000 Paul Kuliniewicz.Bottom. http://216. Go back to the Reference section index. Example: ' Expand the width of window Form1 by 100 and shrink its ' height by 50 using its rectangle. The values to inflate the rectangle by are added to both sides of it.com | www. Positive values increase the width. 0) See Also: OffsetRect Category: Rectangles Go back to the alphabetical Function listing.vbapi.hWnd.168. winrect. The function returns 0 if an error occured. winrect) ' get Form1's rectangle retval = InflateRect(winrect.com | www.html (1 of 2) [9/1/2002 5:32:38 PM] . or 1 if successful.Right. so in reality the width and/or height of the rectangle increases by double what you pass to the function. so the total width will be 40 more. y The value to expand the top and bottom by. -25) ' these values added to each side to inflate it ' Now change the window on screen to match its new rectangle retval = SetWindowPos(Form1. Dim winrect As RECT ' receives the rectangle of the window Dim retval As Long ' return value retval = GetWindowRect(Form1. winrect.com .vbworld.com | www. Positive values increase the size.vbsquare.vbshop. ByVal y As Long) As Long Platforms: Win 32s.

vbapi.26.168.html http://216.com/ref/i/inflaterect.Windows API Guide: InflateRect Function Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:32:38 PM] .92/vbapi/ref/i/inflaterect.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.

vbworld.168.Windows API Guide: InitCommonControlsEx Function vbapi. Example Create an IP Address control and use it to prompt the user for an IP address.0 or later. Parameters lpInitCtrls Specifies which common control classes to register. the function returns zero.com .dll" (lpInitCtrls As INITCOMMONCONTROLSEX_TYPE) As Long Platforms q q q q q Windows 95: Supported. http://216.html (1 of 5) [9/1/2002 5:32:44 PM] .com | www.com | www.92/vbapi/ref/i/initcommoncontrolsex. Windows 98: Supported. To use this example.vbsquare.26.1 or later.com | InitCommonControlsEx Function Declare Function InitCommonControlsEx Lib "comctl32. the function returns a non-zero value. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand. place a command button named cmdGetDomain on a form window.vbforums.com | www. This function must be called before using CreateWindowEx to create a common control. If an error occured.vbapi. Windows NT: Requires Windows NT 3.part of the VB-World Network | www. Description & Usage InitCommonControlsEx registers the window classes used to create various common controls. Windows CE: Requires Windows CE 1. Windows 2000: Supported. the program looks up the first domain name assigned to that address.vbshop. Return Value If successful.com | www. Visual Basic-Specific Issues None. When the user clicks button cmdGetDomain.

ByVal lpWindowName As String. ByVal dwStyle As Long.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32. Source _ As Any.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32. _ ByVal hMenu As Long. ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32. _ ByVal lpClassName As String. ByVal nWidth As Long.92/vbapi/ref/i/initcommoncontrolsex. ByVal hWndParent As Long.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32. ByVal nHeight As Long. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" (addr As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.26.Windows API Guide: InitCommonControlsEx Function ' This code is licensed according to the terms and conditions listed here. ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.dll" (ByVal wVersionRequested As Integer.168.html (2 of 5) [9/1/2002 5:32:44 PM] . ByVal length As Long. ByVal hInstance As Long.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32.dll" Alias "RtlMoveMemory" (Destination As Any. ByVal x _ As Long. ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long. ByVal y As Long. lpParam As Any) As Long http://216.

dll" Alias "SendMessageA" (ByVal hWnd As Long. 20. 0. With comctls . lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window.Windows API Guide: InitCommonControlsEx Function Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32. ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes.hWnd. create an IP Address control in the ' upper-left corner of the form. 0. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long ' the IP address. *** Private hIPControl As Long ' handle to the IP Address control ' When the form is initialized.dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. 125. App. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32. in network byte order ' information about the Winsock implementation Dim sockinfo As WSADATA Dim pHostinfo As Long ' pointer to information about the host computer ' information about the host computer Dim hostinfo As HOSTENT Dim domainName As String ' the primary domain name of the host computer Dim retval As Long ' generic return value http://216. in host byte order Dim ipAddress_n As Long ' the IP address. hIPControl = CreateWindowEx(0.26.dwSize = Len(comctls) .92/vbapi/ref/i/initcommoncontrolsex. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register Dim retval As Long ' generic return value ' Register the IP Address control window class. 0.html (3 of 5) [9/1/2002 5:32:44 PM] .168. wParam As Any. ByVal Msg _ As Long. WC_IPADDRESS. _ Me. "". WS_CHILD Or WS_VISIBLE.hInstance.

AF_INET) If pHostInfo = 0 Then Debug. retval = SendMessage(hIPControl. pHostinfo = gethostbyaddr(ipAddress_n.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered.26. retval Exit Sub End If ' Convert the IP address into network byte order.Windows API Guide: InitCommonControlsEx Function ' Verify that an IP address was entered. 4.Print "Domain name is: ".html (4 of 5) [9/1/2002 5:32:44 PM] . ByVal CLng(0). hostinfo. ipAddress_h) If retval < 4 Then Debug.168.92/vbapi/ref/i/initcommoncontrolsex. retval = WSACleanup() End Sub Category Common Controls Back to the Function list. http://216. retval = SendMessage(hIPControl.Print "ERROR: Attempt to open Winsock failed: error". retval = WSAStartup(&H202. CopyMemory hostinfo. domainName End If ' End the Winsock session. ByVal CLng(0)) If retval <> 0 Then Debug. domainName = Space(lstrlen(hostinfo.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2. Len(hostinfo) ' Copy the host domain name into a string.h_name)) retval = lstrcpy(domainName. ByVal pHostinfo." Else ' Copy the data into the structure. IPM_GETADDRESS. IPM_ISBLANK.Print "Could not find a host with the specified IP address. Back to the Reference section. ByVal CLng(0). sockinfo) If retval <> 0 Then Debug.2 session.h_name) Debug. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer.

168.com Send Encrypted E-Mail This page is at http://www.html http://216.92/vbapi/ref/i/initcommoncontrolsex. E-mail: vbapi@vbapi. 2000 This page is copyright © 2000 Paul Kuliniewicz.com/ref/i/initcommoncontrolsex. 2000 Go back to the Windows API Guide home page.html (5 of 5) [9/1/2002 5:32:44 PM] .vbapi.Windows API Guide: InitCommonControlsEx Function Last Modified: October 29.26. Copyright Information Revised October 29.

etc. be sure that the new item's unique menu item identifier is less than &HF000. Parameters hMenu A handle to the menu to add a new item to. See the example below for a demonstration of how to accomplish this. Minimize.168. Windows 2000: Supported. Windows CE: Not Supported.vbworld. then the window it belongs to will receive a WM_COMMAND message whenever the menu item is selected.vbapi.com | www.com | www.dll" Alias "InsertMenuItemA" (ByVal hMenu As Long. lpmii As MENUITEMINFO) As Long Platforms q q q q q Windows 95: Supported. it is necessary to create a WindowProc window procedure to manually process the WM_COMMAND or WM_SYSCOMMAND messages that the menu item may send.26. The new item can be inserted at any point in the menu. the function returns a non-zero value. ByVal uItem As Long. If the menu is a window's system menu. Visual Basic-Specific Issues When using InsertMenuItem to add something to a menu. Return Value If successful.).0 or later. Windows 98: Supported. Description & Usage InsertMenuItem adds a menu item to a menu that already exists. then the window receives the WM_SYSCOMMAND message instead.92/vbapi/ref/i/insertmenuitem. Also. when adding an item to a window's system menu. Instead. the function returns 0 (use GetLastError to get the error code).com | InsertMenuItem Function Declare Function InsertMenuItem Lib "user32. http://216.Windows API Guide: InsertMenuItem Function vbapi. Windows NT: Requires Windows NT 4. All identifiers greater than that are reserved for items that the system places there (such as Restore.vbshop. keep in mind that there is no way for Visual Basic to create an event handler to run when the item is selected.com | www. If the menu is a regular menu.vbforums.vbsquare. ByVal fByPosition As Long.html (1 of 5) [9/1/2002 5:32:53 PM] . If an error occured.com .part of the VB-World Network | www.com | www.

ByVal fByPosition As Long.dll" Alias "SetMenuItemInfoA" (ByVal _ hMenu As Long. lpmii Describes the menu item to be added. Example ' This code is licensed according to the terms and conditions listed here.26. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. (For example. then uItem is the unique menu item identifier of the existing item. fByPosition If this is a non-zero value. ByVal bRevert _ As Long) As Long Public Declare Function GetMenuItemCount Lib "user32. ByVal fByPosition As Long. but it's worth it! Public Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Long. ByVal uItem As Long.) If this is zero.dll" (ByVal hMenu As Long) As Long Public Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type Public Const MIIM_STATE = &H1 Public Const MIIM_ID = &H2 Public Const MIIM_TYPE = &H10 Public Const MFT_SEPARATOR = &H800 Public Const MFT_STRING = &H0 Public Const MFS_ENABLED = &H0 Public Const MFS_CHECKED = &H8 Public Declare Function InsertMenuItem Lib "user32.Windows API Guide: InsertMenuItem Function uItem Identifies the existing menu item that appears immediately before the point where you want to add the new item. uItem indicates the existing item by using its zero-based position. the first item in the menu has a position of 0.html (2 of 5) [9/1/2002 5:32:53 PM] .92/vbapi/ref/i/insertmenuitem.dll" Alias "InsertMenuItemA" (ByVal _ hMenu As Long. lpmii _ As MENUITEMINFO) As Long http://216. depending on fByPosition.168. lpmii _ As MENUITEMINFO) As Long Public Declare Function SetMenuItemInfo Lib "user32. ByVal uItem As Long. This could be either a position or a menu item identifier.) ' There's quite a few declarations for this example.

A check mark appears next to this option when active. ByVal _ hWndInsertAfter As Long.168. MFS_CHECKED. make sure that the Always On Top ' option is properly checked. ByVal lParam As Long) As Long Public Const WM_SYSCOMMAND = &H112 Public Const WM_INITMENU = &H116 ' ' a ' ' Add an option to make window Form1 "Always On Top" to the bottom of its system menu.26. hSysMenu = GetSystemMenu(hwnd. ByVal y As Long. 0) With mii ' Size of the structure.html (3 of 5) [9/1/2002 5:32:53 PM] . . ByVal x As Long. ' *** Place the following code in a module. ByVal _ cy As Long.fState = MFS_ENABLED Or IIf(ontop.dll" Alias "CallWindowProcA" (ByVal _ lpPrevWndFunc As Long. ByVal nIndex As Long. 0. ByVal cx As Long. check the item. Public Function WindowProc (ByVal hwnd As Long.fMask = MIIM_STATE ' If Form1 is now always on top. mii) WindowProc = 0 http://216. 1. The menu item acts as toggle.dll" Alias "SetWindowLongA" (ByVal hWnd _ As Long.cbSize = Len(mii) ' Only use what needs to be changed. ByVal hWnd As Long. ByVal uMsg As Long. ByVal wParam _ As Long. ByVal lParam As Long) As Long Dim hSysMenu As Long ' handle to Form1's system menu Dim mii As MENUITEMINFO ' menu item information for Always On Top Dim retval As Long ' return value Select Case uMsg Case WM_INITMENU ' Before displaying the system menu. ByVal Msg As Long. ByVal wFlags As Long) As Long Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Declare Function SetWindowLong Lib "user32.Windows API Guide: InsertMenuItem Function Public Declare Function SetWindowPos Lib "user32. *** Public pOldProc As Long Public ontop As Boolean ' pointer to Form1's previous window procedure ' identifies if Form1 is always on top or not ' The following function acts as Form1's window procedure to process messages.dll" (ByVal hWnd As Long. ByVal dwNewLong As Long) As Long Public Const GWL_WNDPROC = -4 Public Declare Function CallWindowProc Lib "user32. .92/vbapi/ref/i/insertmenuitem. 0) End With retval = SetMenuItemInfo(hSysMenu. Note how subclassing the window is necessary to process the two messages needed to give the added system menu item its full functionality. ByVal wParam _ As Long. .

http://216.hWnd. lParam) End Select End Function ' *** Place the following code inside Form1. *** ' When Form1 loads.wID = 0 End With ' Add the separator to the end of the system menu. With mii ' The size of the structure. let the previous procedure handle it. Let the previous window procedure ' process it.Windows API Guide: InsertMenuItem Function Case WM_SYSCOMMAND ' If Always On Top (ID = 1) was selected. add Always On Top to the system menu and set up the ' new window procedure. wParam. SWP_NOMOVE Or SWP_NOSIZE) WindowProc = 0 Else ' Some other item was selected. hwnd. WindowProc = CallWindowProc(pOldProc.fMask = MIIM_ID Or MIIM_TYPE ' This is a separator. . _ 0. HWND_NOTOPMOST). . Private Sub Form_Load() Dim hSysMenu As Long ' handle to the system menu Dim count As Long ' the number of items initially on the menu Dim mii As MENUITEMINFO ' describes a menu item to add Dim retval As Long ' return value ' Get a handle to the system menu. If wParam = 1 Then ' Reverse the setting and make it the current one.168. 0. lParam) End If Case Else ' If this is some other message.html (4 of 5) [9/1/2002 5:32:53 PM] . 0) ' See how many items are currently in it.cbSize = Len(mii) ' What parts of the structure to use. .92/vbapi/ref/i/insertmenuitem. wParam. hwnd. change the on top/not on top ' setting of Form1 to match. hSysMenu = GetSystemMenu(Form1.fType = MFT_SEPARATOR ' It has an ID of 0. . ontop = Not ontop retval = SetWindowPos(hwnd. HWND_TOPMOST. WindowProc = CallWindowProc(pOldProc.26. 0. uMsg. count = GetMenuItemCount(hSysMenu) ' Add a separator bar and then Always On Top to the system menu. IIf(ontop. 0. uMsg.

. 2000 This page is copyright © 2000 Paul Kuliniewicz. . mii) ' Likewise. Back to the Reference section.html http://216. pOldProc) ' Remove the modifications made to the system menu.vbapi.fType = MFT_STRING ' The option is enabled.hWnd.cch = Len(.html (5 of 5) [9/1/2002 5:32:53 PM] . ontop = False pOldProc = SetWindowLong(Form1.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE ' This is a regular text item.wID = 1 ' The text to place in the menu item. Copyright Information Revised October 29.92/vbapi/ref/i/insertmenuitem. retval = SetWindowLong(Form1. count + 1. . retval = InsertMenuItem(hSysMenu. count. 1) End Sub Category Menus Back to the Function list.fState = MFS_ENABLED ' It has an ID of 1 (this identifies it in the window procedure). With mii .26.hWnd.168. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long ' return value ' Replace the previous window procedure to prevent crashing. 1. 2000 Go back to the Windows API Guide home page. Last Modified: June 4. GWL_WNDPROC. . add the Always On Top command.hWnd. AddressOf WindowProc) End Sub ' Before unloading.dwTypeData) End With ' Add this to the bottom of the system menu.Windows API Guide: InsertMenuItem Function retval = InsertMenuItem(hSysMenu. mii) ' Set the custom window procedure to process Form1's messages. 1. GWL_WNDPROC.com/ref/i/insertmenuitem. retval = GetSystemMenu(Form1.dwTypeData = "&Always On Top" . restore the default system menu and remove the ' custom window procedure.

UnionRect Category: Rectangles Go back to the alphabetical Function listing. If one or both of the source rectangles are empty or there is no intersection.com | IntersectRect Function Declare Function IntersectRect Lib "user32.com | www. Example: ' Determine if windows Form1 and Form2 are overlapping on the ' screen.com | www.hWnd.vbapi.com . If they don't the intersection rectangle will be empty. the function returns 0 and the lpDestRect rectangle is set to (0.hWnd.dll" (lpDestRect As RECT.168. The rectangular region where the two source rectangles overlap is the intersection rectangle.vbshop.0). Go back to the Reference section index.Print "Windows Form1 and Form2 are overlapping on the screen." Else Debug. lpDestRect The rectangle to be set as the intersection of the two source rectangles. lpSrc2Rect The second source rectangle. window2 As RECT ' receive rectangles of Form1 and Form2 Dim result As Long ' will be set to 0 if no intersection. lpSrc1Rect The first source rectangle. window1) ' get Form1's rectangle retval = GetWindowRect(Form2. http://216.92/vbapi/ref/i/intersectrect. Win NT IntersectRect creates a rectangle based on the intersecting part of two other rectangles.0)-(0.vbsquare. lpSrc2Rect As RECT) As Long Platforms: Win 32s.26.vbworld. window2) ' determine the intersection rectangle If result = 0 ' in this case.vbforums. the intersection is put into lpDestRect and the function returns 1.html (1 of 2) [9/1/2002 5:33:00 PM] . Dim intrect As RECT ' receives the intersection rectangle Dim window1 As RECT. If the source rectangles do overlap. Win 95/98.com | www." End If See Also: SubtractRect. lpSrc1Rect As RECT.Print "Windows Form1 and Form2 are not overlapping on the screen. 1 if there is intersection Dim retval As Long ' return value for other functions retval = GetWindowRect(Form1. intrect will also be empty Debug.part of the VB-World Network | www.com | www. window1. window2) ' get Form2's rectangle result = IntersectRect(intrect.Windows API Guide: IntersectRect Function vbapi.

92/vbapi/ref/i/intersectrect. E-mail: vbapi@vbapi. Go back to the Windows API Guide home page.Windows API Guide: IntersectRect Function This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.vbapi.com/ref/i/intersectrect.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:33:00 PM] .26.html http://216.168.

com | InvertRect Function Declare Function InvertRect Lib "user32. Copyright Information. ByVal lpRect As RECT) As Long Platforms: Win 32s.part of the VB-World Network | www.html [9/1/2002 5:33:06 PM] . Go back to the Reference section index. 20. 100) ' set r to be (20. The function returns a non-zero value if successful. 30.92/vbapi/ref/i/invertrect.vbsquare.vbapi.100) retval = InvertRect(Form1.html http://216.Windows API Guide: InvertRect Function vbapi.100) on window Form1.vbforums. E-mail: vbapi@vbapi.vbapi. Example: ' Invert the colors in the rectangle (20.com | www.dll" (ByVal hdc As Long. Win 95/98. Dim r As RECT ' rectangle to invert Dim retval As Long ' return value retval = SetRect(r.vb-shop. or 0 if an error occured.com . 150.com | www.com/ref/i/invertrect.30)-(150. Win NT InvertRect inverts the image inside a rectangular area on a device. lpRect The rectangle to invert. This page is copyright © 2000 Paul Kuliniewicz.vbworld. r) ' invert the pixels within the rectangle See Also: InvertRgn Category: Filled Shapes Go back to the alphabetical Function listing.26. hdc A device context to the device to invert the colors in a given rectangle on. The inverted colors are calculated by taking the binary NOT of each pixel's RGB color value inside the rectangle.com | www. Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.com | www.hDC.30)-(150.168.

vbworld. Win 95/98.html (1 of 2) [9/1/2002 5:33:14 PM] . hdc A device context to the device to invert the pixels within a region of.92/vbapi/ref/i/invertrgn.110) ' Invert that region in window Form1.com | www.110). or a non-zero value if successful.Windows API Guide: InvertRgn Function vbapi.com | InvertRgn Function Declare Function InvertRgn Lib "gdi32.vb-shop. Example: ' Invert the pixels ' elliptical region Dim hrgn As Long ' Dim retval As Long within an elliptical region on window Form1.com | www. ByVal hRgn As Long) As Long Platforms: Win 32s. retval = DeleteObject(hrgn) See Also: InvertRect Category: Regions Go back to the alphabetical Function listing.26.30)-(150.com .vbapi.dll" (ByVal hdc As Long.168.com | www. The inverse of the pixels is calculated by doing a binary NOT operation on the RGB color value of each pixel.hDC. The has a bounding rectangle of (20. retval = InvertRgn(Form1. handle to the region to invert ' return value ' Create the elliptical region to invert and get a handle to it. hrgn) ' Delete the region to free up resources.vbsquare. The function returns 0 if an error occured.30.part of the VB-World Network | www.com | www. hrgn = CreateEllipticRgn(20. Go back to the Reference section index.150.vbforums. http://216. hRgn A handle to the region on the device to invert. Win NT InvertRgn inverts the colors of all the pixels inside a region on a given device.

168. Go back to the Windows API Guide home page.com/ref/i/invertrgn. E-mail: vbapi@vbapi.Windows API Guide: InvertRgn Function This page is copyright © 2000 Paul Kuliniewicz.html (2 of 2) [9/1/2002 5:33:14 PM] .com Send Encrypted E-Mail This page is at http://www.vbapi.92/vbapi/ref/i/invertrgn. Copyright Information.html http://216.26.

If an error occured. Visual Basic-Specific Issues When setting cmd to FIONBIO. Description & Usage ioctlsocket manipulates the i/o mode of a socket. cmd One of the following flags specifying the action to take: FIONBIO Set the blocking mode of the socket.vbsquare. Parameters s The descriptor of the socket to manipulate.1 or later. ByVal cmd As Long.part of the VB-World Network | www.com | ioctlsocket Function Declare Function ioctlsocket Lib "wsock32.168. which is the default value. the socket is set to nonblocking mode.com | www.html (1 of 5) [9/1/2002 5:33:24 PM] . Windows CE: Requires Windows CE 1. do not use the ByVal keyword in front of the parameter passed as argp. the socket is set to block (halt the program if no data is yet available to read from the socket). Windows NT: Requires Windows NT 3. the function returns SOCKET_ERROR (use WSAGetLastError to get the error code).com | www.Windows API Guide: ioctlsocket Function vbapi. Windows 98: Supported. the socket must have been created by a previous call to socket. the function returns zero.com | www.vbworld.92/vbapi/ref/i/ioctlsocket.vbshop.0 or later. where functions reading the socket return immediately instead of waiting for input to arrive. argp As Long) As Long Platforms q q q q q Windows 95: Supported. Return Value If successful.com | www. The variable passed as argp receives the number of bytes sitting in the buffer waiting to be read. It gets or sets parameters that control how the socket performs input and output. If this is a non-zero value. (For datagram-based sockets. FIONREAD Determine the amount of data sitting in the socket's input buffer. If argp is zero.26.com . this value is the size of the http://216. Windows 2000: Supported. Naturally.dll" (ByVal s As Long.vbapi.vbforums.

) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type Public Declare Function WSAStartup Lib "wsock32. Constant Definitions Const Const Const Const FIONBIO = &H8004667E FIONREAD = &H4004667F SIOCATMARK = &H40047307 SOCKET_ERROR = -1 Example Download the main page of this web site (http://www. To use this example. and the next attempt to read from the socket will read from the out-of-band data.com). ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) SIOCATMARK Determine if there is any out-of-band data waiting to be read from the socket. If VB had better exception handling. a nonblocking socket is used. argp Usage depends on the flag used for cmd. The document downloaded. the variable passed as argp receives zero. place a command button named cmdDownload on a form window.vbapi. is output to the Debug window. This example supports a very crude implementation of HyperText Transport Protocol (HTTP).dll" () As Long Public Const AF_INET = 2 Public Const SOCK_STREAM = 1 Public Declare Function gethostbyname Lib "wsock32.92/vbapi/ref/i/ioctlsocket. If so. ' This code is licensed according to the terms and conditions listed here. Since there are lots of things that can go wrong.26. the GoTo statements skip down to the end if an unrecoverable error occurs. sending a request to the server and receiving the document. argp receives a non-zero value. with HTTP headers removed.168.dll" (ByVal wVersionRequested As Integer. To prevent the program from appearing to lock up in the event of a momentary interruption in the transfer. If there is no unread out-of-band data. lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" (ByVal name As String) As Long Public Type hostent http://216.Windows API Guide: ioctlsocket Function first datagram in the buffer.html (2 of 5) [9/1/2002 5:33:24 PM] . Note the careful use of GoTo in this example. I would use that instead of GoTo. and WSACleanup must be called at the end no matter what happens.

2) & Right("00" & Hex(bLow).dll" (ByVal af As Long.dll" (ByVal s As Long.dll" (ByVal s As Long. _ ByVal protocol As Long) As Long Public Type sockaddr sin_family As Integer sin_port As Integer sin_addr As Long sin_zero As String * 8 End Type Public Declare Function connect Lib "wsock32.Windows API Guide: ioctlsocket Function h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Declare Function htons Lib "wsock32. _ ByVal flags As Long) As Long Public Declare Function closesocket Lib "wsock32.dll" Alias "RtlMoveMemory" (Destination As Any. Source _ As Any. argp As Long) As Long Public Const FIONBIO = &H8004667E Public Declare Function send Lib "wsock32. ByVal bHigh As Byte) As Integer MAKEWORD = Val("&H" & Right("00" & Hex(bHigh).26. buf As Any.html (3 of 5) [9/1/2002 5:33:24 PM] .dll" (ByVal s As Long. ByVal prototype As Long. ByVal length As Long.92/vbapi/ref/i/ioctlsocket.dll" (ByVal s As Long) As Long Public Declare Sub CopyMemory Lib "kernel32. *** Private Sub Dim Dim Dim Dim Dim Dim Dim cmdDownload_Click() wsockinfo As WSADATA sock As Long pHostinfo As Long hostinfo As hostent pIPAddress As Long ipAddress As Long sockinfo As sockaddr ' ' ' ' ' ' ' info about Winsock the socket descriptor pointer to info about the host computer info about the host computer pointer to host's IP address host's IP address settings for the socket http://216.dll" (ByVal hostshort As Integer) As Integer Public Declare Function socket Lib "wsock32. ByVal namelen _ As Long) As Long Declare Function ioctlsocket Lib "wsock32. _ ByVal flags As Long) As Long Public Declare Function recv Lib "wsock32.168. buf As Any. 2)) End Function ' *** Place the following code inside the form window. Public Function MAKEWORD(ByVal bLow As Byte. name As sockaddr. ByVal length As Long. ByVal Length As Long) Public Const SOCKET_ERROR = -1 ' Define a useful macro.dll" (ByVal s As Long. ByVal cmd As Long.

com") If pHostinfo = 0 Then Debug.com!" GoTo Cleanup End If ' Get the server's IP address out of the structure.h_addr_list.Print "Attempting to connect..vbapi. 2).sin_zero = String(8.h_addrtype <> AF_INET Then Debug. CopyMemory pIPAddress. ByVal hostinfo. . .sin_family = AF_INET ' Connect to port 80.Print "Couldn't get IP address of www.Print "Unable to resolve host!" GoTo Cleanup End If ' Copy information about the server into the structure.vbapi.Windows API Guide: ioctlsocket Function Dim buffer As String Dim reply As String Dim retval As Long ' buffer for sending and receiving data ' accumulates server's reply ' generic return value ' Begin a Winsock session.. wsockinfo) If retval <> 0 Then Debug. 4 CopyMemory ipAddress. Len(sockinfo)) If retval <> 0 Then Debug.vbapi. pHostinfo = gethostbyname("www.Print "Unable to connect!" GoTo Cleanup End If http://216. 0) If sock = SOCKET_ERROR Then Debug. ByVal pHostinfo. . With sockinfo ' Use Internet Protocol (IP) .26.html (4 of 5) [9/1/2002 5:33:24 PM] . 4 ' Create a socket. sock = socket(AF_INET. vbNullChar) End With Debug. retval Exit Sub End If ' Get information about the server to connect to.com:80 (where the web server listens).Print "Unable to initialize Winsock! --".92/vbapi/ref/i/ioctlsocket.sin_addr = ipAddress ' Padding characters.Print "Unable to create socket!" GoTo Cleanup End If ' Make a connection to www.168.. ByVal pIPAddress. retval = WSAStartup(MAKEWORD(2. SOCK_STREAM.sin_port = htons(80) ' Connect to this IP address. sockinfo." retval = connect(sock. Len(hostinfo) If hostinfo. CopyMemory hostinfo.

if the connection is ' lost).1" & vbCrLf & _ "Host: www.com/ref/i/ioctlsocket.. Len(buffer). 0) If retval <> 0 And retval <> SOCKET_ERROR Then reply = reply & Left(buffer. ByVal buffer.." ' Make the socket non-blocking. 2001 This page is copyright © 2001 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www. 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.26. 0) Debug.Print "Document Retrieved:" Debug. so calls to recv don't halt the program waiting for input. DoEvents Loop Until retval = 0 ' Print the response from the server.Print "Sent request. Do buffer = Space(4096) retval = recv(sock. such code is omitted here. retval) End If ' Process background events so the program doesn't appear to freeze. Waiting for reply.Print reply ' Perform the necessary cleanup at the end. retval = ioctlsocket(sock. FIONBIO.html http://216. For brevity.vbapi.html (5 of 5) [9/1/2002 5:33:24 PM] . Cleanup: retval = closesocket(sock) retval = WSACleanup() End Sub Category Winsock Back to the Function list. Len(buffer).e. Back to the Reference section.. Copyright Information Revised October 29. A more sophisticated program ' would watch to see if the connection ever times out (i.com" & vbCrLf & _ "User-Agent: HTTP-Test-Program" & vbCrLf & vbCrLf retval = send(sock. 1) ' Read the response from the other system. Last Modified: January 21. ByVal buffer.vbapi.168.92/vbapi/ref/i/ioctlsocket. buffer = "GET / HTTP/1.Windows API Guide: ioctlsocket Function ' Send an HTTP/GET request for the / document. Debug.

com | www.com | www.dll" (ByVal hWndParent As Long. If the relationship does exist. the function returns 0.26.vbsquare.1 or later.Windows API Guide: IsChild Function vbapi.com | www. Windows NT: Requires Windows NT 3.vbforums.com .vbshop. Return Value If a parent-child relationship does not exist between the two windows.part of the VB-World Network | www.168. The possible child window must be a direct descendant of the possible parent window.0 or later.vbworld. if the possible child window is a child of a child of the possible parent window. Windows 2000: Supported.92/vbapi/ref/i/ischild. For example. Parameters hWndParent A handle to the candidate parent window.vbapi. ByVal hWnd As Long) As Long Platforms q q q q q Windows 95: Supported.html (1 of 2) [9/1/2002 5:33:32 PM] . the function returns a non-zero value.com | www. Visual Basic-Specific Issues None. Windows 98: Supported. the parent-child relationship does not exist. Description & Usage IsChild determines if a parent-child relationship exists between two windows. Windows CE: Requires Windows CE 1. hWnd A handle to the candidate child window. Example http://216.com | IsChild Function Declare Function IsChild Lib "user32.

Command1. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:33:32 PM] . a ' of Form1." ' will happen Else Debug. However." ' won't happen See Also IsWindow. 1999 This page is copyright © 1999 Paul Kuliniewicz. Form2.vbapi.hWnd.Print "Form1 is not Command1's parent window. result = IsChild(Form1. Copyright Information Revised October 29. fellow Dim result As Long ' result relationship and a non-parent-child command button on window Form1." ' will happen End If ' Verify that Form2 is not a child of Form1. SetParent Category Windows Back to the index." ' won't happen Else Debug.26.Print "Form1 is Form2's parent window.hWnd) ' see if Form1 is Command1's parent If result = 0 Then Debug.Print "Form1 is not Form2's parent window. result = IsChild(Form1. 2000 Go back to the Windows API Guide home page.Windows API Guide: IsChild Function ' This code is licensed according to the terms and conditions listed here.html http://216.hWnd) ' see if Form1 is Form2's parent If result = 0 Then Debug.92/vbapi/ref/i/ischild. ' Demonstrate a parent-child ' relationship.com/ref/i/ischild. Last Modified: August 1. Command1. is a child window Form2 is not a child. of the function ' Verify that Command1 is a child of Form1.hWnd.Print "Form1 is Command1's parent window.com Send Encrypted E-Mail This page is at http://www.168.

dll" (ByVal hwnd As Long) As Long Platforms: Win 32s. The function returns 0 if the window is not minimized (it could be either restored or maximized).Print "Form1 is maximized.vbworld.hWnd) ' is Form1 minimized? maxflag = IsZoomed(Form1. maxflag As Long ' receive minimized or maximized status minflag = IsIconic(Form1. ShowWindow Category: Windows Go back to the alphabetical Function listing. minimized. This page is copyright © 2000 Paul Kuliniewicz.com | IsIconic Function Declare Function IsIconic Lib "user32.part of the VB-World Network | www." Else Debug.com | www. Copyright Information.Print "Form1 is restored.vbsquare. Go back to the Reference section index.com Send Encrypted E-Mail http://216.26.168.com | www.com | www. it returns a non-zero value if the window is minimized. E-mail: vbapi@vbapi.com | www. Go back to the Windows API Guide home page." End If See Also: IsZoomed. Win NT IsIconic finds if a given window is minimized or not. Dim minflag As Long.com .vbforums. Win 95/98.92/vbapi/ref/i/isiconic." Elseif maxflag <> 0 Then Debug.vb-shop. Example: ' Determine if the window Form1 is maximized.vbapi.hWnd) ' is Form1 maximized? If minflag <> 0 Then Debug. or restored.Print "Form1 is minimized.html (1 of 2) [9/1/2002 5:33:37 PM] . hwnd A handle to the window to find whether it is minimized or not.Windows API Guide: IsIconic Function vbapi.

html http://216.Windows API Guide: IsIconic Function This page is at http://www.26.vbapi.com/ref/i/isiconic.168.92/vbapi/ref/i/isiconic.html (2 of 2) [9/1/2002 5:33:37 PM] .

A rectangle is considered empty if its right edge is not to the right of its left edge and/or its bottom edge is not below its top edge. window1.vbsquare. http://216.it will be if there's no intersection If isempty = 0 ' in this case. a rectangle (50. window1) ' get Form1's rectangle retval = GetWindowRect(Form2.Print "Windows Form1 and Form2 are not overlapping on the screen.hWnd. Example: ' Determine if windows Form1 and Form2 are overlapping on the ' screen.Print "Windows Form1 and Form2 are overlapping on the screen.hWnd.com .vbforums. For example.com | IsRectEmpty Function Declare Function IsRectEmpty Lib "user32.100) is empty because the right edge is to the left of the left edge. window2) ' get Form2's rectangle retval = IntersectRect(intrect.http://216.168. If they don't the intersection rectangle will be empty.92/vbapi/ref/i/isrectempty.vbapi.com | www. Go back to the Reference section index.com | www.com | www.dll" (lpRect As RECT) As Long Platforms: Win 32s. intrect will also be empty Debug.50)-(25.com | www.html vbapi. Dim intrect As RECT ' receives the intersection rectangle Dim window1 As RECT. window2) ' determine the intersection rectangle isempty = IsRectEmpty(intrect) ' determine if it is empty -. Win NT IsRectEmpty checks to see if a rectangle is empty.92/vbapi/ref/i/isrectempty. Win 95/98.html (1 of 2) [9/1/2002 5:33:42 PM] .26.26.vbworld.vbshop. The function returns 1 if the rectangle is empty and 0 if it is not.168." End If See Also: SetRectEmpty Category: Rectangles Go back to the alphabetical Function listing." Else Debug.part of the VB-World Network | www. lpRect The rectangle to check. window2 As RECT ' receive rectangles of Form1 and Form2 Dim isempty As Long ' will be set to 0 if intersection isn't empty. 1 if it is Dim retval As Long ' return value for other functions retval = GetWindowRect(Form1.

http://216.168.26.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.html This page is copyright © 2000 Paul Kuliniewicz.168.vbapi.html (2 of 2) [9/1/2002 5:33:42 PM] .26.com/ref/i/isrectempty.92/vbapi/ref/i/isrectempty.92/vbapi/ref/i/isrectempty. Copyright Information. Go back to the Windows API Guide home page.html http://216.

dll" (ByVal hWnd As Long) As Long Platforms q q q q q Windows 95: Supported.vbapi.html (1 of 3) [9/1/2002 5:33:47 PM] .vb-shop.0 or later.168.com . The function verifies that the handle in fact refers to a window. Windows 98: Supported.com | www. If the handle does refer to a window. Visual Basic-Specific Issues None. the function returns 0. Example http://216.92/vbapi/ref/i/iswindow. Return Value If the handle does not refer to a window.com | IsWindow Function Declare Function IsWindow Lib "user32.vbworld.vbforums.Windows API Guide: IsWindow Function vbapi. Desctiption & Usage IsWindow determines if a given handle refers to a window or not. Windows CE: Requires Windows CE 1.vbsquare. Windows 2000: Supported. the function returns a non-zero value.1 or later.com | www.26.com | www.part of the VB-World Network | www. Windows NT: Requires Windows NT 3. Parameters hWnd The handle to check if it refers to a window or not. instead of one of the many other objects which handles can represent.com | www.

92/vbapi/ref/i/iswindow.com Send Encrypted E-Mail http://216.Print "hWindow refers to a window. result = IsWindow(hWindow) If result = 0 Then Debug.html (2 of 3) [9/1/2002 5:33:47 PM] . Dim hWindow As Long ' handle to a window (Form1. ' Demonstrate handles refering to a window and not refering to a window.168. hWindow = Form1. result = IsWindow(hPen) If result = 0 Then Debug. 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.hWnd ' hWindow now equals window Form1's handle hPen = GetStockObject(BLACK_PEN) ' hPen refers to a pen ' Verify that hWindow refers to a window. Last Modified: August 1.Print "hWindow does not refer to a window.Windows API Guide: IsWindow Function ' This code is licensed according to the terms and conditions listed here. 1999 This page is copyright © 1999 Paul Kuliniewicz. Go back to the Reference section index." ' won't happen End If See Also IsChild Category Windows Go back to the alphabetical Function listing." ' won't happen Else Debug.Print "hPen does not refer to a window. to be exact) Dim hPen As Long ' handle to a pen (the solid black stock pen) Dim result As Long ' result of the test ' Initialize the two handles. Copyright Information Revised October 29." ' will happen Else Debug.Print "hPen refers to a window." ' will happen End If ' Verify that hPen does not refer to a window.26.

com/ref/i/iswindow.Windows API Guide: IsWindow Function This page is at http://www.26.vbapi.92/vbapi/ref/i/iswindow.html (3 of 3) [9/1/2002 5:33:47 PM] .168.html http://216.

part of the VB-World Network | www. Win 95/98. Example: ' Reverse the enabled status of window Command1.vbworld.168. hwnd A handle to the window to determine if it is enabled or disabled. If the window is ' disabled.vbapi.dll" (ByVal hwnd As Long) As Long Platforms: Win 32s.com | www.com | www. disable it retval = EnableWindow(Command1. Win NT IsWindowEnabled determines if a window is currently enabled or disabled. Dim wasenabled As Long ' receives enabled/disabled status of Command1 Dim retval As Long ' return value ' Determine if the window Command1 is currently enabled or not. 0) End If See Also: EnableWindow Category: Windows Go back to the alphabetical Function listing.html (1 of 2) [9/1/2002 5:33:51 PM] . 1) Else ' if enabled. it cannot receive the focus and will ignore any attempted input.26.92/vbapi/ref/i/iswindowenabled. If a window is disabled. will appear grayed when disabled.hWnd. enable it. Many types of windows. disable it.hWnd) If wasenabled = 0 Then ' if not enabled.vbforums.com | www.vbsquare. enable it retval = EnableWindow(Command1.com | www. or a non-zero value if the window is enabled. such as buttons and other controls.Windows API Guide: IsWindowEnabled Function vbapi. if it is enabled. wasenabled = IsWindowEnabled(Command1.vb-shop.com | IsWindowEnabled Function Declare Function IsWindowEnabled Lib "user32.com . The function returns 0 if the window is disabled.hWnd. http://216. Go back to the Reference section index.

168. E-mail: vbapi@vbapi.26. Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:33:51 PM] .com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/i/iswindowenabled.vbapi.com/ref/i/iswindowenabled. Copyright Information.html http://216.Windows API Guide: IsWindowEnabled Function This page is copyright © 2000 Paul Kuliniewicz.

" Elseif maxflag <> 0 Then Debug. hwnd A handle to the window to find whether it is maximized or not." End If See Also: IsIconic." Else Debug.html (1 of 2) [9/1/2002 5:33:56 PM] . or restored.vbworld.vbsquare. E-mail: vbapi@vbapi. maxflag As Long ' receive minimized or maximized status minflag = IsIconic(Form1.92/vbapi/ref/i/iszoomed.com . This page is copyright © 2000 Paul Kuliniewicz. The function returns 0 if the window is not maximized (it could be either restored or minimized).26.hWnd) ' is Form1 maximized? If minflag <> 0 Then Debug. Win NT IsZoomed finds if a given window is maximized or not.vbforums. Example: ' Determine if the window Form1 is maximized.com | www.com | IsZoomed Function Declare Function IsZoomed Lib "user32.Print "Form1 is maximized. Copyright Information. Go back to the Windows API Guide home page. ShowWindow Category: Windows Go back to the alphabetical Function listing. Win 95/98. minimized.com | www.com | www.part of the VB-World Network | www.dll" (ByVal hwnd As Long) As Long Platforms: Win 32s.Windows API Guide: IsZoomed Function vbapi.168. Dim minflag As Long.com | www.vbapi.Print "Form1 is minimized. it returns a non-zero value if the window is maximized.vb-shop.com Send Encrypted E-Mail http://216. Go back to the Reference section index.hWnd) ' is Form1 minimized? maxflag = IsZoomed(Form1.Print "Form1 is restored.

com/ref/i/iszoomed.Windows API Guide: IsZoomed Function This page is at http://www.26.vbapi.168.html (2 of 2) [9/1/2002 5:33:56 PM] .html http://216.92/vbapi/ref/i/iszoomed.

joyinfo.part of the VB-World Network | www.Print "The joystick driver is: ".dll" Alias "joyGetDevCapsA" (ByVal id As Long.168.com | www.szPname.vbsquare. however.com | joyGetDevCaps Function Declare Function joyGetDevCaps Lib "winmm. uSize The length in bytes of lpCaps.com . This function does not.vbworld.html (1 of 2) [9/1/2002 5:34:02 PM] . Go back to the Reference section index. Len(joyinfo)) ' read joystick information If retval = 0 Then ' there is a functioning Joystick #1 joydriver = Left(joyinfo." End If Category: Joysticks Go back to the alphabetical Function listing.vbforums.vbapi.92/vbapi/ref/j/joygetdevcaps.1) ' extract data from the fixed-length string Debug.com | www.Windows API Guide: joyGetDevCaps Function vbapi. This information is put into the variable passed as lpCaps.Print "There is no joystick connected to Joystick Port #1.vb-shop.com | www. InStr(joyinfo.26. give you the current position of the joystick. starting with 0. ByVal uSize As Long) As Long Platforms: Win 95/98 joyGetDevCaps reads various information about a joystick. lpCaps Variable that receives the information about the joystick.szPname. id The ID number of the joystick to read.com | www. lpCaps As JOYCAPS. Dim joyinfo As JOYCAPS ' receives joystick information Dim joydriver As String ' will be set to the joystick's driver name Dim retval As Long ' return value retval = joyGetDevCaps(0. The function returns 0 if the joystick is connected and working and a non-zero error code if it isn't. Example: ' Display the name of the joystick driver for Joystick #1 ' Note that the ID of Joystick #1 is 0. vbNullChar) . joydriver Else Debug. http://216.

com Send Encrypted E-Mail This page is at http://www.html http://216.com/ref/j/joygetdevcaps.26.html (2 of 2) [9/1/2002 5:34:02 PM] .92/vbapi/ref/j/joygetdevcaps. Go back to the Windows API Guide home page.Windows API Guide: joyGetDevCaps Function This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.168. E-mail: vbapi@vbapi.vbapi.

part of the VB-World Network | www.vbapi." Category: Joysticks Go back to the alphabetical Function listing. "joysticks currently connected to the computer.vbsquare.vbshop. numexist.com/ref/j/joygetnumdevs.92/vbapi/ref/j/joygetnumdevs.Print "There are".) retval = joyGetDevCaps(c. Dim joyinfo As JOYCAPS ' needed for the function call to see if a joystick works Dim numjoys As Long ' receives number of configured joysticks Dim numexist As Long ' number of existing joysticks hooked up to the computer Dim c As Integer ' counter variable Dim retval As Long ' return value for other functions numjoys = joyGetNumDevs() ' determine the number of configured joysticks Debug. "joysticks configured under Windows. The best way to see if a joystick is working is to call joyGetDevCaps and check for a return value of 0.com Send Encrypted E-Mail This page is at http://www.dll" () As Long Platforms: Win 95/98 joyGetNumDevs returns the number of joysticks that are configured under Windows's Control Panel.html [9/1/2002 5:34:07 PM] . E-mail: vbapi@vbapi. This doesn't necessarily mean that all of them are connected and in working order.vbapi." numexist = 0 ' initialize the number of existing joysticks For c = 0 To numjoys . Go back to the Windows API Guide home page.26.vbforums. but there could be.1 ' check each joystick (remember Joystick #1's ID = 0.html http://216.com | www.Windows API Guide: joyGetNumDevs Function vbapi.com . try to read information from it and see if ' the attempt is successful or not. To see if a joystick is connected.com | www.com | www.com | www. Len(joyinfo)) ' try to read information If retval = 0 Then numexist = numexist + 1 ' increment counter if the joystick is connected Next c Debug. etc. Go back to the Reference section index.Print "There are". joyinfo. Copyright Information.168.com | joyGetNumDevs Function Declare Function joyGetNumDevs Lib "winmm. numjoys. This page is copyright © 2000 Paul Kuliniewicz.vbworld. Example: ' Determine the number of configured joysticks and the number of ' connected joysticks.

wButtons And JOY_BUTTON3) = JOY_BUTTON3 Then Debug. or a non-zero error code if it is not.com | www.Print "Y Coordinate:". uJoyID The ID number of the joystick to read.wYpos Debug. y.92/vbapi/ref/j/joygetpos.Print "Z Coordinate:".com | joyGetPos Function Declare Function joyGetPos Lib "winmm." If (pos.Print "Button 1 is depressed.com . and z coordinates of Joystick #1. pji Variable that receives the joystick's current position and status. The function returns 0 if the joystick is connected and working.vbsquare. Copyright Information. This information is put into the variable passed as pji. pji As JOYINFO) As Long Platforms: Win 95/98 joyGetPos reads the current position and status of a joystick. joypos) ' get the joystick status (remember Joystick #1's ID = 0) Debug. pos. pos.wZpos If (pos.26.dll" (ByVal uJoyID As Long.com | www." If (pos. This page is copyright © 2000 Paul Kuliniewicz.Print "Button 3 is depressed." Category: Joysticks Go back to the alphabetical Function listing.vbshop.vbworld. Go back to the Reference section index.Print "Button 2 is depressed.com | www.wXpos Debug.com | www. Dim joypos As JOYINFO ' receives current joystick status Dim retval As Long ' return value retval = joyGetPos(0.vbapi.wButtons And JOY_BUTTON1) = JOY_BUTTON1 Then Debug.part of the VB-World Network | www. http://216.wButtons And JOY_BUTTON2) = JOY_BUTTON2 Then Debug.Print "Button 4 is depressed." If (pos. pos.html (1 of 2) [9/1/2002 5:34:12 PM] . starting at 0.168.Windows API Guide: joyGetPos Function vbapi.vbforums. Example: ' Display the x.Print "X Coordinate:".wButtons And JOY_BUTTON4) = JOY_BUTTON4 Then Debug. as well ' as the status of buttons 1-4 (which are the only ones this function can read).

vbapi. E-mail: vbapi@vbapi.26.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:34:12 PM] .com/ref/j/joygetpos.92/vbapi/ref/j/joygetpos.168.Windows API Guide: joyGetPos Function Go back to the Windows API Guide home page.html http://216.

Parameters bVk The virtual-key code of the key to simulate pressing or releasing.com | keybd_event Function Declare Sub keybd_event Lib "user32.26. The function can simulate a single press or release of a single key.1 or later but Obsolete with Windows NT 4. use SendInput instead. http://216.html (1 of 3) [9/1/2002 5:34:18 PM] .com | www.part of the VB-World Network | www.vbforums. For example.168.com | www. ByVal dwFlags As Long.0 or later.vbapi.92/vbapi/ref/k/keybd_event. use SendInput instead. This function should only be used when a key's state changes.com | www. Windows 98: Supported but Obsolete.0 with Service Pack 3 (SP3) or later.0 or later but Obsolete with Windows CE 2.vbworld.com | www. Windows CE: Requires Windows CE 1. ByVal bScan As Byte. use SendInput instead. do not tell the function to simulate pressing the Z key if the Z key is already pressed. Windows 2000: Supported but Obsolete.Windows API Guide: keybd_event Function vbapi. ByVal dwExtraInfo As Long) Platforms q q q q q Windows 95: Supported.vb-shop. Return Value keybd_event does not return a value. Windows NT: Requires Windows NT 3. Visual Basic-Specific Issues None. Description & Usage keybd_event simulates keyboard input by placing a keyboard input event into the input stream.com .dll" (ByVal bVk As Byte.vbsquare. use SendInput instead.

0. keybd_event VK_MENU.92/vbapi/ref/k/keybd_event. Constant Definitions Const KEYEVENTF_EXTENDEDKEY = &H1 Const KEYEVENTF_KEYUP = &H2 Example ' This code is licensed according to the terms and conditions listed here. ' key combination will minimize the active window. keybd_event VK_N. This ' Hold the Alt key while typing Space. ' Simulate the user pressing Alt+Space followed by N. KEYEVENTF_KEYUP The key specified in bVk is being released. 0. SendInput Category Keyboard http://216. 0.set to 0. 0. KEYEVENTF_KEYUP. 0 ' release Alt ' Type the N key. KEYEVENTF_KEYUP. 0. 0 ' press N keybd_event VK_N.Windows API Guide: keybd_event Function bScan Reserved -. 0. 0 ' press Alt keybd_event VK_SPACE. 0. 0 ' press Space keybd_event VK_SPACE. 0. 0. 0 ' release N See Also mouse_event. If this flag is not specified. KEYEVENTF_KEYUP. 0 ' release Space keybd_event VK_MENU.168. dwFlags A combination of the following flags specifying what kind of keyboard input to synthesize: KEYEVENTF_EXTENDEDKEY Prefix the scan code with a prefix byte having the value &HE0.html (2 of 3) [9/1/2002 5:34:18 PM] . the key is being pressed. dwExtraInfo An additional 32-bit value associated with the keyboard event.26.

html (3 of 3) [9/1/2002 5:34:18 PM] .html http://216.vbapi. Copyright Information Revised October 29. 2000 Go back to the Windows API Guide home page. Last Modified: August 7.168. Go back to the Reference section index.26.com Send Encrypted E-Mail This page is at http://www. 1999 This page is copyright © 1999 Paul Kuliniewicz. E-mail: vbapi@vbapi.92/vbapi/ref/k/keybd_event.com/ref/k/keybd_event.Windows API Guide: keybd_event Function Go back to the alphabetical Function listing.

vbshop.92/vbapi/ref/k/killtimer.vbforums.part of the VB-World Network | www.0 or later.26.168. Parameters hWnd A handle to the window that owns the timer.com . the function returns a non-zero value. Description & Usage KillTimer deactivates and destroys the specified timer. Return Value If successful.com | www. Windows 2000: Supported. This index was specified in the call to SetTimer. this is the value returned by the call to SetTimer. the function returns 0 (use GetLastError to get the error code). The time is updated twice every second.com | KillTimer Function Declare Function KillTimer Lib "user32. it does not remove any existing WM_TIMER messages which may still be sitting in a window's message queue. Visual Basic-Specific Issues None.vbapi. If an error occured. this is the program-defined identifer of the timer. Your program should destroy any timer created by SetTimer once it is no longer needed. Windows CE: Requires Windows CE 1. Windows 98: Supported.com | www.com | www.dll" (ByVal hWnd As Long.com | www. and the time is formatted according http://216.html (1 of 3) [9/1/2002 5:34:24 PM] . Example Display the current time in text box control Text1. This must be the same value originally passed to SetTimer.vbworld. uIDEvent If the timer was owned by a window.1 or later. Windows NT: Requires Windows NT 3. However. if the timer was configured to do so.vbsquare. ByVal nIDEvent As Long) As Long Platforms q q q q q Windows 95: Supported. If the timer is not owned by any window.Windows API Guide: KillTimer Function vbapi.

_ ByVal dwTime As Long) ' the current time Dim systime As SYSTEMTIME Dim timestr As String * 260 ' receives the formatted string Dim slength As Long ' length of formatted string returned ' Retrieve the current time.dll" (ByVal hWnd As Long. GetLocalTime systime ' Format a string to represent the time. slength = GetTimeFormat(0. Form1. CLng(0). slength) End Function ' *** Place the following code inside Form1.Windows API Guide: KillTimer Function to the current locale's settings. 0. according to the computer's time zone.168. *** ' The following function will execute twice every second. ' The timer is given an ID of 1.dll" Alias "GetTimeFormatA" (ByVal _ Locale As Long. To use this example. ByVal nIDEvent As Long) As Long Public Declare Function GetTimeFormat Lib "kernel32.26. place a text edit box named Text1 on a form window. ByVal dwFlags As Long.html (2 of 3) [9/1/2002 5:34:24 PM] . found on window Form1. ' This code is licensed according to the terms and conditions listed here. Private Sub Form1_Load() http://216. It retrieves ' the current time and displays it according to the current locale's formatting preferences.Text = Left(timestr. lpTime As SYSTEMTIME. ByVal uMsg As Long. ByVal lpTimerFunc As Long) As Long Public Declare Function KillTimer Lib "user32.dll" (ByVal hWnd As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. _ ByVal lpTimeStr As String. ByVal cchTime As Long) As Long ' *** Place the following code inside a module. Len(timestr)) ' Display the string in Text1. ByVal lpFormat As Any. ByVal uElapse As Long. ByVal nIDEvent _ As Long. systime. timestr. *** ' Create the timer when the form opens and destroy it when the form closes.92/vbapi/ref/k/killtimer.Text1. ByVal idEvent As Long. so the return values don't need to be saved.) Public Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Public Declare Function SetTimer Lib "user32. Public Sub TimerProc (ByVal hwnd As Long.

Copyright Information Revised October 29.vbapi. 2000 Go back to the Windows API Guide home page. AddressOf TimerProc) End Sub Private Sub Form1_Unload(Cancel As Integer) Dim retval As Long ' return value retval = KillTimer(Form1.hWnd. Back to the Reference section. 2000 This page is copyright © 2000 Paul Kuliniewicz.Windows API Guide: KillTimer Function Dim retval As Long ' return value retval = SetTimer(Form1.hWnd.com/ref/k/killtimer.26.92/vbapi/ref/k/killtimer. Last Modified: December 17.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi.html (3 of 3) [9/1/2002 5:34:24 PM] . 500. 1) End Sub See Also SetTimer Category Timers Back to the Function list. 1.html http://216.168.

Example: ' Draw a red line from (0. Dim pt As POINT_TYPE ' needed for another API function Dim retval As Long ' return value Form1. Copyright Information.com | www. or 1 if successful. 50) ' draw a line from current point to (100.92/vbapi/ref/l/lineto.com Send Encrypted E-Mail This page is at http://www. E-mail: vbapi@vbapi. Win NT LineTo draws a line from the current point to the point specified on a device. This page is copyright © 2000 Paul Kuliniewicz.vbworld.dll" (ByVal hdc As Long.com | LineTo Function Declare Function LineTo Lib "gdi32. Go back to the Reference section index. PolylineTo. 40. The algorithm Windows uses to draw a line does not actually color the last pixel of the line because it is not considered part of the line.ForeColor = RGB(255. Go back to the Windows API Guide home page.vbforums. Win 95/98. ByVal y As Long) As Long Platforms: Win 32s.vbsquare.html [9/1/2002 5:34:28 PM] .vbapi.hdc.com/ref/l/lineto. The function returns 0 if an error occured.26. hdc The device context of the device to draw on.40) retval = LineTo(Form1. ByVal x As Long.Windows API Guide: LineTo Function vbapi. 100. After the line is drawn.vbapi. x The x coordinate of the endpoint to draw to. the endpoint is the new current point.50) on the window Form1.com | www. y The y coordinate of the endpoint to draw to.50) See Also: Polyline.168.40) to (100.vbshop.com .com | www. The line is drawn in the color specified by that object's .part of the VB-World Network | www. 0) ' set the foreground drawing color of Form1 to red retval = MoveToEx(Form1. 0. PolyPolyline Category: Lines & Curves Go back to the alphabetical Function listing.ForeColor property.com | www.html http://216.hdc. 0. pt) ' set the current point to (0.

IDC_IBEAM = 32513 The I-shaped beam cursor (text editing cursor).vbapi.html (1 of 2) [9/1/2002 5:34:33 PM] . IDC_ARROW = 32512 The regular arrow pointer cursor.92/vbapi/ref/l/loadcursor. If unsuccessful.vbworld. the function returns 0.part of the VB-World Network | www.com | www. set this to the application's instance handle. If successful.168.com . IDC_SIZENESW = 32643 The double-pointed resize arrow pointing to the upper-right and lower-left. Win 95/98.dll" Alias "LoadCursorA" (ByVal hInstance As Long.Windows API Guide: LoadCursor Function vbapi. For Windows's cursors. Win NT LoadCursor loads a cursor from either a currently running program's cursor resources or Windows's cursor resources.com | www.vbforums. IDC_SIZENS = 32645 The double-pointed resize arrow pointing up and down. IDC_SIZEALL = 32646 The four-pointed resize/move arrow. set this to 0.com | www. To load one of Windows's cursor resources.vbshop.com | LoadCursor Function Declare Function LoadCursor Lib "user32. IDC_ICON = 32641 Win NT only: An empty cursor. IDC_SIZE = 32640 Win NT only: The four-pointed resize/move arrow. IDC_CROSS = 32515 The cross cursor. IDC_NO = 32648 The "no" symbol cursor (circle with a slash).vbsquare. the function returns a handle to the loaded cursor. exactly one of the following flags can be used to select the desired cursor resource: IDC_APPSTARTING = 32650 The application starting cursor (arrow and hourglass). ByVal lpCursorName As Any) As Long Platforms: Win 32s.26. or a numeric ID number identifying the resource.com | www. lpCursorName Either a string containing the name of the cursor resource to load. The cursor can be referenced either by its resource name or by its numeric resource ID number. IDC_SIZEWE = 32644 http://216. hInstance To load one of a program's cursor resources. IDC_SIZENWSE = 32642 The double-pointed resize arrow pointing to the upper-left and lower-right.

Dim hcursor As Long ' receives handle to application starting cursor Dim holdcursor As Long ' receives handle to previously used cursor Dim retval As Long ' throw-away return value Then hcursor = LoadCursor(0.Windows API Guide: LoadCursor Function The double-pointed resize arrow pointing left and right. E-mail: vbapi@vbapi.html http://216. IDC_UPARROW = 32516 The up-arrow cursor.26.168.com Send Encrypted E-Mail This page is at http://www. ' restore the old cursor (whatever it happens to be). The cursor resource is loaded from Windows. Go back to the Reference section index.com/ref/l/loadcursor. Go back to the Windows API Guide home page.92/vbapi/ref/l/loadcursor. This page is copyright © 2000 Paul Kuliniewicz. Copyright Information. IDC_WAIT = 32514 The wait cursor (hourglass). IDC_APPSTARTING) ' load Windows's application starting cursor holdcursor = SetCursor(hcursor) ' set it to the new cursor Sleep 3000 ' wait for 3 seconds retval = SetCursor(holdcursor) ' set it to the previous cursor See Also: LoadCursorFromFile Category: Cursor Go back to the alphabetical Function listing. Example: ' Display the application starting (arrow and hourglass) Windows ' cursor for three seconds.html (2 of 2) [9/1/2002 5:34:33 PM] .vbapi.

com . The cursor file can contain either a regular cursor (*.com | www.cur) or an animated cursor (*.com | www.com | www.vbapi.ani). the function returns 0.vbsquare.vbapi. Dim hcursor As Long ' receives handle to the loaded cursor Dim holdcursor As Long ' receives handle to the previously in use cursor Dim retval As Long ' throw-away return value hcursor = LoadCursorFromFile("C:\MyProg\custom. Go back to the Windows API Guide home page.cur or an *.com | www.com/ref/l/loadcursorfromfile.com Send Encrypted E-Mail This page is at http://www. lpFileName The filename of the cursor file to load.html [9/1/2002 5:34:37 PM] . This page is copyright © 2000 Paul Kuliniewicz.26.html http://216.vbshop.ani" and set it as ' the current cursor for three seconds.ani cursor file.part of the VB-World Network | www. Win 95/98.vbworld.vbforums. the function returns a cursor handle to the newly loaded cursor.168. This file can either be a *. E-mail: vbapi@vbapi.Windows API Guide: LoadCursorFromFile Function vbapi. Go back to the Reference section index. Example: ' Load the cursor "C:\MyProg\custom.ani") ' load the animated cursor from the file If hcursor = 0 Then End ' abort program if cursor couldn't be loaded holdcursor = SetCursor(hcursor) ' set the loaded cursor as the current cursor Sleep 3000 ' wait for three seconds retval = SetCursor(holdcursor) ' restore the previous cursor See Also: LoadCursor Category: Cursor Go back to the alphabetical Function listing. Then restore the original cursor as ' the current cursor. If successful.dll" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long Platforms: Win 32s.com | LoadCursorFromFile Function Declare Function LoadCursorFromFile Lib "user32. Copyright Information.92/vbapi/ref/l/loadcursorfromfile. If unsuccessful. Win NT LoadCursorFromFile loads a cursor from a cursor file.

lpFileTime As FILETIME) As Long Platforms: Win 32s. lpFileTime Receives the time and date specified in lpLocalFileTime converted to UTC time.wSecond = 0 ' Convert sourcetime into FILETIME format: retval = SystemTimeToFileTime(sourcetime. The source and target times are stored in FILETIME format. 1999 6:10:00 PM local time ' to a FILETIME structure in UTC time.vbforums.com . Win NT LocalFileTimeToFileTime converts a time from local time (time according to the computer's current time zone) to UTC time (also known as Greenwich Mean Time). Dim sourcetime As SYSTEMTIME ' original time and date Dim localtime As FILETIME ' receives sourcetime's time Dim utctime As FILETIME ' receives the final result Dim retval As Long ' return value ' Set sourcetime to the desired date: sourcetime.168. Example: ' Convert the time and date May 1.dll" (lpLocalFileTime As FILETIME.wDay = 1: sourcetime.vb-shop. utctime) ' utctime now has the converted time and date http://216.wYear = 1999 sourcetime.vbworld.wMinute = 10: sourcetime.part of the VB-World Network | www.com | www. lpLocalFileTime The time and date in local time to convert. The function returns 1 if successful.com | www.Windows API Guide: LocalFileTimeToFileTime Function vbapi. Win 95/98.92/vbapi/ref/l/localfiletimetofiletime.wMonth = 5: sourcetime.html (1 of 2) [9/1/2002 5:34:41 PM] . or 0 if an error occured.vbapi.vbsquare.com | www.com | www.wHour = 18: sourcetime.26. localtime) ' Convert localtime into UTC time: retval = LocalFileTimeToFileTime(localtime.com | LocalFileTimeToFileTime Function Declare Function LocalFileTimeToFileTime Lib "kernel32.

92/vbapi/ref/l/localfiletimetofiletime. Go back to the Windows API Guide home page.html http://216.Windows API Guide: LocalFileTimeToFileTime Function See Also: FileTimeToLocalFileTime Category: Time Go back to the alphabetical Function listing. Copyright Information. E-mail: vbapi@vbapi.168.com Send Encrypted E-Mail This page is at http://www. Go back to the Reference section index.vbapi. This page is copyright © 2000 Paul Kuliniewicz.26.com/ref/l/localfiletimetofiletime.html (2 of 2) [9/1/2002 5:34:41 PM] .

26. Windows CE: Not Supported.com | www.vbsquare. Windows 2000: Supported. Description & Usage LockWorkStation locks the computer.http://216. preventing anybody from entering input until either the user who locked it or an administrator enters his or her password.92/vbapi/ref/l/lockworkstation.dll" () As Long Platforms q q q q q Windows 95: Not Supported.html (1 of 2) [9/1/2002 5:34:46 PM] .html vbapi.vbworld. the function returns zero (use GetLastError to get the error code). Visual Basic-Specific Issues None." Return Value If successful.168.92/vbapi/ref/l/lockworkstation. Windows 98: Not Supported.com .com | LockWorkStation Function Declare Function LockWorkStation Lib "user32.vbforums. Windows NT: Not Supported. the function returns a non-zero value. Example http://216.26. This function does the same thing as though the user had pressed Ctrl+Alt+Del and selected "Lock Workstation.com | www. Parameters None. If an error occured.com | www.vbapi.com | www.168.part of the VB-World Network | www.vb-shop.

) Public Declare Function LockWorkStation Lib "user32.168. 2000 This page is copyright © 2000 Paul Kuliniewicz. to use this example.dll" () As Long ' *** Place the following code inside the form window.vbapi.92/vbapi/ref/l/lockworkstation.html (2 of 2) [9/1/2002 5:34:46 PM] . ' This code is licensed according to the terms and conditions listed here.26.168. you must place a command button named cmdLock on a form window. Back to the Reference section. Copyright Information Revised October 29. E-mail: vbapi@vbapi. Obviously. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. Dim retval As Long ' return value retval = LockWorkStation() ' That's all there is to it! End Sub Category Shutdown Back to the Function list. 2000 Go back to the Windows API Guide home page.26.com/ref/l/lockworkstation. *** Private Sub cmdLock_Click () ' Lock the workstation when this button is clicked.92/vbapi/ref/l/lockworkstation. Last Modified: December 17.html http://216.http://216.com Send Encrypted E-Mail This page is at http://www.html Lock the workstation when the user clicks the command button named cmdLock.

which places all symbols except hyphens and apostrophes before the letter "a" (hyphens and apostrophes are treated differently).com | www. ByVal lpString2 As String) As Long Platforms q q q q q Windows 95: Supported.168. Windows 2000: Supported.com | www. the first string is greater than the second string. In any case.dll" Alias "lstrcmpA" (ByVal lpString1 As String.1 or later.com | www. Windows NT: Requires Windows NT 3.com | lstrcmp Function Declare Function lstrcmp Lib "kernel32. then the second character. Return Value If the function returns a negative value.com | www. Windows CE: Not Supported.vbforums. The strings are compared by comparing the first character of each string. If the function returns a positive value. the actual return value is the difference of the first unequal characters encountered.Windows API Guide: lstrcmp Function vbapi.vbsquare. the first string is less than the second string (i.vbworld.part of the VB-World Network | www.com .vbapi. the two strings are equal. the first string comes before the second string in alphabetical order).vb-shop. until unequal characters are encountered. Parameters lpString1 http://216. Description & Usage lstrcmp compares two strings using a case-sensitive comparison based on the current user locale.26. Windows 98: Supported. The function uses a word sort method.e..html (1 of 3) [9/1/2002 5:34:51 PM] .. If the function returns 0. Visual Basic-Specific Issues None. etc.92/vbapi/ref/l/lstrcmp.

swap them. If compval > 0 Then tempstr = words(oc) words(oc) = words(ic) words(ic) = tempstr End If Next ic Next oc ' Display the list of sorted words.html (2 of 3) [9/1/2002 5:34:51 PM] . they are switched. if a pair is out of alphabetical order. ' Use a case-senitive comparison method to alphabetically sort ' nine words.Print words(oc) Next oc http://216. words(ic)) ' If words(oc) is greater. "can't" "cant" "cannot" "pants" "co-op" "coop" "Denver" "denver" "denveR" ' Sort the strings. For oc = 1 To 8 ' first string of the pair For ic = oc + 1 To 9 ' second string of the pair ' Compare the two strings.26.168.92/vbapi/ref/l/lstrcmp. swapping any pairs which are out of order. For oc = 1 To 9 Debug. ic As Integer ' counter variables Dim compval As Long ' result of comparison ' Load the words(1) = words(2) = words(3) = words(4) = words(5) = words(6) = words(7) = words(8) = words(9) = nine strings into the array. compval = lstrcmp(words(oc). lpString2 The second string to compare.Windows API Guide: lstrcmp Function The first string to compare. Dim words(1 To 9) As String ' the words to sort Dim tempstr As String ' buffer used to swap strings Dim oc As Integer. The sorting method simply compares each possible pair ' of words. Example ' This code is licensed according to the terms and conditions listed here.

1999 This page is copyright © 1999 Paul Kuliniewicz.26. lstrcmpi Category Strings Go back to the alphabetical Function listing. Last Modified: December 30.html (3 of 3) [9/1/2002 5:34:51 PM] .vbapi.com/ref/l/lstrcmp. 2000 Go back to the Windows API Guide home page.92/vbapi/ref/l/lstrcmp. Go back to the Reference section index. Copyright Information Revised October 29.com Send Encrypted E-Mail This page is at http://www.168.html http://216.Windows API Guide: lstrcmp Function See Also CompareString. E-mail: vbapi@vbapi.

the first string comes before the second string in alphabetical order).com | www. The function uses a word sort method.1 or later.vbsquare. Windows 2000: Supported.html (1 of 3) [9/1/2002 5:34:55 PM] .168.com | www. The strings are compared by comparing the first character of each string. until unequal characters are encountered.dll" Alias "lstrcmpiA" (ByVal lpString1 As String.. Windows CE: Not Supported. the first string is less than the second string (i.vbworld. the first string is greater than the second string.com .com | www.26.vb-shop.vbapi. then the second character.e.. Windows 98: Supported. Return Value If the function returns a negative value.part of the VB-World Network | www. etc.vbforums.Windows API Guide: lstrcmpi Function vbapi. Description & Usage lstrcmpi compares two strings using a case-insensitive comparison based on the current user locale. In any case.com | www. Windows NT: Requires Windows NT 3. If the function returns 0.com | lstrcmpi Function Declare Function lstrcmpi Lib "kernel32. Parameters lpString1 http://216. which places all symbols except hyphens and apostrophes before the letter "a" (hyphens and apostrophes are treated differently). the actual return value is the difference of the first unequal characters encountered.92/vbapi/ref/l/lstrcmpi. If the function returns a positive value. Visual Basic-Specific Issues None. ByVal lpString2 As String) As Long Platforms q q q q q Windows 95: Supported. the two strings are equal.

26. depending on how the search loops play out -' the three strings are equal in the eyes of the function and therefore ' not sorted relative to each other.html (2 of 3) [9/1/2002 5:34:55 PM] . If compval > 0 Then tempstr = words(oc) words(oc) = words(ic) words(ic) = tempstr End If Next ic Next oc http://216. For oc = 1 To 8 ' first string of the pair For ic = oc + 1 To 9 ' second string of the pair ' Compare the two strings.92/vbapi/ref/l/lstrcmpi. Example ' This code is licensed according to the terms and conditions listed here. ic As Integer ' counter variables Dim compval As Long ' result of comparison ' Load the words(1) = words(2) = words(3) = words(4) = words(5) = words(6) = words(7) = words(8) = words(9) = nine strings into the array.168. lpString2 The second string to compare. swap them. swapping any pairs which are out of order. they are switched. if a pair is out of alphabetical order. ' Use a case-insenitive comparison method to alphabetically sort ' nine words. The sorting method simply compares each possible pair ' of words. "can't" "cant" "cannot" "pants" "co-op" "coop" "Denver" "denver" "denveR" ' Sort the strings. compval = lstrcmpi(words(oc).Windows API Guide: lstrcmpi Function The first string to compare. ' (Note how this sort will seemingly arrange the "Denver" trio in ' a random order. words(ic)) ' If words(oc) is greater.) Dim words(1 To 9) As String ' the words to sort Dim tempstr As String ' buffer used to swap strings Dim oc As Integer.

html http://216. E-mail: vbapi@vbapi.Print words(oc) Next oc See Also CompareString.vbapi.26. 2000 Go back to the Windows API Guide home page. lstrcmp Category Strings Go back to the alphabetical Function listing. 1999 This page is copyright © 1999 Paul Kuliniewicz. For oc = 1 To 9 Debug. Go back to the Reference section index.com/ref/l/lstrcmpi.com Send Encrypted E-Mail This page is at http://www.html (3 of 3) [9/1/2002 5:34:55 PM] .Windows API Guide: lstrcmpi Function ' Display the list of sorted words.168. Copyright Information Revised October 29.92/vbapi/ref/l/lstrcmpi. Last Modified: December 30.

vbapi.1 or later. Windows CE: Not Supported.168. instead of being a "real" string. Windows 98: Supported. Description & Usage lstrcpy copies the entire contents of one string into another string.92/vbapi/ref/l/lstrcpy.com . can also be merely a pointer to a string instead. the function returns a non-zero value. Windows 2000: Supported.vbforums.vbshop. If successful. lpString2 Either an actual string to copy into lpString1 or a pointer to the string to copy into lpString1.Windows API Guide: lstrcpy Function vbapi.vbsquare. Visual Basic-Specific Issues This function is very useful for "converting" a pointer to a string into an actual string.com | lstrcpy Function Declare Function lstrcpy Lib "kernel32. ByVal lpString2 As Any) As Long Platforms q q q q q Windows 95: Supported. Return Value If an error occured. This could be either the string itself or a pointer to the string. http://216.com | www. The target string must already have enough space to receive the source string's contents. Parameters lpString1 String that receives the copied contents of lpString2. The function also will copy a terminating null character into the target string.vbworld. Either string.com | www.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.com | www.com | www.part of the VB-World Network | www. Windows NT: Requires Windows NT 3.html (1 of 2) [9/1/2002 5:35:04 PM] .26. the function returns 0 (use GetLastError to get the error code).

html (2 of 2) [9/1/2002 5:35:04 PM] .Print "Target string: ". world!" ' the source string to copy target = Space(Len(source)) ' make room in target to receive the copied string retval = lstrcpy(target.. target ' they should be the same. source Debug. target As String ' the two strings Dim retval As Long ' return value source = "Hello.html http://216. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.26.com/ref/l/lstrcpy..vbapi.168. source) ' set target to equal source Debug. See Also lstrcpyn Category Strings Go back to the alphabetical Function listing. Go back to the Reference section index.Windows API Guide: lstrcpy Function Example ' This code is licensed according to the terms and conditions listed here.Print "Source string: ". 1999 This page is copyright © 1999 Paul Kuliniewicz. E-mail: vbapi@vbapi. ' Copy the source string to the target string Dim source As String.92/vbapi/ref/l/lstrcpy.. Last Modified: December 22. Copyright Information Revised October 29.

This could be either the string itself or a pointer to the string.part of the VB-World Network | www.com | www. Parameters lpString1 String that receives the copied contents of lpString2.168. Description & Usage lstrcpy copies one or more characters from one string into another string. Return Value If an error occured.com | lstrcpy Function Declare Function lstrcpyn Lib "kernel32.vbworld. Windows CE: Not Supported.vbshop.1 or later.com | www. Windows 98: Supported.com .vbforums. Either string.Windows API Guide: lstrcpyn Function vbapi. the function returns 0 (use GetLastError to get the error code).vbsquare.com | www. ByVal lpString2 As Any.html (1 of 2) [9/1/2002 5:35:14 PM] .92/vbapi/ref/l/lstrcpyn. Windows NT: Requires Windows NT 3. ByVal iMaxLength As Long) As Long Platforms q q q q q Windows 95: Supported. followed by a terminating null character. can also be merely a pointer to a string instead.vbapi. Visual Basic-Specific Issues This function is very useful for "converting" a pointer to a string into an actual string. If successful.dll" Alias "lstrcpynA" (ByVal lpString1 As Any. The target string must already have enough space to receive the source string's contents along with the terminating null.com | www. lpString2 Either an actual string to copy into lpString1 or a pointer to the string to copy into lpString1.26. the function returns a non-zero value. instead of being a "real" string. Windows 2000: Supported. iMaxLength http://216.

com Send Encrypted E-Mail This page is at http://www.26.Print "Source string: ". (For example. Example ' This code is licensed according to the terms and conditions listed here. E-mail: vbapi@vbapi.com/ref/l/lstrcpyn. 6) ' set target to equal source target = Left(target. target ' this should be "Hello" See Also lstrcpy Category Strings Go back to the alphabetical Function listing.Print "Target string: ".Windows API Guide: lstrcpyn Function The number of characters to copy from lpString2 to lpString1.1) ' remove the terminating null character Debug. Go back to the Reference section index. including the terminating null character added to the end.html (2 of 2) [9/1/2002 5:35:14 PM] . source. world!" ' the source string to copy target = Space(6) ' make room in target to receive the copied string retval = lstrcpy(target. source Debug.92/vbapi/ref/l/lstrcpyn. 1999 This page is copyright © 1999 Paul Kuliniewicz. Len(target) . target As String ' the two strings Dim retval As Long ' return value source = "Hello. Last Modified: December 26. ' Copy the first word source string to the target string Dim source As String. Copyright Information Revised October 29. a value of 4 for this parameter would copy three characters from lpString2 and a null character into lpString1.vbapi.html http://216.168. 2000 Go back to the Windows API Guide home page.

The length of a string is considered to be the number of characters it contains. This function can also determine the length of a string to which a pointer refers.part of the VB-World Network | www. Return Value The function returns the length of the string.com | www.com | lstrlen Function Declare Function lstrlen Lib "kernel32. measured in number of characters. Windows 2000: Supported.vbforums. for "converting" a pointer to a string into an actual string.vb-shop. http://216. in conjunction with lstrcpy. not counting any possible terminating null character. Windows NT: Requires Windows NT 3.com | www. Windows CE: Not Supported. Parameters lpString Either the string to determine the length of or a pointer to the string to determine the length of.Windows API Guide: lstrlen Function vbapi.com | www. Windows 98: Supported.vbapi.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Platforms q q q q q Windows 95: Supported.168.com .com | www. Description & Usage lstrlen determines the length of a string.vbworld. Visual Basic-Specific Issues This function is very useful.92/vbapi/ref/l/lstrlen.26.vbsquare.1 or later.html (1 of 2) [9/1/2002 5:35:18 PM] .

com Send Encrypted E-Mail This page is at http://www.vbapi. world!' contains". world!") ' find the length of the string Debug.html (2 of 2) [9/1/2002 5:35:18 PM] . Copyright Information Revised October 29. E-mail: vbapi@vbapi. 1999 This page is copyright © 1999 Paul Kuliniewicz. ' Display the length of the string "Hello. Go back to the Reference section index. world!" Dim slength As Long ' receives the length of the string slength = lstrlen("Hello.html http://216.92/vbapi/ref/l/lstrlen. "characters.com/ref/l/lstrlen.26. slength.168.Windows API Guide: lstrlen Function Example ' This code is licensed according to the terms and conditions listed here." Category Strings Go back to the alphabetical Function listing.Print "The string 'Hello. Last Modified: December 21. 2000 Go back to the Windows API Guide home page.

Description & Usage mciGetErrorString obtains a textual description of an error raised by another Media Control Interface (MCI) function.Windows API Guide: mciGetErrorString Function vbapi. Return Value If successful.com | www.html (1 of 3) [9/1/2002 5:35:24 PM] .com | www. Windows 2000: Supported.com . Parameters fdwError A MCI error code returned by another MCI function. If an error occured. This string must already contain enough room to receive the text. ByVal lpszErrorText As String. Visual Basic-Specific Issues None. Rather.vbworld.com | www. Windows CE: Not Supported. they are caused by "problems" with the device (for example. ByVal cchErrorText As Long) As Long Platforms q q q q q Windows 95: Supported. the function returns 0. Example http://216.168.26. Windows 98: Supported.dll" Alias "mciGetErrorStringA" (ByVal fdwError As Long. the function returns a nonzero value. lpszErrorText A string that receives a textual description of the error terminated by a null character.com | mciSendString Function Declare Function mciGetErrorString Lib "winmm.vbsquare.92/vbapi/ref/m/mcigeterrorstring.vbforums. so your program's attempt to open it failed). Typically these errors are not the fault of the program. This string should be at least 128 characters long. the MIDI driver is currently being used by another program.part of the VB-World Network | www. Windows NT: Requires Windows NT 3. mciGetErrorString gets a description of this error. cchErrorText The length of the string passed as lpszErrorText.vbshop. The messages retrieved by this function are sufficient to tell the user what caused the error.vbapi.com | www.1 or later.

0. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.168. The file C:\Music\canyon. 0. 0) If errcode <> 0 Then DisplayError errcode End Sub Private Sub cmdPlay_Click() ' Begin playback of the MIDI file when this button is pressed. name the other one "cmdStop" and set its Caption to "&Stop MIDI File". ByVal lpszReturnString As String. Private Sub Form_Load() ' Open the file "C:\Music\canyon.dll" Alias "mciSendStringA" (ByVal _ lpszCommand As String.Windows API Guide: mciGetErrorString Function To run this code. 0) If errcode <> 0 Then DisplayError errcode End Sub Private Sub cmdStop_Click() ' Stop playback of the MIDI file when this button is pressed. it ' behaves just as pausing playback would. ' Give it an alias of "canyon" so we don't need to refer to the filename again. Likewise. ' The position within the file does not move back to the beginning. The file closes when the form unloads. ByVal hwndCallback As Long) As Long Public Declare Function mciGetErrorString Lib "winmm. Dim errcode As Long ' MCI error code errcode = mciSendString("open C:\Music\canyon.dll" Alias "mciGetErrorStringA" (ByVal _ fdwError As Long. Name one "cmdPlay" and set its Caption to "&Play MIDI File". ByVal cchErrorText As Long) As Long ' Use the MCI to play or stop playback of a MIDI file.) Public Declare Function mciSendString Lib "winmm. Dim errcode As Long ' MCI error code errcode = mciSendString("play canyon".26. ' If anything goes wrong in the example. place two command buttons on a form window. 0. The Play and Stop buttons behave as you'd expect. ByVal lpszErrorText As String.mid alias canyon". The ' only potential surprise is that the current position is not reset when playback stops. "".mid" for later use in the example. ByVal cchReturnLength _ As Long. "".92/vbapi/ref/m/mcigeterrorstring. 0) If errcode <> 0 Then DisplayError errcode End Sub http://216. ' This code is licensed according to the terms and conditions listed here. Dim errcode As Long ' MCI error code errcode = mciSendString("stop canyon".html (2 of 3) [9/1/2002 5:35:24 PM] . display a message box with ' the MCI error message text. "".mid ' is opened when the form opens.

html (3 of 3) [9/1/2002 5:35:24 PM] .92/vbapi/ref/m/mcigeterrorstring.Windows API Guide: mciGetErrorString Function Private Sub Form_Unload(Cancel As Integer) ' Close the MIDI file when the form unloads.html http://216. Dim errstr As String ' MCI error message text Dim retval As Long ' return value ' Get a string explaining the MCI error. E-mail: vbapi@vbapi. errstr = Space(128) retval = mciGetErrorString(errcode. There's no need to check ' for an error here. "". VB's MsgBox function will suffice. This is important.com/ref/m/mcigeterrorstring. errstr. vbNullChar) . 0) End Sub Private Sub DisplayError(ByVal errcode As Long) ' This subroutine displays a dialog box with the text of the MCI error. There's ' no reason to use the MessageBox API function. 0.26. Back to the Reference section. 2000 Go back to the Windows API Guide home page. since we're just closing the file. InStr(errstr.vbapi. vbOKOnly Or vbCritical) End Sub See Also mciSendString Category Media Control Interface (MCI) Back to the Function list. errstr = Left(errstr.1) ' Display a simple error message box. Last Modified: July 4. 2000 This page is copyright © 2000 Paul Kuliniewicz. because the ' MIDI driver can only work with one file at a time. retval = MsgBox(errstr.com Send Encrypted E-Mail This page is at http://www. Dim errcode As Long ' MCI error code errcode = mciSendString("close canyon". Len(errstr)) ' Remove the terminating null and empty space at the end. Copyright Information Revised October 29.168.

mciSendString provides a relatively easy way to perform multimedia output operations. Look at the MCI command strings page for a list of some of the command strings used by the mciSendString function. Windows NT: Requires Windows NT 3. This string must initially be at least 128 characters long in order to receive the string. Any information placed into this string will be nullterminated.vbsquare. Windows 2000: Supported. cchReturn http://216. ByVal lpszReturnString As String.com | www. If the command string does not return any information. including all of its necessary parameters and desired options.com | www. Description & Usage mciSendString sends a command to a Multimedia Control Interface (MCI) device. Windows 98: Supported. The command strings used with this function can perform almost any task necessary for using a multimedia device installed on the computer. To get a textual description of the error. ByVal hwndCallback As Long) As Long Platforms q q q q q Windows 95: Supported.Windows API Guide: mciSendString Function vbapi. Return Value If successful.com | www. Visual Basic-Specific Issues None. If an error occured. ByVal cchReturnLength As Long.com .1 or later. this string receives the data output by the command. the function returns 0.part of the VB-World Network | www.com | mciSendString Function Declare Function mciSendString Lib "winmm.vbapi.26. use the mciGetErrorString function.168.html (1 of 4) [9/1/2002 5:35:30 PM] . Parameters lpszCommand The command string to execute.vbforums.com | www.dll" Alias "mciSendStringA" (ByVal lpszCommand As String. Windows CE: Not Supported.vbworld. this parameter is ignored. lpszReturnString For command strings that return information. the function returns a nonzero MCI error code.vbshop.92/vbapi/ref/m/mcisendstring.

place two command buttons on a form window. ByVal hwndCallback As Long) As Long Public Declare Function mciGetErrorString Lib "winmm.92/vbapi/ref/m/mcisendstring.) Public Declare Function mciSendString Lib "winmm. ByVal cchReturnLength _ As Long. Likewise.mid alias canyon". ByVal cchErrorText As Long) As Long ' Use the MCI to play or stop playback of a MIDI file. The Play and Stop buttons behave as you'd expect. The ' only potential surprise is that the current position is not reset when playback stops.dll" Alias "mciSendStringA" (ByVal _ lpszCommand As String. 0) If errcode <> 0 Then DisplayError errcode End Sub Private Sub cmdStop_Click() http://216. it ' behaves just as pausing playback would.mid" for later use in the example.dll" Alias "mciGetErrorStringA" (ByVal _ fdwError As Long. display a message box with ' the MCI error message text.168. The file C:\Music\canyon. The file closes when the form unloads.26. "". name the other one "cmdStop" and set its Caption to "&Stop MIDI File". this is a handle to the window to receive a MM_MCINOTIFY message when the command has completed.Windows API Guide: mciSendString Function The length of the string passed as lpszReturnString.mid ' is opened when the form opens. ' This code is licensed according to the terms and conditions listed here. Private Sub Form_Load() ' Open the file "C:\Music\canyon. Dim errcode As Long ' MCI error code errcode = mciSendString("open C:\Music\canyon. Example To run this code. ' If anything goes wrong in the example. no matter whether it succeeded or failed. 0. 0. 0) If errcode <> 0 Then DisplayError errcode End Sub Private Sub cmdPlay_Click() ' Begin playback of the MIDI file when this button is pressed.html (2 of 4) [9/1/2002 5:35:30 PM] . Dim errcode As Long ' MCI error code errcode = mciSendString("play canyon". ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. ' Give it an alias of "canyon" so we don't need to refer to the filename again. hwndCallback If the "notify" flag of the command string is specified. ByVal lpszReturnString As String. "". ByVal lpszErrorText As String. Name one "cmdPlay" and set its Caption to "&Play MIDI File".

There's no need to check ' for an error here. errstr = Left(errstr. Last Modified: July 4. since we're just closing the file.1) ' Display a simple error message box.168. 0) End Sub Private Sub DisplayError(ByVal errcode As Long) ' This subroutine displays a dialog box with the text of the MCI error. 0. This is important. "".92/vbapi/ref/m/mcisendstring. errstr. 0. retval = MsgBox(errstr. errstr = Space(128) retval = mciGetErrorString(errcode.Windows API Guide: mciSendString Function ' Stop playback of the MIDI file when this button is pressed. InStr(errstr. There's ' no reason to use the MessageBox API function. because the ' MIDI driver can only work with one file at a time. "". VB's MsgBox function will suffice. Dim errcode As Long ' MCI error code errcode = mciSendString("close canyon". 2000 http://216. Dim errstr As String ' MCI error message text Dim retval As Long ' return value ' Get a string explaining the MCI error. Len(errstr)) ' Remove the terminating null and empty space at the end. ' The position within the file does not move back to the beginning. 0) If errcode <> 0 Then DisplayError errcode End Sub Private Sub Form_Unload(Cancel As Integer) ' Close the MIDI file when the form unloads. Back to the Reference section. vbOKOnly Or vbCritical) End Sub See Also mciGetErrorString Category Media Control Interface (MCI) Back to the Function list. Dim errcode As Long ' MCI error code errcode = mciSendString("stop canyon".html (3 of 4) [9/1/2002 5:35:30 PM] .26. vbNullChar) .

2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.html http://216. Copyright Information Revised October 29.Windows API Guide: mciSendString Function This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/m/mcisendstring.26.com/ref/m/mcisendstring. E-mail: vbapi@vbapi.168.html (4 of 4) [9/1/2002 5:35:30 PM] .vbapi.

plays a beep using the computer's internal speaker. this is exactly one of the following flags specifying which sound to play: MB_ICONASTERISK = &H40 Play the SystemAsterisk sound. with one exception.com | www.part of the VB-World Network | www. MB_ICONHAND = &H10 Play the SystemHand sound. Example: ' Play the SystemQuestion sound.Windows API Guide: MessageBeep Function vbapi.vbforums. MB_ICONQUESTION = &H20 Play the SystemQuestion sound. or 0 if an error occured. wType If set to -1 (or &HFFFFFFFF). MB_OK = &H0 Play the SystemDefault sound.92/vbapi/ref/m/messagebeep. this function can also play a beep on the computer's internal speaker. Otherwise. MB_ICONEXCLAMATION = &H30 Play the SystemExclamation sound.com | www.com | www. Win 95/98.dll" (ByVal wType As Long) As Long Platforms: Win 32s.html (1 of 2) [9/1/2002 5:35:34 PM] . However.vb-shop.vbapi. Win NT MessageBeep plays one of the system's associated sounds.vbworld.26. Dim retval As Long ' return value retval = MessageBeep(MB_ICONQUESTION) See Also: Beep Category: Errors ' play the SystemQuestion sound http://216.vbsquare.168.com | MessageBeep Function Declare Function MessageBeep Lib "user32.com | www.com . The function returns 1 if successful. These sounds are some of the ones that Windows associates with certain events.

com/ref/m/messagebeep.com Send Encrypted E-Mail This page is at http://www.168. Copyright Information.26. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:35:34 PM] . Go back to the Reference section index.html http://216.Windows API Guide: MessageBeep Function Go back to the alphabetical Function listing.vbapi. Go back to the Windows API Guide home page. This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/m/messagebeep.

vbforums. Windows 2000: Supported.com | www.vbshop.com | MessageBox Function Declare Function MessageBox Lib "user32. the function returns one of the following flags specifying the button the user clicked on: IDABORT The Abort button was clicked.com | www. the function returns 0 (use GetLastError to get the error code). IDIGNORE The Ignore button was clicked. ByVal lpCaption As String. Message boxes are typically used either to communicate important information (such as an error message) or to prompt the user. Description & Usage MessageBox opens and operates a small message box on the screen. IDRETRY The Retry button was clicked.html (1 of 5) [9/1/2002 5:35:42 PM] .168.92/vbapi/ref/m/messagebox. ByVal uType As Long) As Long Platforms q q q q q Windows 95: Supported.vbapi. The message box only closes when the user presses one of the buttons presented.part of the VB-World Network | www.26.0 or later. IDTRYAGAIN http://216. Windows NT: Requires Windows NT 3.Windows API Guide: MessageBox Function vbapi. IDNO The No button was clicked.dll" Alias "MessageBoxA" (ByVal hWnd As Long. ByVal lpText As String. Windows 98: Supported. IDCONTINUE Windows 2000: The Continue button was clicked. IDCANCEL The Cancel button was clicked (or the user dismissed the message box using the Esc key). IDOK The OK button was clicked.com . Return Value If an error occured.com | www. If successful.com | www. Windows CE: Requires Windows CE 1.1 or later.vbworld.vbsquare.

e. Use one of the following flags to specify which buttons to display in the message box. MB_OK The message box contains the OK button. the Help button cannot appear alone). MB_HELP Windows 95. When the user clicks the Help button. The available flags are grouped according to function. MB_ICONSTOP Display the stop-sign icon in the message box.) MB_ABORTRETRYIGNORE The message box contains the Abort. MB_ICONINFORMATION Display the information icon: a lowercase letter "i" inside a blue circle. Try Again. If no flags in a certain group are specified. http://216. This is the default.168. and Cancel buttons. 98. Retry. Use one of the following flags to specify which icon to display in the message box: MB_ICONASTERISK. NT 4. lpCaption The text to display inside the caption area of the message box's title bar. uType A combination of various flags specifying the behavior and appearance of the message box. MB_OKCANCEL The message box contains the OK and Cancel buttons. Visual Basic-Specific Issues None.. This flag can only be used by combining it with another button flag (i.26.Windows API Guide: MessageBox Function Windows 2000: The Try Again button was clicked. MB_ICONHAND. IDYES The Yes button was clicked. MB_RETRYCANCEL The message box contains the Retry and Cancel buttons.0 or later. the WM_HELP message is sent to the owner of the message box (specified by the hWnd parameter). This is meant to replace the MB_ABORTRETRYIGNORE flag. MB_ICONERROR. the default is used. No. (Note that MB_HELP can be combined with any of the other flags. MB_YESNOCANCEL The message box contains the Yes.92/vbapi/ref/m/messagebox.html (2 of 5) [9/1/2002 5:35:42 PM] . 2000: Add the Help button to the message box. MB_YESNO The message box contains the Yes and No buttons. lpText The text to display inside the message box. and Continue buttons. Parameters hWnd A handle to the window opening the message box. and Ignore buttons. MB_CANCELTRYCONTINUE Windows 2000: The message box contains the Cancel.

92/vbapi/ref/m/messagebox. The user cannot switch to any other windows owned by the calling thread until he or she first closes the message box.0. MB_SYSTEMMODAL The message box is system-modal.51: Same as MB_SERVICE_NOTIFICATION. MB_ICONWARNING Display the exclamation-point icon in the message box. The user cannot switch to any other windows until he or she first closes the message box. MB_DEFBUTTON2 The second button is the default. This is the default. MB_SERVICE_NOTIFICATION_NT3X Windows NT 3. Constant Definitions Const IDABORT = 3 Const IDCANCEL = 2 Const IDCONTINUE = 5 http://216. Use zero or more of the following flags to specify other options for the message box: MB_DEFAULT_DESKTOP_ONLY Windows NT. 2000: Same as MB_SERVICE_NOTIFICATION. The value of this flag changed with the release of NT 4.168.0 or later. Use one of the following flags to specify which button is selected by default: MB_DEFBUTTON1 The first button is the default. MB_DEFBUTTON4 The fourth button is the default. Use one of the following flags to specify the modality of the message box: MB_APPLMODAL The message box is application-modal. 2000: The calling thread is a service notifying the user of an event. MB_SERVICE_NOTIFICATION Windows NT 4. MB_TOPMOST Make the message box a topmost window. except that the system will display the message box only on the interactive window station's default desktop. MB_RIGHT The text in the message box is right-justified. MB_ICONQUESTION Display the question-mark icon in the message box.26. MB_TASKMODAL The message box is thread-modal. The user cannot switch to any other windows owned by the application until he or she first closes the message box. This is the default.1 through 3. MB_SETFOREGROUND Make the message box the foreground window. MB_DEFBUTTON3 The third button is the default. MB_RTLREADING Display the message text and caption using right-to-left reading order if desired by the system language.html (3 of 5) [9/1/2002 5:35:42 PM] .Windows API Guide: MessageBox Function MB_ICONEXCLAMATION. The hWnd parameter must be 0.

92/vbapi/ref/m/messagebox.html (4 of 5) [9/1/2002 5:35:42 PM] . Have "No" selected by default. Make the message box system-modal to force the ' user to reply immediately. flags = MB_YESNO Or MB_ICONWARNING Or MB_DEFBUTTON2 Or MB_SYSTEMMODAL http://216. use a variable to represent the flag settings.Windows API Guide: MessageBox Function Const IDIGNORE = 5 Const IDNO = 7 Const IDOK = 1 Const IDRETRY = 4 Const IDTRYAGAIN = 4 Const IDYES = 6 Const MB_ABORTRETRYIGNORE = &H2 Const MB_CANCELTRYCONTINUE = &H2 Const MB_HELP = &H4000 Const MB_OK = &H0 Const MB_OKCANCEL = &H1 Const MB_RETRYCANCEL = &H5 Const MB_YESNO = &H4 Const MB_YESNOCANCEL = &H3 Const MB_ICONASTERISK = &H40 Const MB_ICONERROR = &H10 Const MB_ICONEXCLAMATION = &H30 Const MB_ICONHAND = &H10 Const MB_ICONINFORMATION = &H40 Const MB_ICONQUESTION = &H20 Const MB_ICONSTOP = &H10 Const MB_ICONWARNING = &H30 Const MB_DEFBUTTON1 = &H0 Const MB_DEFBUTTON2 = &H100 Const MB_DEFBUTTON3 = &H200 Const MB_DEFBUTTON4 = &H300 Const MB_APPLMODAL = &H0 Const MB_SYSTEMMODAL = &H1000 Const MB_TASKMODAL = &H2000 Const MB_DEFAULT_DESKTOP_ONLY = &H20000 Const MB_RIGHT = &H80000 Const MB_RTLREADING = &H100000 Const MB_SETFOREGROUND = &H10000 'Const MB_TOPMOST = ??? 'Const MB_SERVICE_NOTIFICATION = ??? 'Const MB_SERVICE_NOTIFICATION_NT3X = ??? Example ' This code is licensed according to the terms and conditions listed here. Dim mbresult As Long ' result of message box Dim flags As Long ' message box flags ' For convenience. ' Display a warning message box with the Yes and No option ' owned by window Form1.168.26.

"Warning!".Print "Operation aborted. Copyright Information Revised October 29.Windows API Guide: MessageBox Function ' Display the message box. mbresult = MessageBox(Form1." End If See Also MessageBoxEx.html (5 of 5) [9/1/2002 5:35:42 PM] . go ahead and do that. If mbresult = IDYES Then Debug.26. 2000 Go back to the Windows API Guide home page. "Are you sure you want to do that?". Back to the Reference section.com/ref/m/messagebox. 2000 This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/m/messagebox." Elseif mbresult = IDNO Then Debug.vbapi.html http://216. Last Modified: January 29. MessageBoxIndirect Category Dialog Boxes Back to the Function list.Print "OK.hWnd. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.168. flags) ' Determine what the user pressed.

Return Value If an error occured. IDIGNORE The Ignore button was clicked. Description & Usage MessageBoxEx opens and operates a small message box on the screen.com .vbsquare. ByVal wLanguageId As Long) As Long Platforms q q q q q Windows 95: Supported. IDCANCEL The Cancel button was clicked (or the user dismissed the message box using the Esc key).Windows API Guide: MessageBoxEx Function vbapi.92/vbapi/ref/m/messageboxex. The message box only closes when the user presses one of the buttons presented. Windows CE: Not Supported.part of the VB-World Network | www. ByVal lpCaption As String.1 or later. the function returns one of the following flags specifying the button the user clicked on: IDABORT The Abort button was clicked.com | www. IDOK The OK button was clicked.com | www. Windows 98: Supported. IDRETRY The Retry button was clicked.dll" Alias "MessageBoxExA" (ByVal hWnd As Long. the function returns 0 (use GetLastError to get the error code).vbapi.html (1 of 5) [9/1/2002 5:35:48 PM] . ByVal lpText As String. IDTRYAGAIN http://216. Windows 2000: Supported.vbworld.26.168.com | MessageBoxEx Function Declare Function MessageBoxEx Lib "user32. IDNO The No button was clicked. ByVal uType As Long. Windows NT: Requires Windows NT 3.com | www. IDCONTINUE Windows 2000: The Continue button was clicked.vbforums.com | www. If successful.vbshop. Message boxes are typically used either to communicate important information (such as an error message) or to prompt the user.

Retry. lpCaption The text to display inside the caption area of the message box's title bar. 2000: Add the Help button to the message box. NT 4. MB_CANCELTRYCONTINUE Windows 2000: The message box contains the Cancel. and Continue buttons. MB_ICONERROR.26. the WM_HELP message is sent to the owner of the message box (specified by the hWnd parameter). http://216. 98. (Note that MB_HELP can be combined with any of the other flags. MB_HELP Windows 95.92/vbapi/ref/m/messageboxex. IDYES The Yes button was clicked. This is the default.e. and Ignore buttons. Visual Basic-Specific Issues None.Windows API Guide: MessageBoxEx Function Windows 2000: The Try Again button was clicked. MB_YESNO The message box contains the Yes and No buttons.168. MB_OK The message box contains the OK button. This flag can only be used by combining it with another button flag (i. Use one of the following flags to specify which icon to display in the message box: MB_ICONASTERISK. Use one of the following flags to specify which buttons to display in the message box. MB_ICONSTOP Display the stop-sign icon in the message box. MB_RETRYCANCEL The message box contains the Retry and Cancel buttons. When the user clicks the Help button.html (2 of 5) [9/1/2002 5:35:48 PM] . If no flags in a certain group are specified.0 or later. lpText The text to display inside the message box.. MB_YESNOCANCEL The message box contains the Yes. the Help button cannot appear alone). Try Again. the default is used. uType A combination of various flags specifying the behavior and appearance of the message box. MB_ICONINFORMATION Display the information icon: a lowercase letter "i" inside a blue circle. MB_OKCANCEL The message box contains the OK and Cancel buttons. This is meant to replace the MB_ABORTRETRYIGNORE flag. and Cancel buttons. No. MB_ICONHAND. The available flags are grouped according to function. Parameters hWnd A handle to the window opening the message box.) MB_ABORTRETRYIGNORE The message box contains the Abort.

MB_SERVICE_NOTIFICATION_NT3X Windows NT 3. MB_ICONQUESTION Display the question-mark icon in the message box. Use zero or more of the following flags to specify other options for the message box: MB_DEFAULT_DESKTOP_ONLY Windows NT.26.51: Same as MB_SERVICE_NOTIFICATION.0. The hWnd parameter must be 0. created by MAKELANGID. MB_DEFBUTTON3 The third button is the default. 2000: The calling thread is a service notifying the user of an event. MB_RIGHT The text in the message box is right-justified. which identifies the language used to display the message box's buttons. MB_TOPMOST Make the message box a topmost window. The value of this flag changed with the release of NT 4. MB_DEFBUTTON2 The second button is the default. MB_RTLREADING Display the message text and caption using right-to-left reading order if desired by the system language.168. The user cannot switch to any other windows owned by the application until he or she first closes the message box. MB_ICONWARNING Display the exclamation-point icon in the message box. MB_SETFOREGROUND Make the message box the foreground window. The user cannot switch to any other windows until he or she first closes the message box. 2000: Same as MB_SERVICE_NOTIFICATION. The specified language must be installed on the system. This is the default.1 through 3.html (3 of 5) [9/1/2002 5:35:48 PM] . MB_DEFBUTTON4 The fourth button is the default. Constant Definitions http://216. wLanguageId A language identifier. The user cannot switch to any other windows owned by the calling thread until he or she first closes the message box. Use one of the following flags to specify which button is selected by default: MB_DEFBUTTON1 The first button is the default. MB_TASKMODAL The message box is thread-modal.92/vbapi/ref/m/messageboxex. except that the system will display the message box only on the interactive window station's default desktop. This is the default.Windows API Guide: MessageBoxEx Function MB_ICONEXCLAMATION. Use one of the following flags to specify the modality of the message box: MB_APPLMODAL The message box is application-modal.0 or later. MB_SYSTEMMODAL The message box is system-modal. MB_SERVICE_NOTIFICATION Windows NT 4.

Make the message box system-modal to force the ' user to reply immediately.26.html (4 of 5) [9/1/2002 5:35:48 PM] .92/vbapi/ref/m/messageboxex. and display ' the buttons in American English. Dim mbresult As Long ' result of message box http://216.Windows API Guide: MessageBoxEx Function Const IDABORT = 3 Const IDCANCEL = 2 Const IDCONTINUE = 5 Const IDIGNORE = 5 Const IDNO = 7 Const IDOK = 1 Const IDRETRY = 4 Const IDTRYAGAIN = 4 Const IDYES = 6 Const MB_ABORTRETRYIGNORE = &H2 Const MB_CANCELTRYCONTINUE = &H2 Const MB_HELP = &H4000 Const MB_OK = &H0 Const MB_OKCANCEL = &H1 Const MB_RETRYCANCEL = &H5 Const MB_YESNO = &H4 Const MB_YESNOCANCEL = &H3 Const MB_ICONASTERISK = &H40 Const MB_ICONERROR = &H10 Const MB_ICONEXCLAMATION = &H30 Const MB_ICONHAND = &H10 Const MB_ICONINFORMATION = &H40 Const MB_ICONQUESTION = &H20 Const MB_ICONSTOP = &H10 Const MB_ICONWARNING = &H30 Const MB_DEFBUTTON1 = &H0 Const MB_DEFBUTTON2 = &H100 Const MB_DEFBUTTON3 = &H200 Const MB_DEFBUTTON4 = &H300 Const MB_APPLMODAL = &H0 Const MB_SYSTEMMODAL = &H1000 Const MB_TASKMODAL = &H2000 Const MB_DEFAULT_DESKTOP_ONLY = &H20000 Const MB_RIGHT = &H80000 Const MB_RTLREADING = &H100000 Const MB_SETFOREGROUND = &H10000 'Const MB_TOPMOST = ??? 'Const MB_SERVICE_NOTIFICATION = ??? 'Const MB_SERVICE_NOTIFICATION_NT3X = ??? Example ' This code is licensed according to the terms and conditions listed here. Have "No" selected by default.168. ' Display a warning message box with the Yes and No option ' owned by window Form1.

168.html (5 of 5) [9/1/2002 5:35:48 PM] .vbapi. "Are you sure you want to do that?".Windows API Guide: MessageBoxEx Function Dim flags As Long ' message box flags Dim lang As Long ' language ID ' For convenience. go ahead and do that. flags = MB_YESNO Or MB_ICONWARNING Or MB_DEFBUTTON2 Or MB_SYSTEMMODAL ' Generate the proper language ID. mbresult = MessageBox(Form1.html http://216.hWnd." End If See Also MessageBox. If mbresult = IDYES Then Debug.com Send Encrypted E-Mail This page is at http://www. 2000 Go back to the Windows API Guide home page.26. E-mail: vbapi@vbapi. SUBLANG_ENGLISH_US) ' Display the message box. MessageBoxIndirect Category Dialog Boxes Back to the Function list. Copyright Information Revised October 29. flags. "Warning!".Print "OK. lang) ' Determine what the user pressed. use a variable to represent the flag settings.com/ref/m/messageboxex. 2000 This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/m/messageboxex. lang = MAKELANGID(LANG_ENGLISH. Back to the Reference section. Last Modified: February 10." Elseif mbresult = IDNO Then Debug.Print "Operation aborted.

Return Value If an error occured.92/vbapi/ref/m/messageboxindirect.vbshop.com | www.com | www. If successful.vbsquare. the function returns 0 (use GetLastError to get the error code).0 or later. IDIGNORE The Ignore button was clicked.Windows API Guide: MessageBoxIndirect Function vbapi.html (1 of 4) [9/1/2002 5:36:02 PM] . Windows CE: Not Supported.vbapi. IDRETRY The Retry button was clicked.com | www.part of the VB-World Network | www. IDNO The No button was clicked. IDCONTINUE Windows 2000: The Continue button was clicked.com .dll" Alias "MessageBoxIndirectA" (lpMsgBoxParams As MSGBOXPARAMS) As Long Platforms q q q q q Windows 95: Supported. Windows 98: Supported.26.vbforums. IDCANCEL The Cancel button was clicked (or the user dismissed the message box using the Esc key). Description & Usage MessageBoxIndirect opens and operates a small message box on the screen. http://216.com | www.com | MessageBoxIndirect Function Declare Function MessageBoxIndirect Lib "user32.168. This function offers more options for the creation of the message box than MessageBox and MessageBoxEx do because this function stores those options in a structure passed to the function.vbworld. Windows 2000: Supported. Windows NT: Requires Windows NT 4. Message boxes are typically used either to communicate important information (such as an error message) or to prompt the user. The message box only closes when the user presses one of the buttons presented. the function returns one of the following flags specifying the button the user clicked on: IDABORT The Abort button was clicked. IDOK The OK button was clicked.

92/vbapi/ref/m/messageboxindirect. to where various parts of the example code offer a Help in a WinHelp file. IDYES The Yes button was clicked. Constant Definitions Const Const Const Const Const Const Const Const Const IDABORT = 3 IDCANCEL = 2 IDCONTINUE = 5 IDIGNORE = 5 IDNO = 7 IDOK = 1 IDRETRY = 4 IDTRYAGAIN = 4 IDYES = 6 Example ' This code is licensed according to the terms and conditions listed here.26. lpHelpInfo.hlp". Visual Basic-Specific Issues None. Parameters lpMsgBoxParams The settings used to create and operate the message box. *** ' This callback function handles the message box's Help button. retval = WinHelp(Form1. Pay attention must be placed. ' *** Place the following code in a module. Also button which opens the corresponding topic The message box is owned by window Form1. ' The desired Context ID is found inside the structure. "C:\MyProg\proghelp. HELP_CONTEXT. Public Sub MsgBoxCallback (lpHelpInfo As HELPINFO) Dim retval As Long ' return value ' Open the proper topic in the help file "C:\MyProg\proghelp.hlp".html (2 of 4) [9/1/2002 5:36:02 PM] .Windows API Guide: MessageBoxIndirect Function IDTRYAGAIN Windows 2000: The Try Again button was clicked.hWnd. ' ' ' ' Create a Yes/No dialog for the user.168.dwContextId) End Sub http://216.

Back to the Reference section.92/vbapi/ref/m/messageboxindirect.hInstance ' handle to instance of this program .Print "Operation aborted.hwndOwner = Form1.hWnd ' window which owns the message box .lpszCaption = "User Prompt" ' message box's title bar text . If mbresult = IDYES Then Debug. merely returning what is passed to it. MessageBoxEx Category Dialog Boxes Back to the Function list. mbresult = MessageBoxIndirect(mbp) ' Determine what the user pressed.lpszText = "Are you sure you want to do that?" ' message box text ." End If See Also MessageBox.hInstance = App.lpszIcon = 0 ' not needed . ' is needed because the AddressOf operator is only valid inside ' a function call.Windows API Guide: MessageBoxIndirect Function ' This is a dummy function.html (3 of 4) [9/1/2002 5:36:02 PM] . *** Dim mbp As MSGBOXPARAMS ' message box's parameters Dim mbresult As Long ' result of message box ' Fill in the parameter structure for the message box. go ahead and do that. http://216." Elseif mbresult = IDNO Then Debug. whereas we need to use it to set a data member. With mbp .cbSize = Len(mbp) ' size of structure .Print "OK.dwContextHelpId = 2300 ' Context ID for the proper topic in the Help file .168.lpfnMsgBoxCallback = DummyFunc(AddressOf MsgBoxCallback) ' pointer to calback function . Public Function DummyFunc (ByVal param As Long) As Long DummyFunc = param End Function This ' *** Place the following code where you want to create the message box. SUBLANG_ENGLISH_US) ' use American English End With ' Display the message box.dwStyle = MB_YESNO Or MB_HELP Or MB_ICONQUESTION ' flags for display .dwLanguageId = MAKELANGID(LANG_ENGLISH.26.

html (4 of 4) [9/1/2002 5:36:02 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz.com/ref/m/messageboxindirect.26. E-mail: vbapi@vbapi. Copyright Information Revised October 29.Windows API Guide: MessageBoxIndirect Function Last Modified: February 11. 2000 Go back to the Windows API Guide home page.vbapi.com Send Encrypted E-Mail This page is at http://www.168.92/vbapi/ref/m/messageboxindirect.html http://216.

65535).com | mouse_event Function Declare Sub mouse_event Lib "user32. Parameters dwFlags A combination of the following flags specifying which mouse input information to place into the input stream. the program should not send another left-button-down input. ByVal dy As Long.1 or later. whose actual amount of movement depends on the current mouse speed and acceleration settings. if the left mouse button is already down. Windows NT: Requires Windows NT 3. dx and dy contain relative coordinates. Windows 2000: Supported. For example.92/vbapi/ref/m/mouse_event. Only changes in mouse position or button state should be send via this function. Visual Basic-Specific Issues None.part of the VB-World Network | www.168.26. Return Value mouse_event does not return a value.vbshop.vbsquare. In the coordinate system used by the function.com | www.0 or later.com | www. Description & Usage mouse_event synthesizes mouse input by placing mouse input information into the input stream.com | www. the coordinates can be given in either absolute or relative form. Remember to only specify button status information for those which have changed. Windows CE: Requires Windows CE 2. regardless of the actual screen size. Note that scroll wheel movement and X button status cannot be simultaneously specified because they both use the dwData parameter. For mouse movement. ByVal cButtons As Long. If this flag is not set.Windows API Guide: mouse_event Function vbapi. A single mouse input event consists of either a move of the mouse or the change of the button state.com . ByVal dx As Long. http://216.html (1 of 4) [9/1/2002 5:36:12 PM] . ByVal dwExtraInfo As Long) Platforms q q q q q Windows 95: Supported. MOUSEEVENTF_ABSOLUTE The dx and dy parameters contain absolute mouse coordinates.vbworld. Windows 98: Supported.0) and the lower-right corner has coordinates (65535.dll" (ByVal dwFlags As Long.vbforums.vbapi. the screen's upper-left corner has coordinates (0.com | www.

MOUSEEVENTF_XDOWN Windows 2000: An X button was pressed. MOUSEEVENTF_WHEEL Windows NT. MOUSEEVENTF_MOVE The mouse moved. MOUSEEVENTF_LEFTUP The left button was released. and negative values mean backwards (toward) rotation. For relative motion.168. The dwData parameter identifies which X buttons. positive values move right and negative values move left. Windows 2000: If dwFlags contains either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP. The dwData parameter specifies the amount of movement.Windows API Guide: mouse_event Function MOUSEEVENTF_LEFTDOWN The left button was pressed.92/vbapi/ref/m/mouse_event. dy Specifies either the y-coordinate of absolute mouse movement or the amount of relative movement along the y-axis. dwExtraInfo An additional 32-bit value associated with the mouse event. The dwData parameter identifies which X buttons. this is a combination of the following flags specifying which X buttons have been pressed or released: XBUTTON1 The first X button was pressed or released. Constant Definitions Const Const Const Const Const Const Const Const Const MOUSEEVENTF_ABSOLUTE = &H8000 MOUSEEVENTF_LEFTDOWN = &H2 MOUSEEVENTF_LEFTUP = &H4 MOUSEEVENTF_MIDDLEDOWN = &H20 MOUSEEVENTF_MIDDLEUP = &H40 MOUSEEVENTF_MOVE = &H1 MOUSEEVENTF_RIGHTDOWN = &H8 MOUSEEVENTF_RIGHTUP = &H10 MOUSEEVENTF_WHEEL = &H80 http://216. 2000: If dwFlags contains MOUSEEVENTF_WHEEL. positive values move down and negative values move up.html (2 of 4) [9/1/2002 5:36:12 PM] .26. MOUSEEVENTF_MIDDLEUP The middle button was released. dwData Windows NT. Positive values mean forward (away) rotation. this specifies the amount of wheel movement. MOUSEEVENTF_MIDDLEDOWN The middle button was pressed. For relative motion. XBUTTON2 The second X button was pressed or released. The dx and dy parameters specify the amount or location of the movement. 2000: The scroll wheel has moved. MOUSEEVENTF_RIGHTUP The right button was released. MOUSEEVENTF_RIGHTDOWN The right button was pressed. dx Specifies either the x-coordinate of absolute mouse movement or the amount of relative movement along the x-axis. MOUSEEVENTF_XUP Windows 2000: An X button was released. in integer multiples of WHEEL_DELTA.

dll" (ByVal x As Long. 0) ' Click the left mouse button once. to use this example. mouse_event MOUSEEVENTF_LEFTDOWN. Go back to the Reference section index. 0. ByVal dx As Long. 0. retval = SetCursorPos(0. ' This code is licensed according to the terms and conditions listed here. 2000 http://216.26. ByVal dy _ As Long. 0. Last Modified: August 26. Although we could use the mouse_event function to move the cursor. 2000 This page is copyright © 2000 Paul Kuliniewicz. 0 End Sub See Also keybd_event. ByVal cButtons As Long. ByVal dwExtraInfo As Long) Public Declare Function SetCursorPos Lib "user32. 0.) Public Declare Sub mouse_event Lib "user32. 0.Windows API Guide: mouse_event Function Const Const Const Const Const MOUSEEVENTF_XDOWN = &H100 MOUSEEVENTF_XUP = &H200 WHEEL_DELTA = 120 XBUTTON1 = &H1 XBUTTON2 = &H2 Example Simulate clicking the left mouse button at the upper-left corner of the screen.168.dll" (ByVal dwFlags As Long.92/vbapi/ref/m/mouse_event. The example runs when the user clicks button Command1. 0. it is much easier to use SetCursorPos instead. SendInput Category Mouse Go back to the Function listing. ByVal y As Long) As Long Private Sub Command1_Click() Dim retval As Long ' return value ' Move the mouse cursor to the upper-left corner of the screen. 0 mouse_event MOUSEEVENTF_LEFTUP.html (3 of 4) [9/1/2002 5:36:12 PM] . you must place a command button named Command1 on a form window. Copyright Information Revised October 29. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. Obviously.

E-mail: vbapi@vbapi.92/vbapi/ref/m/mouse_event.26.com Send Encrypted E-Mail This page is at http://www.168.vbapi.html (4 of 4) [9/1/2002 5:36:12 PM] .Windows API Guide: mouse_event Function Go back to the Windows API Guide home page.com/ref/m/mouse_event.html http://216.

lpExistingFileName The source file or directory. Win 95/98.txt") See Also: CopyFile Category: Files Go back to the alphabetical Function listing.92/vbapi/ref/m/movefile.26.Windows API Guide: MoveFile Function vbapi.txt. "C:\Dummy\buffer.txt to C:\Dummy\buffer.vbworld.com | www. Note how this example both changes ' the filename and moves the file into a different directory simultaneously..part of the VB-World Network | www.dll" Alias "MoveFileA" (ByVal lpExistingFileName As String. Dim retval As Long ' return value retval = MoveFile("C:\MyFiles\temp. Win NT MoveFile moves or renames a file or directory -.com | www.txt". If a directory is moved/renamed.com . The function returns 1 if successful.com/ref/m/movefile. ' The original file will no longer exist.com Send Encrypted E-Mail This page is at http://www. the file or directory to rename (move). Go back to the Windows API Guide home page. Copyright Information.vbapi. all of the subdirectories and files contained in it will similarly be moved/renamed to reflect the path change. i. ByVal lpNewFileName As String) As Long Platforms: Win 32s.com | www.vbapi. i. or 0 if an error occured. E-mail: vbapi@vbapi. Go back to the Reference section index.html [9/1/2002 5:36:17 PM] . Example: ' Move the file to C:\MyFiles\temp.e.com | www.com | MoveFile Function Declare Function MoveFile Lib "kernel32.vbsquare. the new file or directory name to give the source file (where to move the file or directory).e..vb-shop.it's really the same operation either way.html http://216.168. lpNewFileName The target file or directory. This page is copyright © 2000 Paul Kuliniewicz.vbforums.

vbsquare.com | www. Windows 98: Supported. After the copy.1 or later. Windows 2000: Supported.vbworld. Example http://216.com .168.92/vbapi/ref/m/movememory. Source As Any.com | www. which initially holds the data to be transfered. Description & Usage MoveMemory moves the contents of a portion of memory from one location to another.Windows API Guide: MoveMemory Function vbapi. the original contents in the source are set to zeros. ByVal Length As Long) Platforms q q q q q Windows 95: Supported.com | www.vbapi. Length The number of bytes of data to copy from the source memory location to the target memory location. Windows CE: Not Supported. Windows NT: Requires Windows NT 3.vbshop. the ByVal keyword must preceed it. The two locations are identified by pointers to the memory addresses.vbforums. Return Value MoveMemory does not return a value. However. if either a String or a Long holding the desired memory address is passed. which receives the transfered data.html (1 of 2) [9/1/2002 5:36:21 PM] . Source A pointer to the memory address to use as the source.26.part of the VB-World Network | www.com | MoveMemory Function Declare Sub MoveMemory Lib "kernel32. Parameters Destination A pointer to the memory address to use as the target.com | www. Visual Basic-Specific Issues A pointer to any variable can be automatically generated merely be passing that variable as either Destination or Source.dll" Alias "RtlMoveMemory" (Destination As Any.

After the transfer. ' are implied merely by passing the arrays as usual.html (2 of 2) [9/1/2002 5:36:21 PM] .html http://216. 1999 This page is copyright © 1999 Paul Kuliniewicz.168.Print target(c). Last Modified: July 28.26. 10 ' copy all 10 bytes Note how pointers ' Verify that the contents were transfered. Dim source(0 To 9) As Byte ' source array of 10 bytes Dim target(0 To 9) As Byte ' similarly sized target array Dim c As Integer ' counter variable ' Fill the source array with some information. E-mail: vbapi@vbapi. MoveMemory target(0).92/vbapi/ref/m/movememory. For c = 0 To 9 Debug.com/ref/m/movememory. ' this will now contain the information Next c See Also CopyMemory Category Memory Go back to the alphabetical Function listing. source(0).vbapi. ' the contents of the source array are set to 0.Windows API Guide: MoveMemory Function ' This code is licensed according to the terms and conditions listed here. Copyright Information Go back to the Windows API Guide home page. For c = 0 To 9 ' loop through each element source(c) = c ' set each element's value to its index Next c ' Transfer the data from the target array to the source array.com Send Encrypted E-Mail This page is at http://www. Go back to the Reference section index. ' Transfer the contents of one byte array to another.

com | www.168. 50) ' draw a line from current point to (100. 0. Go back to the Windows API Guide home page. hdc The device context of the device to set the current point of. y The y coordinate of the point to set as the current point.com | www.dll" (ByVal hdc As Long. pt) ' set the current point to (0.vbapi.hdc. E-mail: vbapi@vbapi. Win 95/98.26. lpPoint Variable that receives the coordinate of the former current point.vbshop. Go back to the Reference section index. or 1 if successful.hdc.92/vbapi/ref/m/movetoex. Dim pt As POINT_TYPE ' receives the former current point Dim retval As Long ' return value Form1. ByVal x As Long.40) ' Note that pt now contains whatever the old current point was.Windows API Guide: MoveToEx Function vbapi. Win NT MoveToEx sets the current point of a device. The function returns 0 if an error occured.com | www. 0.html (1 of 2) [9/1/2002 5:36:26 PM] .ForeColor = RGB(255. Example: ' Draw a red line from (0. This function also puts the former current point into the variable passed as lpPoint.50) on the window Form1. This page is copyright © 2000 Paul Kuliniewicz. The current point is the starting point from which all graphics APIs ending with "To" (such as LineTo) begin drawing from.part of the VB-World Network | www. but it doesn't matter here.50) Category: Lines & Curves Go back to the alphabetical Function listing.com Send Encrypted E-Mail http://216. Some programming languages call this point the last point referenced.40) to (100.com | www. ByVal y As Long. 0) ' set the foreground drawing color of Form1 to red retval = MoveToEx(Form1. lpPoint As POINT_TYPE) As Long Platforms: Win 32s.vbworld.com | MoveToEx Function Declare Function MoveToEx Lib "gdi32. 40.com . 100.vbforums.vbsquare. Copyright Information. retval = LineTo(Form1. x The x coordinate of the point to set as the current point.

html http://216.92/vbapi/ref/m/movetoex.26.Windows API Guide: MoveToEx Function This page is at http://www.vbapi.168.html (2 of 2) [9/1/2002 5:36:26 PM] .com/ref/m/movetoex.

Win NT MoveWindow moves a window to a new location.com | www. nWidth The width in pixels to resize the window to. 150). In addition to moving it. Example: ' Move window Form1. 150. retval = MoveWindow(Form1. or 0 if an error occured.com | www.html (1 of 2) [9/1/2002 5:36:34 PM] . updates the screen to display the window at its new position.vbsquare. ByVal y As Long. ' Change its size to a width of 175 and a height of 300.com | www. 200.com | www.Windows API Guide: MoveWindow Function vbapi. nHeight The height in pixels to resize the window to. Go back to the Reference section index. The function returns 1 if successful. this function also changes the window's size to a new width and height. Win 95/98. ByVal nHeight As Long. bRepaint If 1. ByVal bRepaint As Long) As Long Platforms: Win 32s.vbshop. ByVal x As Long. hwnd The handle of the window to move and resize.dll" (ByVal hwnd As Long. does not update the screen to reflect the move (the window will appear to be unmoved but will actually be at its new location!). x The x-coordinate to position the upper-left corner of the window at. 175.part of the VB-World Network | www.vbapi. Set its upper-left corner to the point (200. SetWindowPos Category: Windows Go back to the alphabetical Function listing.vbforums.com .com | MoveWindow Function Declare Function MoveWindow Lib "user32.vbworld.92/vbapi/ref/m/movewindow. ByVal nWidth As Long. 1) ' (If the last value had been 0.hWnd. http://216. the window would have appeared to be unmoved!) See Also: GetWindowRect. 300.26. Dim retval As Long ' return value ' Move the window and make sure it's redrawn at its new position.168. If 0. y The y-coordinate to position the upper-left corner of the window at.

com Send Encrypted E-Mail This page is at http://www.vbapi.168.com/ref/m/movewindow.html http://216. Go back to the Windows API Guide home page.92/vbapi/ref/m/movewindow.html (2 of 2) [9/1/2002 5:36:34 PM] . Copyright Information.Windows API Guide: MoveWindow Function This page is copyright © 2000 Paul Kuliniewicz.26. E-mail: vbapi@vbapi.

vb-shop. Description & Usage MulDiv multiplies two 32-bit integers together and divides the resulting 64-bit integer by a 32-bit integer.html (1 of 2) [9/1/2002 5:36:40 PM] . The final result is (usually) a 32-bit integer.168. it is rounded to the nearest integer.vbapi.vbworld.com | www.com | www. Windows 2000: Supported.26. ByVal nDenominator As Long) As Long Platforms q q q q q Windows 95: Supported. Windows NT: Requires Windows NT 3. the function returns -1.Windows API Guide: MulDiv Function vbapi. Visual Basic-Specific Issues None.com | MulDiv Function Declare Function MulDiv Lib "kernel32.vbforums.part of the VB-World Network | www.com | www.com . This function is useful because it can calculate expressions which.1 or later. If successful. the function returns the result of the expression (nNumber * nNumerator) / nDenominator rounded to the nearest integer. ByVal nNumerator As Long. If the end result is not an integer.com | www.dll" (ByVal nNumber As Long.vbsquare. Return Value If an error occured (such as if the result is greater than a 32-bit value or division by zero was attempted).92/vbapi/ref/m/muldiv. Windows 98: Supported. although resulting in a perfectly acceptable value. would otherwise cause an overflow error if the programming language's arithmetic operators were used. Parameters nNumber http://216. Windows CE: Not Supported.

Windows API Guide: MulDiv Function The first number to multiply. an overflow error ' will occur because the result of the multiplication is greater ' than a 32-bit value. 1999 This page is copyright © 1999 Paul Kuliniewicz. 2000 Go back to the Windows API Guide home page. 'result = -134217728 * 243 / 110592 ' With MulDiv: There is no problem calculating the result.vbapi. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:36:40 PM] . nDenominator The number to divide by. nNumerator The second number to multiply.html http://216.168. Dim result As Long ' Without MulDiv: If you uncomment the line below.com Send Encrypted E-Mail This page is at http://www.26. Go back to the Reference section index.) Category Math Go back to the alphabetical Function listing.92/vbapi/ref/m/muldiv. 243. result = MulDiv(-134217728. ' Demonstrate how MulDiv can help avoid producing overflow errors. Example ' This code is licensed according to the terms and conditions listed here. 110592) ' (The result is exactly -294912.com/ref/m/muldiv. Copyright Information Revised October 29. Last Modified: October 9.

winrect. This page is copyright © 2000 Paul Kuliniewicz.hWnd. The function returns 0 if an error occured.168. Win NT OffsetRect changes the position of a rectangle without changing its size.vbforums.Left. -20) ' shift the upwards ' Now change the window on screen to match its new retval = SetWindowPos(Form1.dll" (lpRect As RECT.hWnd.com | www. winrect.com | www. Go back to the Reference section index.com | www.Windows API Guide: OffsetRect Function vbapi.com Send Encrypted E-Mail http://216. Negative values move up. winrect. Example: ' Shift window Form1 50 pixels right and 20 pixels up using its rectangle. x The value to move the rectangle horizontally by. 0. y The value to move the rectangle vertically by. lpRect The rectangle to move. Win 95/98. ByVal x As Long.com . Form1's rectangle rectangle 50 to the right and 20 rectangle winrect. or 1 if successful. E-mail: vbapi@vbapi.html (1 of 2) [9/1/2002 5:36:44 PM] . positive down.vbsquare.vbshop. positive values move it right or down. ByVal y As Long) As Long Platforms: Win 32s.Bottom. Negative values move to the left.Top.vbworld. Go back to the Windows API Guide home page.92/vbapi/ref/o/offsetrect. 50.com | www.26.vbapi. positive to the right. Copyright Information. If the value to move by is negative. Dim winrect As RECT ' receives the rectangle of the window Dim retval As Long ' return value retval = GetWindowRect(Form1.Right.part of the VB-World Network | www. winrect) ' get retval = OffsetRect(winrect.com | OffsetRect Function Declare Function OffsetRect Lib "user32. the rectangle is moved left or up (depending on the direction). 0) See Also: InflateRect Category: Rectangles Go back to the alphabetical Function listing.

168.92/vbapi/ref/o/offsetrect.vbapi.html http://216.26.html (2 of 2) [9/1/2002 5:36:44 PM] .Windows API Guide: OffsetRect Function This page is at http://www.com/ref/o/offsetrect.

negative ones move to the left. not down http://216. fill an elliptical region in light gray.com | www. The function returns 0 if an error occured.vbworld.com | OffsetRgn Function Declare Function OffsetRgn Lib "gdi32.e.com | www. up. negative ones move up. Win NT OffsetRgn translates (slides) a region by a specified amount horizontally and vertically. hDarkBrush As Long ' handles to the two brushes to be used Dim retval As Long ' generic return value ' Create the elliptical region.92/vbapi/ref/o/offsetrgn.com .com | www.vbforums. SIMPLEREGION = 2 The region is rectangular in shape.100)-(220. Then translate the ' region 50 pixels right and 20 pixels up and fill it with dark gray.hDC.26. hRgn A handle to the region to move.Windows API Guide: OffsetRgn Function vbapi. hLightBrush = GetStockObject(LTGRAY_BRUSH) hDarkBrush = GetStockObject(DKGRAY_BRUSH) ' Fill in the region in its current location on Form1 in light gray.vbshop.200) ' Get handles to the light and dark gray solid stock brushes. ByVal y As Long) As Long Platforms: Win 32s. or exactly one of the following flags identifying the shape of the region which was moved: COMPLEXREGION = 3 The region is not empty but is not a rectangle. -20) ' -20 means 20 up.html (1 of 2) [9/1/2002 5:36:51 PM] .dll" (ByVal hRgn As Long. null. hLightBrush) ' Slide the region 50 pixels right and 20 pixels up. right. or down. Positive values move to the right. NULLREGION = 1 The region is empty. y The number of pixels to move the region vertically.168. Positive values move down. 220. Dim hRgn As Long ' handle to the region Dim hLightBrush As Long. Example: ' On window Form1. retval = OffsetRgn(hRgn. retval = FillRgn(Form1. i. 50. 100. ByVal x As Long. Win 95/98. hRgn. The region can be moved in any direction left. 200) ' bounding rectangle (20.vbapi. x The number of pixels to move the region horizontally.com | www. hRgn = CreateEllipticRgn(20..part of the VB-World Network | www.vbsquare.

com/ref/o/offsetrgn.com Send Encrypted E-Mail This page is at http://www. Copyright Information. retval = DeleteObject(hRgn) Category: Regions Go back to the alphabetical Function listing. Go back to the Windows API Guide home page. Go back to the Reference section index.html (2 of 2) [9/1/2002 5:36:51 PM] . hRgn. hDarkBrush) ' Delete the region to free up resources.html http://216.168. This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/o/offsetrgn.Windows API Guide: OffsetRgn Function ' Fill in the region in its new location in dark gray.vbapi. E-mail: vbapi@vbapi. retval = FillRgn(Form1.26.hDC.

pDefault A PRINTER_DEFAULTS structure specifying some options for opening the printer. This handle can then be used by a number of printer API functions to reference the printer.vbforums.168. Windows NT: Requires Windows NT 3.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String.vbapi.1 or later.vbshop. If an error occured. Windows 2000: Supported.92/vbapi/ref/o/openprinter. phPrinter Receives a handle to the newly opened printer.com | OpenPrinter Function Declare Function OpenPrinter Lib "winspool. Description & Usage OpenPrinter opens a printer and obtains a handle to it. Visual Basic-Specific Issues When passing zero for pDefault. After your program is finished using this handle. it should close the printer via ClosePrinter. pass zero for this parameter.com | www.vbsquare.vbworld. Windows CE: Not Supported. Example http://216.com | www.part of the VB-World Network | www.26.com . Windows 98: Supported. the expression ByVal CLng(0) must be used. phPrinter As Long. To use the default settings. Parameters pPrinterName The name of the printer or print server to obtain a handle to.html (1 of 4) [9/1/2002 5:36:55 PM] . pDefault As Any) As Long Platforms q q q q q Windows 95: Supported. the function obtains a handle to the default print server. Return Value If successful.com | www. If this is an empty string.com | www. the function returns a non-zero value.Windows API Guide: OpenPrinter Function vbapi. the function returns zero (use GetLastError to get the error code).

phPrinter As Long. ByVal cdBuf As Long. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. buffer(0).1) As Long ' Get information about the default printer. bytesNeeded. numPrinters) ' Allocate that much space in the buffer array.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function OpenPrinter Lib "winspool. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. ByVal hPrinter _ As Long) As Long Public Declare Function ClosePrinter Lib "winspool. 1. first place a command button named cmdProperties on a form window.) Public Type PRINTER_INFO_1 flags As Long pDescription As String pName As String pComment As String End Type Public Declare Function EnumPrinters Lib "winspool.html (2 of 4) [9/1/2002 5:36:55 PM] .drv" (ByVal hPrinter As Long) As Long ' *** Place the following code inside a form window.drv" Alias "EnumPrintersA" (ByVal flags As Long.drv" Alias "OpenPrinterA" (ByVal pPrinterName _ As String. pcReturned As Long) As Long Public Const PRINTER_ENUM_DEFAULT = &H1 Public Declare Function lstrcpy Lib "kernel32. The dialog box is opened when the user clicks the button cmdProperties. http://216. 1. ' This code is licensed according to the terms and conditions listed here. vbNullString. pDefault As Any) As Long Public Declare Function PrinterProperties Lib "winspool. pPrinterEnum As Long. ReDim buffer(0 To bytesNeeded / 4 . _ ByVal lpString2 As Any) As Long Public Declare Function lstrlen Lib "kernel32.Windows API Guide: OpenPrinter Function Display the Properties dialog box for the system's default printer. ByVal Level As Long. vbNullString.dll" Alias "lstrcpyA" (ByVal lpString1 As Any.drv" (ByVal hWnd As Long. *** Private Sub Dim Dim Dim Dim Dim Dim Dim cmdProperties_Click() pi1 As PRINTER_INFO_1 bytesNeeded As Long numPrinters As Long buffer() As Long slength As Long hPrinter As Long retval As Long ' ' ' ' ' ' ' a little info about the printer size needed for buffer number of printers enumerated (should be 1) buffer for printer information length of string to copy handle to the printer generic return value ' Figure out how much space is needed to store the printer information. _ pcbNeeded As Long. To use the example. 0.168. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.26. ByVal 0.92/vbapi/ref/o/openprinter. _ ByVal name As String.

buffer(1)) . Last Modified: January 21.pDescription = Space(lstrlen(buffer(1))) retval = lstrcpy(. If retval = 0 Or numPrinters <> 1 Then Debug. retval = OpenPrinter(pi1. numPrinters) ' Make sure we were successful. hPrinter) ' Close the printer.26.pName. retval = PrinterProperties(Me.Windows API Guide: OpenPrinter Function bytesNeeded. 2000 http://216. hPrinter.Print "Unable to open printer!" End If End Sub See Also ClosePrinter Category Printers Go back to the Function listing.pComment = Space(lstrlen(buffer(3))) retval = lstrcpy(.168.pComment. since the buffer holds pointers to them.html (3 of 4) [9/1/2002 5:36:55 PM] . 2001 This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29." Exit Sub End If ' Copy the data into the structure. buffer(3)) End With ' Open the printer.pName.flags = buffer(0) ' Strings require more work. retval = ClosePrinter(hPrinter) Else Debug. .pName = Space(lstrlen(buffer(2))) retval = lstrcpy(.Print "No default printer or some other error.pDescription. Go back to the Reference section index. _ bytesNeeded. ByVal CLng(0)) If retval <> 0 Then ' Display the properties dialog.hWnd. With pi1 ' Copy numerical data directly. buffer(2)) . .92/vbapi/ref/o/openprinter.

com/ref/o/openprinter. E-mail: vbapi@vbapi.html (4 of 4) [9/1/2002 5:36:55 PM] .Windows API Guide: OpenPrinter Function Go back to the Windows API Guide home page.168.92/vbapi/ref/o/openprinter.com Send Encrypted E-Mail This page is at http://www.26.html http://216.vbapi.

lpdwIconIndex As Long) As Long Platforms q q q q q Windows 95: Supported. This string will also receive the name of the file which holds the user's selection. Windows 98: Supported.http://216. Windows NT. Therefore. Return Value If successful. ByVal nMaxFile As Long.92/vbapi/ref/p/pickicondlg. If an error occured or the user did not choose an icon (for example. any strings output by the function also must be converted from Unicode into ANSI.com | www. if any. 2000: All strings used by this function must be Unicode. lpstrFile A null-terminated string specifying the default icon-containing file to look inside. Description & Usage PickIconDlg displays the standard Windows "icon selection" dialog box. http://216.vbforums.html vbapi. ByVal lpstrFile As String.dll" Alias "#62" (ByVal hwndOwner As Long. Visual Basic-Specific Issues None.com | www. PickIconDlg is officially undocumented. Windows CE: Unknown.1 or later.168.26. the user clicked "Cancel"). the function returns a non-zero value.26.vbshop.168. Windows NT: Requires Windows NT 3.com | www.vbworld.vbapi.html (1 of 4) [9/1/2002 5:37:00 PM] .vbsquare. The function then reports which icon the user selected. the function returns 0. Windows 2000: Supported. any strings passed to the function must first be converted into Unicode.part of the VB-World Network | www. this string must have enough empty space after the terminating null character to receive the final string. It allows the user to choose an icon found inside a file. Likewise.92/vbapi/ref/p/pickicondlg.com | PickIconDlg Function Declare Function PickIconDlg Lib "shell32.com . Therefore.com | www. Parameters hwndOwner A handle to the window which is opening the icon selection dialog box.

dll" (ByVal hIcon As Long) As Long Public Declare Function GetSystemDirectory Lib "kernel32.92/vbapi/ref/p/pickicondlg. display an icon selection dialog box. Example ' This code is licensed according to the terms and conditions listed here. Private Sub Command1_Click() Dim iconfile As String ' file that contains the desired icon Dim iconindex As Long ' index of the desired icon Dim slength As Long ' length of returned string Dim hIcon As Long ' handle to the icon once it is extracted Dim ovi As OSVERSIONINFO ' identifies the Windows platform Dim retval As Long ' return value ' First.dll" Alias "GetSystemDirectoryA" _ (ByVal lpBuffer As String.dll" Alias "ExtractIconA" (ByVal hInst _ As Long. ByVal nIconIndex As Long) As Long Public Declare Function DrawIcon Lib "user32. If the ' user chooses an icon. http://216.92/vbapi/ref/p/pickicondlg.dll" (ByVal hDC As Long.dll" Alias "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long Public Declare Function ExtractIcon Lib "shell32. determine if the computer is running Windows NT or 2000. ByVal nMaxFile As Long. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.http://216. ByVal x As Long.26.26.168. This variable also receives the zero-based index of the icon the user selected. ByVal hIcon As Long) As Long Public Declare Function DestroyIcon Lib "user32. then draw it in the corner of window Form1's client area.dll" Alias "#62" (ByVal hwndOwner As Long. ByVal lpszExeFileName As String. _ ByVal y As Long.) Public Declare Function PickIconDlg Lib "shell32.html nMaxFile The length of the string passed as lpstrFile. ByVal nSize As Long) As Long ' When the user presses button Command1. lpdwIconIndex The zero-based index of the icon to select by default.html (2 of 4) [9/1/2002 5:37:00 PM] In either .168. _ ByVal lpstrFile As String. lpdwIconIndex As Long) As Long Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Public Const VER_PLATFORM_WIN32_NT = 2 Public Const VER_PLATFORM_WIN32_WINDOWS = 1 Public Declare Function GetVersionEx Lib "kernel32.

iconfile. ovi. 0. draw the icon on Form1. Include plenty ' of extra space in the string so it can receive the user's selection. Back to the Reference section. iconfile = Space(256) slength = GetSystemDirectory(iconfile.168. iconindex) ' Draw it in the corner of the window. If retval <> 0 Then ' Extract the icon from the file.http://216. convert ' the string to and from Unicode immediately before and after calling the function.26. vbUnicode) End If retval = PickIconDlg(Form1.dwOSVersionInfoSize = Len(ovi) retval = GetVersionEx(ovi) ' Figure out where the System directory is.html (3 of 4) [9/1/2002 5:37:00 PM] . Len(iconfile)) iconfile = Left(iconfile. hIcon = ExtractIcon(App. Category Shell Back to the Function list. vbFromUnicode) End If ' Remove the terminating null and empty space from the string. vbNullChar) . Last Modified: June 4. Len(iconfile).hWnd. hIcon) ' Destroy the icon to free resources.html case. 2000 http://216.26. If ovi.hDC. retval = DrawIcon(Form1.dll" & vbNullChar & Space(256) iconindex = 2 ' Display the icon selection dialog. iconfile.hInstance. iconfile = Left(iconfile.1) ' If the user selected something.92/vbapi/ref/p/pickicondlg.dwPlatformId = VER_PLATFORM_WIN32_NT Then iconfile = StrConv(iconfile. ' all strings used with PickIconDlg must be converted into Unicode. InStr(iconfile.92/vbapi/ref/p/pickicondlg.dwPlatformId = VER_PLATFORM_WIN32_NT Then iconfile = StrConv(iconfile. iconindex) If ovi. iconfile = iconfile & "\pifmgr. 0.168. retval = DestroyIcon(hIcon) End If End Sub If Windows NT or 2000 is running.dll. slength) ' Have the default selection be the third icon in pifmgr.

http://216. Copyright Information Revised October 29.html http://216.html (4 of 4) [9/1/2002 5:37:00 PM] .92/vbapi/ref/p/pickicondlg.168.92/vbapi/ref/p/pickicondlg.html This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.26.com/ref/p/pickicondlg. E-mail: vbapi@vbapi. 2000 Go back to the Windows API Guide home page.26.168.vbapi.

y) coordinate and the ellipse. filling the area between them (going counterclockwise around the ellipse).com | Pie Function Declare Function Pie Lib "gdi32. 20) http://216.vbsquare. The first two sets of (x. retval = Pie(Form1. X2 The x-coordinate of the lower-right corner of the ellipse's bounding rectangle.vbworld. 70. ByVal Y3 As Long. ByVal X2 As Long..vbapi. or 0 if an error occured.com | www.com | www. the "upper-right" fourth of the ellipse. The pie wedge will have endpoints on the ellipse of (210. the start and endpoints are determined by the intersection of a ray from the ellipse's center through the (x. Y3 The y-coordinate of the point determining the starting point of the pie wedge.part of the VB-World Network | www. The ellipse has a bounding rectangle ' of (10.com | www. Y4 The y-coordinate of the point determining the ending point of the pie wedge. Win 95/98.92/vbapi/ref/p/pie. ByVal Y4 As Long) As Long Platforms: Win 32s.26.120). The pie wedge consists of two radials from the ellipse's center to the ellipse's edge.70) ' and (110. ByVal X1 As Long. Draw the pie wedge ' using Form1's current brush and pen.Windows API Guide: Pie Function vbapi. Example: ' Draw a pie wedge on window Form1.vbforums. 20.vbshop. 10.20)-(210. ByVal X4 As Long. Dim retval As Long ' return value ' Draw the chord as specified above.y) coordinate pairs specify the bounding rectangle which determines the ellipse.i.hDC. X3 The x-coordinate of the point determining the starting point of the pie wedge.y) pairs determine the points along the ellipse.20) -. hdc A device context to the device to draw the chord on. 120. 210. ByVal Y2 As Long. ByVal Y1 As Long. The function returns 1 if successful. The pie wedge is drawn using the device's currently selected pen and is filled using its currently selected brush. X1 The x-coordinate of the upper-left corner of the ellipse's bounding rectangle.dll" (ByVal hdc As Long. 110. Win NT Pie draws an elliptical pie wedge on a device.com | www.168. X4 The x-coordinate of the point determining the ending point of the pie wedge. ByVal X3 As Long. The last two sets of (x. Y2 The y-coordinate of the lower-right corner of the ellipse's bounding rectangle. 210.html (1 of 2) [9/1/2002 5:37:04 PM] . Y1 The y-coordinate of the upper-left corner of the ellipse's bounding rectangle.e.com .

92/vbapi/ref/p/pie.26.html http://216.com/ref/p/pie. This page is copyright © 2000 Paul Kuliniewicz.com Send Encrypted E-Mail This page is at http://www.168.html (2 of 2) [9/1/2002 5:37:04 PM] .Windows API Guide: Pie Function See Also: Chord. Go back to the Windows API Guide home page.vbapi. Go back to the Reference section index. Copyright Information. Ellipse Category: Filled Shapes Go back to the alphabetical Function listing. E-mail: vbapi@vbapi.

com . Visual Basic users must use the alternate declare of the function in order to pass the numeric identifier of the sound instead of a string. Note that when the function needs to play an application resource or a RAM-loaded sound.Windows API Guide: PlaySound Function vbapi. ByVal hModule As Long.com | www. lpszName The name or some other identifier of the sound.wav file to play. The function returns 0 if an error occured. Win NT PlaySound plays a waveform sound through the speakers.com | www. the SystemDefault sound will play if the specified sound cannot be located http://216. pass 0 for this parameter. SND_APPLICATION = &H80 lpszName is a string identifying the application-specific event association sound to play. if needed.part of the VB-World Network | www. Win 95/98.html (1 of 2) [9/1/2002 5:37:08 PM] .vbworld. SND_LOOP = &H8 Continue looping the sound until this function is called again ordering the looped playback to stop. SND_ALIAS_ID = &H110000 lpszName is a string identifying the name of the predefined sound identifier to play. This sound could be a . SND_MEMORY = &H4 lpszName is a numeric pointer refering to the memory address of the image of the waveform sound loaded into RAM. Its exact format depends on the flags passed as dwFlags.vbsquare. or a sound resource stored in an application.wav file. ByVal hModule As Long. If this flag is not specified. SND_ASYNC must also be specified.dll" Alias "PlaySoundA" (ByVal lpszName As String.92/vbapi/ref/p/playsound.return immediately after beginning to play the sound and have it play in the background. If the function does not need this information. SND_FILENAME = &H20000 lpszName is a string identifying the filename of the . a system event sound (such as the system startup sound).168.vbforums. ByVal dwFlags As Long) As Long Platforms: Win 32s. SND_ASYNC = &H1 Play the sound asynchronously -.com | PlaySound Function Declare Function PlaySound Lib "winmm. dwFlags Zero or more of the following flags specifying what lpszName refers to and how to play the sound: SND_ALIAS = &H10000 lpszName is a string identifying the name of the system event sound to play.com | www. SND_NODEFAULT = &H2 If the specified sound cannot be found. terminate the function with failure instead of playing the SystemDefault sound.dll" Alias "PlaySoundA" (ByVal lpszName As Long. hModule A handle to the application module containing the sound resource the play.com | www.26. or a non-zero value if successful.vbapi.vbshop. ByVal dwFlags As Long) As Long Alternate Declare for when using a resource or memory location: Declare Function PlaySound_Res Lib "winmm.

92/vbapi/ref/p/playsound.Windows API Guide: PlaySound Function and the function will return with success.wav". retval = PlaySound("C:\Sounds\scream. 0.com/ref/p/playsound. SND_ALIAS Or SND_SYNC) ' Now loop the .26.wav file for five seconds before purging its playback. Copyright Information. SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP) Sleep 5000 ' wait for 5 seconds while sound loops retval = PlaySound("". SND_NOSTOP = &H10 If a sound is already playing.vbapi. Go back to the Reference section index. do not wait for the currently playing sound to stop and instead return with failure. Go back to the Windows API Guide home page. SND_SYNC = &H0 Play the sound synchronously -. Dim retval As Long ' return value of the function ' Synchronously play the SystemStart sound. lpszName must be an empty string. the playing sound will be terminated and the sound specified by the function will play instead. SND_NOWAIT = &H2000 If a sound is already playing. This function returns when the sound is done. E-mail: vbapi@vbapi. do not prematurely stop that sound from playing and instead return with failure.com Send Encrypted E-Mail This page is at http://www. SND_PURGE = &H40 Stop playback of any waveform sound. SND_PURGE Or SND_NODEFAULT) ' stop playback See Also: sndPlaySound Category: Audio Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz. 0. hModule must be specified as that application's module handle.do not return until the sound has finished playing.wav for 5 seconds before stopping. Then loop ' playing the file C:\Sounds\scream. If this flag is not specified. Note that ' we don't want the default sound to play if the file is not found. retval = PlaySound("SystemStart".html http://216.168. SND_RESOURCE = &H4004 lpszName is the numeric resource identifier of the sound stored in an application. Example: ' First play the SystemStart event sound synchronously. 0.html (2 of 2) [9/1/2002 5:37:08 PM] .

26. the function returns a non-zero value. Windows 2000: Supported.com | www.part of the VB-World Network | www.com | www. ByVal cPoints As Long) As Long Platforms q q q q q Windows 95: Supported.com | www.com .50) as well).com | PolyBezier Function Declare Function PolyBezier Lib "gdi32.vbsquare.vbworld. lppt As POINT_TYPE. Description & Usage PolyBezier draws a series of cubic Bézier curves on a device.168. the third curve would begin at (100.Windows API Guide: PolyBezier Function vbapi.92/vbapi/ref/p/polybezier. Windows CE: Not Supported. Return Value If an error occured. 2000: use GetLastError to get the error code).dll" (ByVal hdc As Long. If successful. Visual Basic-Specific Issues None. Windows NT: Requires Windows NT 3.html (1 of 3) [9/1/2002 5:37:28 PM] .vbforums. the function returns 0 (Windows NT. Windows 98: Supported. Parameters hdc A handle to a device context to the device to draw the Bézier curves on.vbapi.vb-shop.50).com | www. The function begins drawing the curves at a start point and draws each subsequent curve starting at the point where the previous one ended (for example. Each Bézier curve is drawn using the device's current pen.1 or later. http://216. if the second curve ended at (100.

x = pts(2).Windows API Guide: PolyBezier Function lppt An array containing all the end points and control points for the Bézier curves. Dim hPen As Long ' handle to the solid black stock pen Dim hOldPen As Long ' handle to Form1's previous pen Dim pts(0 To 6) As POINT_TYPE ' array of points for the curves Dim retval As Long ' return value ' Load the ' into the pts(0). cPoints The number of elements in the array passed as lppt.x = pts(5). hPen) ' Draw the two Bézier curves. hPen = GetStockObject(BLACK_PEN) ' Select the pen for use in Form1. ' Draw two Bézier curves on window Form1 using the ' solid black stock pen. 7) ' Select the previous pen used by Form1.y = 200 ' 2nd curve ends at (250. pts(0).50) 300: pts(5). Example ' This code is licensed according to the terms and conditions listed here.y = 50 ' control point (225.92/vbapi/ref/p/polybezier.200) ' Get a handle to the solid black stock pen.75) 150: pts(2).x = pts(1).100) 125: pts(1).y = 75 ' control point (125.y = 150 ' control point (300.html (2 of 3) [9/1/2002 5:37:28 PM] . This value will have to be one more than three times the number of curves to draw. hOldPen) See Also http://216. The first point is the starting point for the first curve.168. 100: pts(0).x = pts(6). 150) 250: pts(6).26.125) 175: pts(3).hDC.y = 125 ' control point (150. starting at (175.100) 225: pts(4).100) three define the second curve.y = 100 ' 1st curve starts at (100.hDC.x = seven points defining the two Bézier curves array.x = ' The next pts(4). retval = PolyBezier(Form1.x = pts(3).hDC.y = 100 ' 1st curve ends at (175. Each set of three points following the first identifies how to draw each curve: the first two points in the set are the two control points. and the third point is the end point of the curve. hOldPen = SelectObject(Form1. The coordinates of the curves appear in ' the example code. The first four points define the first curve. retval = SelectObject(Form1.

Last Modified: November 10. 1999 This page is copyright © 1999 Paul Kuliniewicz.26.html http://216. Go back to the Reference section index. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29.vbapi.92/vbapi/ref/p/polybezier.com/ref/p/polybezier.Windows API Guide: PolyBezier Function PolyBezierTo Category Lines & Curves Go back to the alphabetical Function listing.168. E-mail: vbapi@vbapi.html (3 of 3) [9/1/2002 5:37:28 PM] .

vbforums.com | www.vb-shop. http://216.html (1 of 3) [9/1/2002 5:37:33 PM] .50).vbworld.com | PolyBezierTo Function Declare Function PolyBezierTo Lib "gdi32. the function returns 0 (Windows NT.Windows API Guide: PolyBezierTo Function vbapi. Return Value If an error occured. Windows 98: Supported.50) as well).168. Windows 2000: Supported. If successful. Description & Usage PolyBezierTo draws a series of cubic Bézier curves on a device. the third curve would begin at (100.26.com | www. Each Bézier curve is drawn using the device's current pen. ByVal cCount As Long) As Long Platforms q q q q q Windows 95: Supported. Parameters hdc A handle to a device context to the device to draw the Bézier curves on. Visual Basic-Specific Issues None.vbapi.92/vbapi/ref/p/polybezierto. Windows CE: Not Supported.dll" (ByVal hdc As Long.part of the VB-World Network | www. if the second curve ended at (100.com | www. 2000: use GetLastError to get the error code).com | www. Windows NT: Requires Windows NT 3. the function returns a non-zero value. lppt As POINT_TYPE.1 or later.com . The function begins drawing the curves at the device's current point and draws each subsequent curve starting at the point where the previous one ended (for example.vbsquare.

x = 250: pts(5). 100) ' Load the six points defining the two Bézier curves ' into the array.html (2 of 3) [9/1/2002 5:37:33 PM] .x = 150: pts(1). ' Use the solid black stock pen to draw a straight line. and the third point is the end point of the curve.hDC.y = 200 ' 2nd curve ends at (250.x = 225: pts(3). ' followed by two Bézier curves on window Form1.125) pts(2).50) pts(4).26. pts(0). hPen = GetStockObject(BLACK_PEN) ' Select the pen for use in Form1. hPen) ' Move the current point to (200. 6) http://216. Dim hPen As Long ' handle to the solid black stock pen Dim hOldPen As Long ' handle to Form1's previous pen Dim curpt As POINT_TYPE ' receives previous current point Dim pts(0 To 5) As POINT_TYPE ' array of points for the curves Dim retval As Long ' return value ' Get a handle to the solid black stock pen. 200.y = 150 ' control point (300. Each set of three points identifies one curve: the first two points are the control points.hDC.x = 125: pts(0). hOldPen = SelectObject(Form1.x = 300: pts(4).100) ' The next three define the second curve.100). The ' coordinates of the line and curves appear in the example code.hDC.75) pts(1).y = 50 ' control point (225. cPoints The number of elements in the array passed as lppt.x = 175: pts(2). ' The curve will of course start of (100.168. 100. 150) pts(5).200) ' Draw the two Bézier curves. 25) and draw a line ' to the point (100.92/vbapi/ref/p/polybezierto.y = 125 ' control point (150. 25.Windows API Guide: PolyBezierTo Function lppt An array containing all the end points and control points for the Bézier curves. starting at (175. This value will have to be three times the number of curves to draw. retval = MoveToEx(Form1.y = 75 ' control point (125.hDC. retval = PolyBezierTo(Form1.100). The first three points define the first curve.100) pts(3).y = 100 ' 1st curve ends at (175. Example ' This code is licensed according to the terms and conditions listed here. pts(0). curpt) retval = LineTo(Form1.

com Send Encrypted E-Mail This page is at http://www. Copyright Information Revised October 29.com/ref/p/polybezierto. E-mail: vbapi@vbapi. 2000 Go back to the Windows API Guide home page.168.vbapi. Last Modified: November 11.26.hDC. Go back to the Reference section index.Windows API Guide: PolyBezierTo Function ' Select the previous pen used by Form1.92/vbapi/ref/p/polybezierto.html (3 of 3) [9/1/2002 5:37:33 PM] . 1999 This page is copyright © 1999 Paul Kuliniewicz.html http://216. hOldPen) See Also PolyBezier Category Lines & Curves Go back to the alphabetical Function listing. retval = SelectObject(Form1.

100) 2nd point (250.x = 200: points(2). 4) ' four points in the array See Also: PolyPolygon Category: Filled Shapes Go back to the alphabetical Function listing.com | www. http://216.26.com | www. Win 95/98.x = 150: points(3).y = 200 ' points(3).part of the VB-World Network | www.x = 200: points(0). The vertices of the polygon are stored in an array passed as lpPoint. Dim points(0 To 3) As POINT_TYPE ' vertices of the polygon Dim retval As Long ' return value ' Load the coordinates of the diamond's points(0). The polygon is drawn using the current pen and is filled using the current brush.Windows API Guide: Polygon Function vbapi.vbapi. Only specify each point once.hDC.com | Polygon Function Declare Function Polygon Lib "gdi32.vb-shop. Win NT Polygon draws and fills a polygon on a device. The function returns 1 if successful.168.92/vbapi/ref/p/polygon. nCount The number of elements in the array passed as lpPoint.vbworld.200) 4th point (150.com | www.com | www. hdc A device context to the device to draw the polygon on. lpPoint As POINT_TYPE.vbforums.html (1 of 2) [9/1/2002 5:37:40 PM] . ByVal nCount As Long) As Long Platforms: Win 32s.y = 150 ' vertices into the array. 1st point (200. or 0 if an error occured.dll" (ByVal hdc As Long. lpPoint An array holding the vertices of the polygon in the order which they will be drawn in.y = 150 ' points(2). Example: ' Draw a diamond on window Form1 using the default pen and ' brush.x = 250: points(1).com .150) ' Draw the diamond using Form1's default pen and brush retval = Polygon(Form1. Specify each point only once.y = 100 ' points(1). points(0).150) 3rd point (200. Note how the points must be loaded into the array before calling the function. in sequential order.vbsquare.

com/ref/p/polygon. Copyright Information.com Send Encrypted E-Mail This page is at http://www.html (2 of 2) [9/1/2002 5:37:40 PM] . This page is copyright © 2000 Paul Kuliniewicz. Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.vbapi.Windows API Guide: Polygon Function Go back to the Reference section index.92/vbapi/ref/p/polygon.168.26.html http://216.

com | www.com | Polyline Function Declare Function Polyline Lib "gdi32. Dim points(0 To 3) As POINT_API ' the points to draw to/from Dim retval As Long ' return value ' Put the points to use into the array.100) must be given as both the first and last points. Win 95/98.com .y = 150 ' point #1: (200. Lines are drawn connecting the first point to the second point.150) points(2).168. points(0). The first and last points are not connected. Four points must be specified to draw the ' triangle because the point (100.html (1 of 2) [9/1/2002 5:37:48 PM] . 150).x = 100: points(0).vbforums.100) must be entered twice. PolyPolyline Category: Lines & Curves Go back to the alphabetical Function listing. or 0 if an error occured.ForeColor = RGB(255.y = 100 ' point #0: (100. etc. the second point to the third point. and (0. http://216. Example: ' Draw a triangle having corners (100. Win NT Polyline draws a series of lines on a graphics-capable device. points(0).com | www. The lines are drawn using the device's current drawing color.hDC. nCount The number of elements in the array passed as lpPoint. Note how since we want the first and last points to be connected. lpPoint As POINT_TYPE.Windows API Guide: PolyLine Function vbapi. (200.vbworld. 150) ' on window Form1.com | www. hdc The device context of the device to draw the lines on. Go back to the Reference section index.92/vbapi/ref/p/polyline. ByVal nCount As Long) As Long Platforms: Win 32s.com | www.vbsquare.vbshop. These lines connect the points given in an array passed as lpPoint. PolylineTo.dll" (ByVal hdc As Long.y = 150 ' point #2: (0. lpPoint An array specifying the x and y coordinates of each point to draw lines to or from. The function returns 1 if successful.100). 0.150) points(3).x = 200: points(1).x = 100: points(3).part of the VB-World Network | www. ' point (100.26.y = 100 ' point #3: (100. 0) ' set Form1's drawing color to red retval = Polyline(Form1. 4) ' draw the lines See Also: LineTo.x = 0: points(2).100) Form1.vbapi.100) points(1).

Copyright Information.com Send Encrypted E-Mail This page is at http://www.com/ref/p/polyline. E-mail: vbapi@vbapi.html http://216.26. Go back to the Windows API Guide home page.html (2 of 2) [9/1/2002 5:37:48 PM] .Windows API Guide: PolyLine Function This page is copyright © 2000 Paul Kuliniewicz.vbapi.168.92/vbapi/ref/p/polyline.

100). PolyPolyline http://216. The current point must first be set to (100. curpt) ' Load the points of the triangle into the array points().150).x = 100: points(2).y = 150 ' point #0: (200.vbapi.y = 150 ' point #1: (0. Example: ' Draw a red triangle with corners (100.vbsquare.Windows API Guide: PolylineTo Function vbapi.hDC.part of the VB-World Network | www. 100.com | PolylineTo Function Declare Function PolylineTo Lib "gdi32. cCount The number of elements in lppt. hdc The device context of the device to draw the lines on.vbforums. The original current point and the last point are not connected.150) points(1). (200. ByVal cCount As Long) As Long Platforms: Win 32s.y = 100 ' point #2: (100. points(0).x = 0: points(1).com | www. Notice that (100.26.vbshop. The function draws lines connecting the device's current point to the first point. 0. The function returns 1 if successful.100) retval = MoveToEx(Form1. and the last ' point must also be given as (100.ForeColor = RGB(255. Win NT PolylineTo draws a series of connected lines on a graphics-capable device.com | www. Polyline. Win 95/98. 100.com | www. points(0).100) ' is given as the last point to close the figure.html (1 of 2) [9/1/2002 5:37:52 PM] . and (0.x = 200: points(0).168.100) to close the triangle. the first point to the second point. etc. When the function is finished.92/vbapi/ref/p/polylineto.150) points(2).dll" (ByVal hdc As Long.hDC. 0) ' set Form1's drawing color to red retval = PolylineTo(Form1.com . lppt An array of points to connect using the lines. lppt As POINT_TYPE.vbworld. the second point to the third point.100). Dim points(0 To 2) As POINT_TYPE ' points given to the function Dim curpt As POINT_TYPE ' receives current point from MoveToEx Dim retval As Long ' return value ' Set Form1's current point to (100. or 0 if an error occured. 3) ' draw the lines See Also: LineTo. it sets the current point to whatever the last point in the array is.100) Form1. The points are given to the function inside an array passed as lppt. The lines are drawn in the device's current drawing color.150) ' on window Form1.com | www.

Go back to the Reference section index.168. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:37:52 PM] .vbapi. This page is copyright © 2000 Paul Kuliniewicz.com/ref/p/polylineto.html http://216.com Send Encrypted E-Mail This page is at http://www.92/vbapi/ref/p/polylineto.Windows API Guide: PolylineTo Function Category: Lines & Curves Go back to the alphabetical Function listing. Go back to the Windows API Guide home page. Copyright Information.26.

lpPolyCounts An array holding the number of points in lpPoint belonging to each polygon.com | www.y = 200 ' 1st point: (350. points(4).150) (200.y numpoints(0) = 4 ' first four the diamond.vbsquare. lpPolyCounts(0) identifies the number of points belonging to the first polygon. lpPolyCounts As Long. Example: ' Draw a diamond and a triangle on window Form1.x = 150: points(3).92/vbapi/ref/p/polypolygon.com . This function is equivalent to calling the Polygon function multiple times.part of the VB-World Network | www. lpPoint An array holding all of the vertices of every polygon to draw.200) (150. nCount The number of elements in the array passed as lpPolyCounts.vbshop.com | PolyPolygon Function Declare Function PolyPolygon Lib "gdi32.y points(2). ByVal nCount As Long) As Long Platforms: Win 32s. The polygons are drawn using the device's current pen and are filled using the device's current brush.Windows API Guide: PolyPolygon Function vbapi. Win NT PolyPolygon draws multiple polygons on a given device. The array passed as lpPolyCounts identifies the number of vertices in each polygon. hdc A device context to the device to draw the polygons on.com | www. or 0 if an error occured. The vertices of every polygon are stored in an array passed as lpPoint.vbworld.vbapi. listed in their proper order. lpPoint As POINT_TYPE. etc.x = 200: points(0). Dim points(0 To 6) As POINT_TYPE ' holds diamond's and triangle's vertices Dim numpoints(0 To 1) As Long ' holds number of points belonging to each polygon Dim retval As Long ' return value ' Load the points belonging to points(0). The two ' polygons are not interconnected and are drawn using the window's current pen ' and brush. = 100 ' 1st point: = 150 ' 2nd point: = 200 ' 3rd point: = 150 ' 4th point: points identify the (200.x = 350: points(4).dll" (ByVal hdc As Long. Win 95/98.html (1 of 2) [9/1/2002 5:37:59 PM] .x = 200: points(2). For example. Note how the two arrays delineate each polygon's set of vertices.y points(1).150) diamond ' Load the points belonging to the triangle.26.com | www.168. The various polygons are not connected.y points(3).200) http://216.x = 250: points(1).vbforums. Do not specify any point more than once in each polygon's set of vertices. The function returns 1 if successful.100) (250.com | www.

' two polygons This page is copyright © 2000 Paul Kuliniewicz.com/ref/p/polypolygon.y = 250 ' 3rd point: (300.y = 250 ' 2nd point: (400.x = 400: points(5). numpoints(0).hDC.Windows API Guide: PolyPolygon Function points(5). Go back to the Reference section index. Go back to the Windows API Guide home page.92/vbapi/ref/p/polypolygon.html http://216. points(0).com Send Encrypted E-Mail This page is at http://www.250) numpoints(1) = 3 ' next three points identify the triangle ' Draw the two polygons retval = PolyPolygon(Form1. 2) See Also: Polygon Category: Filled Shapes Go back to the alphabetical Function listing. Copyright Information.26.x = 300: points(6).168. E-mail: vbapi@vbapi.html (2 of 2) [9/1/2002 5:37:59 PM] .vbapi.250) points(6).

y = 100 ' point #0: (100. (400.com | www.150) points(3).vbforums. just as the sets are not connected to each other. This function has a similar effect as using Polyline with various sets of points. Example: ' Draw a red triangle and a red parallelogram on window Form1. followed by those in the second set.y = 150 ' point #1: (200. The connecting lines are drawn in the object's current drawing color.x = 0: points(2). (350.com | PolyPolyline Function Declare Function PolyPolyline Lib "gdi32.26.com . Win NT PolyPolyline draws multiple sets of lines connecting points on a graphics-capable device.com | www. etc. Lines are drawn to connect the first point in a set to the second point.Windows API Guide: PolyPolyline Function vbapi. All of the points go into an array passed as lppt.100) points(1).100).vbsquare.vbapi.x = 100: points(3).y = 150 ' point #2: (0.vbworld. and (0.x = 200: points(1).92/vbapi/ref/p/polypolyline.com | www. Dim points(0 To 8) As POINT_TYPE ' the points in both sets Dim numpoints(0 To 1) As Long ' the number of points in each set Dim retval As Long ' return value ' Load the points for the triangle into the array. and (250. The point (100. Win 95/98.400). or 0 if an error occured.html (1 of 2) [9/1/2002 5:38:06 PM] .vbshop. points(0).300).150) points(2). The first and last points in a set are not connected. Note that since the first and last points ' are not connected.part of the VB-World Network | www. followed by those in the third set. The first element specified how many points are in the first set.300).dll" (ByVal hdc As Long. hdc The device context of the device to draw the lines on.x = 100: points(0). The ' triangle has corners (100. The function returns 1 if successful. This should have all of the points in the first set. etc.150).400). lppt As POINT_TYPE.y = 100 ' point #3: (100.100) is both the first ' and last points in order to close the figure. lpdwPolyPoints An array identifying how many points belong to each set. cCount The number of elements in lpdwPolyPoints. ByVal cCount As Long) As Long Platforms: Win 32s. the second point to the third.168. The parallelogram has corners ' (300. lppt An array holding all of the points in every set. etc.com | www.100) http://216. (200.150). lpdwPolyPoints As Long. the beginning point is also specified as the last point in order ' to close the figures.

The two are not mutually connected. numpoints(0).x = 250: points(7).html http://216. Form1. point #4: (300.400) point #8: (300. Polyline.300) point #6: (350.hDC.300) second set ' Load the points for the parallelogram points(4).vbapi. Copyright Information. This page is copyright © 2000 Paul Kuliniewicz.92/vbapi/ref/p/polypolyline.com Send Encrypted E-Mail This page is at http://www. points(0). 0.x = 350: points(6).Windows API Guide: PolyPolyline Function numpoints(0) = 4 ' number of points in first set in a similar fashion.y = 300 ' numpoints(1) = 5 ' number of points in ' Now.ForeColor = RGB(255.y = 300 ' points(6). 0) ' set Form1's drawing color to red retval = PolyPolyline(Form1.y = 300 ' points(5).y = 400 ' points(7).300) point #5: (400.26.168.x = 400: points(5). PolylineTo Category: Lines & Curves Go back to the alphabetical Function listing. finally draw both sets of points.com/ref/p/polypolyline.x = 300: points(8). E-mail: vbapi@vbapi.x = 300: points(4).html (2 of 2) [9/1/2002 5:38:06 PM] . 2) ' draw the lines See Also: LineTo.400) point #7: (250. Go back to the Reference section index.y = 400 ' points(8). Go back to the Windows API Guide home page.

vbsquare. Either box can be used to allow the user to select a printer and other settings. pNames As Long ' pointers to the memory blocks for the two DEV* structures Dim retval As Long ' return value of function ' First. load default settings into printmode. Example: ' Open a Print common dialog box. or a non-zero value if the user successfully pressed OK. see the example below. Win NT PrintDlg displays either the Print common dialog box or the Print Setup dialog box.dmOrientation = DMORIENT_PORTRAIT ' default to Portrait orientation http://216. To save space.168.Windows API Guide: PrintDlg Function vbapi. is used to provide the defaults. The function returns 0 if either an error occured or the user pressed Cancel. Carefully note how memory ' blocks are allocated to hold the two data structures containing information about the ' printer device. Dim pd As PRINTDLG_TYPE ' holds information to make the dialog box Dim printmode As DEVMODE ' holds settings for the printer device Dim printnames As DEVNAMES ' holds device.com | www.dmSize = Len(printmode) ' size of the data structure printmode. ' such as the printer name. referring to the default ' printer.vbworld.dmDeviceName = Printer.dmFields = DM_ORIENTATION ' identify which other members have information printmode. Visual Basic's Printer object.vbshop.92/vbapi/ref/p/printdlg. Of course. Then display certain selections the user made.com | www. handles to the memory blocks holding their data are required by the function.part of the VB-World Network | www. Note that instead of using the latter two structures explicitly. desired for a print operation.DeviceName ' name of the printer printmode. printmode.vbforums.26. such as the number of copies and the page range.vbapi.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLG_TYPE) As Long Platforms: Win 32s. and orientation.html (1 of 3) [9/1/2002 5:38:22 PM] . Information for initializing the dialog box as well as information returned from it is stored in the structure passed as pPrintdlg.com | www. API functions could also be used ' to get these defaults. Note that we only fill relevant information. and DEVNAMES structures for more details about using this function. DEVMODE. driver. pPrintdlg Stores both the dialog box's initialization settings and the information returned from the dialog box. Win 95/98.com | www. number of copies.com . and port names Dim pMode As Long. See the pages for the PRINTDLG_TYPE.com | PrintDlg Function Declare Function PrintDlg Lib "comdlg32.

Len(printmode) retval = GlobalUnlock(pd. pd. return device context: pd.DriverName) ' offset of printer name string devnames. This is explained on the DEVNAMES page.hDevNames) ' unlock the block ' Finally.hDevMode) CopyMemory printmode. Len(printmode) ' allocate memory block pMode = GlobalLock(pd.nMinPage = 1 ' allow user to select first page of "document" pd. Len(printnames) ' allocate memory block pNames = GlobalLock(pd.DeviceName & vbNullChar & Printer.nMaxPage = 15 ' let's say there are 15 pages of the "document" ' Note how we can ignore those members which will be set or are not used here. We'll ' set the pointers to the structures after this. Len(printnames) ' copy structure to memory block retval = GlobalUnlock(pd.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT. devnames.wDriverOffset = 8 ' offset of driver name string devnames. pd.lStructSize = Len(pd) ' size of structure pd.wOutputOffset = devnames. If retval <> 0 Then ' First. separated by null characters. This is almost identical ' to the code above where we did the reverse. pd. printmode. load strings for default printer into printnames.wDeviceOffset + 1 + Len(Printer. printnames.hDevNames) http://216. disable Print to File option.26.DriverName & vbNullChar & Printer.html (2 of 3) [9/1/2002 5:38:22 PM] . Note the unusual way in which such ' information is stored.hWnd ' window Form1 is opening the Print dialog box ' Flags: All Pages default. load the initialization settings into pd. Comments here are omitted for brevity. display some information about the selection. doesn't it? ' If the user hit OK. ' Copy the data in printmode and printnames into the memory blocks we allocate.92/vbapi/ref/p/printdlg.hDevNames) ' get a pointer to the block CopyMemory ByVal pNames.168. Len(printmode) ' copy structure to memory block retval = GlobalUnlock(pd.Windows API Guide: PrintDlg Function ' Next.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT. which is passed to the function.wDefault = 0 ' maybe this isn't the default selected printer ' Load the three strings into the buffer. we must copy the memory block data back into the structures.flags = PD_ALLPAGES Or PD_DISABLEPRINTTOFILE Or PD_RETURNDC pd.extra = Printer. devnames. pMode = GlobalLock(pd.wDeviceOffset = devnames.wDriverOffset + 1 + Len(Printer.hwndOwner = Form1. open the dialog box! retval = PrintDlg(pd) ' looks so simple.hDevMode) ' get a pointer to the block CopyMemory ByVal pMode.hDevMode) ' unlock the block ' Now do the same for printnames.Port) ' offset to output port string devnames. ByVal pMode.Port & vbNullChar ' Finally.hDevMode) pNames = GlobalLock(pd.

ByVal pNames.nCopies Debug.Print "Print pages".Print "Number of Copies:". Go back to the Reference section index.vbapi.92/vbapi/ref/p/printdlg. If printmode.html (3 of 3) [9/1/2002 5:38:22 PM] . Len(printnames) retval = GlobalUnlock(pd.26.nFromPage.com/ref/p/printdlg.Windows API Guide: PrintDlg Function CopyMemory printnames. pd.Print "Print all pages. we have to deallocate the memory blocks from before. printmode. pd.dmDeviceName Debug.Print "Printer Name: ".flags And PD_PAGENUMS) = PD_PAGENUMS Then ' user chose a page range Debug. pd. Go back to the Windows API Guide home page. display the information we want." Elseif (pd.com Send Encrypted E-Mail This page is at http://www.Print "Orientation: ".html http://216. E-mail: vbapi@vbapi.nToPage Else ' only one left is "All" Debug.dmOrientation = DMORIENT_PORTRAIT Then Debug.168.Print "Print the current selection." End If End If ' No matter what. Debug. We could instead use this info to print something.hDevMode) retval = GlobalFree(pd.hDevNames) Category: Common Dialog Go back to the alphabetical Function listing. This page is copyright © 2000 Paul Kuliniewicz.Print "Landscape" If (pd. "to". Copyright Information.hDevNames) ' Now.Print "Portrait" Else Debug. retval = GlobalFree(pd.flags And PD_SELECTION) = PD_SELECTION Then ' user chose "Selection" Debug.

26.com | PrinterProperties Function Declare Function PrinterProperties Lib "winspool. Windows 2000: Supported. ByVal hPrinter As Long) As Long Platforms q q q q q Windows 95: Supported. http://216.vbshop. If an error occured. and its look generally depends on the make and model of printer.vbforums. the function returns a non-zero value. Windows 98: Supported. The dialog box is opened when the user clicks the button cmdProperties. Windows NT: Requires Windows NT 3.com | www. Parameters hWnd A handle to the window opening the dialog box. Description & Usage PrinterProperties displays the Properties dialog box for a specific printer. hPrinter A handle to the printer to display the Properties dialog box for.168.com | www.vbapi. the function returns zero (use GetLastError to get the error code). first place a command button named cmdProperties on a form window. The dialog is opened modally -. To use the example.Windows API Guide: PrinterProperties Function vbapi.vbworld.com .your program pauses execution until the user exits the dialog.92/vbapi/ref/p/printerproperties.html (1 of 3) [9/1/2002 5:38:26 PM] .com | www.drv" (ByVal hWnd As Long. Example Display the Properties dialog box for the system's default printer. This dialog allows the user to configure the printer. Windows CE: Not Supported.com | www. Return Value If successful.1 or later. Visual Basic-Specific Issues None.part of the VB-World Network | www.vbsquare.

ReDim buffer(0 To bytesNeeded / 4 . numPrinters) ' Make sure we were successful. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.1) As Long ' Get information about the default printer.drv" Alias "EnumPrintersA" (ByVal flags As Long. 1. bytesNeeded. buffer(0).92/vbapi/ref/p/printerproperties. _ bytesNeeded.dll" Alias "lstrcpyA" (ByVal lpString1 As Any. pPrinterEnum As Long. _ ByVal lpString2 As Any) As Long Public Declare Function lstrlen Lib "kernel32. _ pcbNeeded As Long. http://216. retval = EnumPrinters(PRINTER_ENUM_DEFAULT. *** Private Sub Dim Dim Dim Dim Dim Dim Dim cmdProperties_Click() pi1 As PRINTER_INFO_1 bytesNeeded As Long numPrinters As Long buffer() As Long slength As Long hPrinter As Long retval As Long ' ' ' ' ' ' ' a little info about the printer size needed for buffer number of printers enumerated (should be 1) buffer for printer information length of string to copy handle to the printer generic return value ' Figure out how much space is needed to store the printer information. retval = EnumPrinters(PRINTER_ENUM_DEFAULT.) Public Type PRINTER_INFO_1 flags As Long pDescription As String pName As String pComment As String End Type Public Declare Function EnumPrinters Lib "winspool. vbNullString. phPrinter As Long.drv" (ByVal hPrinter As Long) As Long ' *** Place the following code inside a form window.Windows API Guide: PrinterProperties Function ' This code is licensed according to the terms and conditions listed here. _ ByVal name As String.html (2 of 3) [9/1/2002 5:38:26 PM] .26. ByVal hPrinter _ As Long) As Long Public Declare Function ClosePrinter Lib "winspool. numPrinters) ' Allocate that much space in the buffer array. ByVal cdBuf As Long. pDefault As Any) As Long Public Declare Function PrinterProperties Lib "winspool. vbNullString. bytesNeeded.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function OpenPrinter Lib "winspool. pcReturned As Long) As Long Public Const PRINTER_ENUM_DEFAULT = &H1 Public Declare Function lstrcpy Lib "kernel32. ByVal 0. 1.drv" (ByVal hWnd As Long. ByVal Level As Long.168.drv" Alias "OpenPrinterA" (ByVal pPrinterName _ As String. 0.

since the buffer holds pointers to them.pName = Space(lstrlen(buffer(2))) retval = lstrcpy(.com/ref/p/printerproperties. 2001 This page is copyright © 2001 Paul Kuliniewicz.pDescription.flags = buffer(0) ' Strings require more work.Print "No default printer or some other error.vbapi. hPrinter) ' Close the printer. retval = PrinterProperties(Me. . .168.pComment.html http://216.com Send Encrypted E-Mail This page is at http://www. Back to the Reference section. buffer(2)) . With pi1 ' Copy numerical data directly.pName. 2000 Go back to the Windows API Guide home page.Windows API Guide: PrinterProperties Function If retval = 0 Or numPrinters <> 1 Then Debug.hWnd.92/vbapi/ref/p/printerproperties. retval = OpenPrinter(pi1. buffer(1)) . Copyright Information Revised October 29." Exit Sub End If ' Copy the data into the structure.html (3 of 3) [9/1/2002 5:38:26 PM] .pComment = Space(lstrlen(buffer(3))) retval = lstrcpy(. E-mail: vbapi@vbapi.pName. buffer(3)) End With ' Open the printer. ByVal CLng(0)) If retval <> 0 Then ' Display the properties dialog.pDescription = Space(lstrlen(buffer(1))) retval = lstrcpy(.26. Last Modified: January 21. retval = ClosePrinter(hPrinter) Else Debug. hPrinter.Print "Unable to open printer!" End If End Sub Category Printers Back to the Function list.

html (1 of 3) [9/1/2002 5:38:31 PM] . Windows CE: Not Supported.com | www. Windows 98: Supported. Visual Basic-Specific Issues None.vbforums.vbworld.vbshop. Parameters hSnapshot A handle to the system snapshot created by the CreateToolhelp32Snapshot function. lppe Receives information about the first process in the snapshot.dll" (ByVal hSnapshot As Long.part of the VB-World Network | www.168. Windows NT: Not Supported.26. a http://216. Example Print a list of all the processes currently running on the computer when the user clicks button Command1. Return Value If successful. lppe As PROCESSENTRY32) As Long Platforms q q q q q Windows 95: Supported. the function returns a nonzero value.com . Description & Usage Process32First retrieves information about the first process in the process list contained in a system snapshot.92/vbapi/ref/p/process32first.Windows API Guide: Process32First Function vbapi. possibly if there is an empty or nonexistent process list in the snapshot. the function returns zero. To do this.com | www. The dwSize member of this structure must be initialized before calling the function. This snapshot must have previously been generated using the CreateToolhelp32Snapshot function. If an error occured.vbsquare.com | www.com | www.vbapi. Windows 2000: Supported. This snapshot contains the process list from which the first process is read.com | Process32First Function Declare Function Process32First Lib "kernel32.

To use this example.dll" (ByVal dwFlags As Long.dll" (ByVal hSnapshot As Long. ' This code is licensed according to the terms and conditions listed here. processInfo) ' Make sure a handle was returned.92/vbapi/ref/p/process32first. If hSnapshot = -1 Then Debug. The filename of the process and the number of threads owned by it is then displayed.168.26. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module. make a snapshot of the current process list.dll" (ByVal hSnapshot As Long. place a command button named Command1 on a form window. and then each process in it is analyzed. 0) ' Get information about the first process in the list. _ lppe As PROCESSENTRY32) As Long Public Declare Function Process32Next Lib "kernel32. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS.Windows API Guide: Process32First Function snapshot of the running process list is taken. processInfo.) Public Declare Function CreateToolhelp32Snapshot Lib "kernel32.dwSize = Len(processInfo) success = Process32First(hSnapshot.html (2 of 3) [9/1/2002 5:38:31 PM] .dll" (ByVal hObject As Long) As Long ' *** Place the following code inside a form window. _ lppe As PROCESSENTRY32) As Long Public Declare Function CloseHandle Lib "kernel32. *** Private Sub Dim Dim Dim Dim Dim Command1_Click() hSnapshot As Long ' handle to the snapshot of the process list processInfo As PROCESSENTRY32 ' information about a process in that list success As Long ' success of having gotten info on another process exeName As String ' filename of the process retval As Long ' generic return value ' First.Print "Unable to take snapshot of process list!" Exit Sub End If http://216. ByVal _ th32ProcessID As Long) As Long Public Const TH32CS_SNAPPROCESS = &H2 Public Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * 260 End Type Public Declare Function Process32First Lib "kernel32.

Last Modified: September 24.Print "Process: ".e. processInfo) Wend ' Destroy the snapshot. if there is one. exeName Debug.szExeFile.html (3 of 3) [9/1/2002 5:38:31 PM] . 2000 This page is copyright © 2000 Paul Kuliniewicz. Back to the Reference section. processInfo.dwSize = Len(processInfo) success = Process32Next(hSnapshot.cntThreads ' Get information about the next process. InStr(processInfo. processInfo. now that we no longer need it. Copyright Information Revised October 29.Windows API Guide: Process32First Function ' Loop for each process on the list.Print " .26.Number of threads:". retval = CloseHandle(hSnapshot) End Sub See Also Process32Next Category Tool Help Back to the Function list.szExeFile. Debug.. 2000 Go back to the Windows API Guide home page.com Send Encrypted E-Mail This page is at http://www.vbapi. While success <> 0 ' Extract the filename of the process (i.168.com/ref/p/process32first. remove the empty space) exeName = Left(processInfo.1) ' Display the process name and the number of threads it owns.html http://216. vbNullChar) . E-mail: vbapi@vbapi.92/vbapi/ref/p/process32first.

com .vbshop.com | Process32First Function Declare Function Process32Next Lib "kernel32. after an initial call to Process32First.html (1 of 3) [9/1/2002 5:38:35 PM] . Windows 98: Supported.com | www. the function returns zero. The dwSize member of this structure must be initialized before calling the function.vbworld.168. Calling this function repeatedly.com | www. Windows 2000: Supported. Return Value If successful. Windows CE: Not Supported. most likely if there are no more unread processes in the list.part of the VB-World Network | www.26. Description & Usage Process32Next retrieves information about the next unread process in the process list contained in a system snapshot. Visual Basic-Specific Issues None. lppe Receives information about the next unread process in the snapshot. Parameters hSnapshot A handle to the system snapshot created by the CreateToolhelp32Snapshot function. the function returns a nonzero value.vbforums. Example http://216. will allow your program to read the entire process list. This snapshot contains the process list from which the next unread process is read.com | www.Windows API Guide: Process32Next Function vbapi.vbsquare.vbapi.92/vbapi/ref/p/process32next.com | www. lppe As PROCESSENTRY32) As Long Platforms q q q q q Windows 95: Supported.dll" (ByVal hSnapshot As Long. Windows NT: Not Supported. This snapshot must have previously been generated using the CreateToolhelp32Snapshot function. If an error occured.

dwSize = Len(processInfo) success = Process32First(hSnapshot. The filename of the process and the number of threads owned by it is then displayed. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.dll" (ByVal hSnapshot As Long. processInfo. _ lppe As PROCESSENTRY32) As Long Public Declare Function Process32Next Lib "kernel32.dll" (ByVal hObject As Long) As Long ' *** Place the following code inside a form window. *** Private Sub Dim Dim Dim Dim Dim Command1_Click() hSnapshot As Long ' handle to the snapshot of the process list processInfo As PROCESSENTRY32 ' information about a process in that list success As Long ' success of having gotten info on another process exeName As String ' filename of the process retval As Long ' generic return value ' First. _ lppe As PROCESSENTRY32) As Long Public Declare Function CloseHandle Lib "kernel32. ByVal _ th32ProcessID As Long) As Long Public Const TH32CS_SNAPPROCESS = &H2 Public Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * 260 End Type Public Declare Function Process32First Lib "kernel32.168. and then each process in it is analyzed. 0) ' Get information about the first process in the list. a snapshot of the running process list is taken. place a command button named Command1 on a form window.) Public Declare Function CreateToolhelp32Snapshot Lib "kernel32. processInfo) ' Make sure a handle was returned.html (2 of 3) [9/1/2002 5:38:35 PM] .26.dll" (ByVal hSnapshot As Long. To do this.92/vbapi/ref/p/process32next. ' This code is licensed according to the terms and conditions listed here. make a snapshot of the current process list.Windows API Guide: Process32Next Function Print a list of all the processes currently running on the computer when the user clicks button Command1. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS.dll" (ByVal dwFlags As Long. If hSnapshot = -1 Then Debug.Print "Unable to take snapshot of process list!" Exit Sub End If http://216. To use this example.

2000 This page is copyright © 2000 Paul Kuliniewicz.168. Copyright Information Revised October 29. remove the empty space) exeName = Left(processInfo. Last Modified: September 24. if there is one.92/vbapi/ref/p/process32next. now that we no longer need it. Back to the Reference section.vbapi.szExeFile.. InStr(processInfo. processInfo. 2000 Go back to the Windows API Guide home page.dwSize = Len(processInfo) success = Process32Next(hSnapshot. retval = CloseHandle(hSnapshot) End Sub See Also Process32First Category Tool Help Back to the Function list.com Send Encrypted E-Mail This page is at http://www.e.Print " .1) ' Dis