Windows API Guide: RegQueryValueEx Function


Declare Function SetFocusAPI Lib "user32.dll" Alias "SetFocus" (ByVal hWnd As Long) 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

SetFocus gives a window the input focus. The window must be owned by the thread calling the function, however -- the function will not set the focus to another program's window.

Return Value

If successful, the function returns a handle to the window that previously had the input focus. If an error occured, the function returns zero (use GetLastError to get the error code).

Visual Basic-Specific Issues

This function behaves exactly like the SetFocus method of many VB controls. However, because this function shares its name with this method, it must be renamed to something like SetFocusAPI when you use it in a VB program, or else the compiler will give you an error. See the example for a demonstration of this.

Parameters

hWnd
A handle to the window to give the input focus.

Example

When the form loads, immediately give button cmdGetsFocus the keyboard focus. Although an easier way to do this is through the button's SetFocus method, the API function is useful if you only have a handle to the window you want to give the focus. To use this example, you must place a button named cmdGetsFocus 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 SetFocusAPI Lib "user32.dll" Alias "SetFocus" (ByVal hWnd As Long) As Long ' *** Place the following code inside a form window. *** Private Sub Form_Load() Dim retval As Long  ' return value ' Give the input focus to cmdGetsFocus right away. retval = SetFocusAPI(cmdGetsFocus.hWnd) End Sub

See Also

GetFocus

Category

Windows

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


Last Modified: December 17, 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/(?/name).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