Windows API Guide: GetWindowRect Function


Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As INITCOMMONCONTROLSEX_TYPE) As Long

Platforms

  • 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

InitCommonControlsEx registers the window classes used to create various common controls. This function must be called before using CreateWindowEx to create a common control.

Return Value

If successful, the function returns a non-zero value. If an error occured, the function returns zero.

Visual Basic-Specific Issues

None.

Parameters

lpInitCtrls
Specifies which common control classes to register.

Example

Create an IP Address control and use it to prompt the user for an IP address. When the user clicks button cmdGetDomain, the program looks up the first domain name assigned to that address.

To use this example, place a command button named cmdGetDomain on a form window. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand.

' 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 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, lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup 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 htonl Lib "wsock32.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal length As Long, ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source _ As Any, 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" Alias "lstrcpyA" (ByVal lpString1 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" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, _ ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x _ As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, _ ByVal hMenu As Long, ByVal hInstance 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.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg _ As Long, wParam As Any, lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window. *** Private hIPControl As Long  ' handle to the IP Address control ' When the form is initialized, create an IP Address control in the ' upper-left corner of the form. 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. With comctls .dwSize = Len(comctls) .dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. hIPControl = CreateWindowEx(0, WC_IPADDRESS, "", WS_CHILD Or WS_VISIBLE, 0, 0, 125, 20, _ Me.hWnd, 0, App.hInstance, ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. 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. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long   ' the IP address, in host byte order Dim ipAddress_n As Long   ' the IP address, in network byte order Dim sockinfo As WSADATA   ' information about the Winsock implementation Dim pHostinfo As Long     ' pointer to information about the host computer Dim hostinfo As HOSTENT   ' information about the host computer 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. retval = SendMessage(hIPControl, IPM_ISBLANK, ByVal CLng(0), 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. retval = SendMessage(hIPControl, IPM_GETADDRESS, ByVal CLng(0), ipAddress_h) If retval < 4 Then Debug.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2.2 session. retval = WSAStartup(&H202, sockinfo) If retval <> 0 Then Debug.Print "ERROR: Attempt to open Winsock failed: error"; retval Exit Sub End If ' Convert the IP address into network byte order. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer. pHostinfo = gethostbyaddr(ipAddress_n, 4, AF_INET) If pHostInfo = 0 Then Debug.Print "Could not find a host with the specified IP address." Else ' Copy the data into the structure. CopyMemory hostinfo, ByVal pHostinfo, Len(hostinfo) ' Copy the host domain name into a string. domainName = Space(lstrlen(hostinfo.h_name)) retval = lstrcpy(domainName, hostinfo.h_name) Debug.Print "Domain name is: "; domainName End If ' End the Winsock session. retval = WSACleanup() End Sub

Category

Common Controls

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


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/i/initcommoncontrolsex.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net