devxlogo

Give Focus To Another 16-Bit Application In NT

Give Focus To Another 16-Bit Application In NT

Note that in writing in VB3.0, Visual Basic’s AppActivate statementfails to make a 32-bit application the active window under Windows NT.For example:

 Sub Form_Load ()	AppActivate "Notepad - (Untitled)"End Sub

Visual Basic fails to give focus to the Notepad session because the16-bit Windows subsystems may not be fully available to other 16-bit programs.To work around this, use the FindWindow and SetWindowPos Windows API functionslike this: 1. Start a new project in Visual Basic. Form1 is created by default.2. Double-click on the form to open the code window. Select (general)from the Object box. Enter the following in the (general) (declarations)window:

 Declare Function FindWindow% Lib "USER" _	(ByVal Class&, ByVal Caption$)' The following Declare statement must be on one line:Declare Sub SetWindowPos Lib "user" _	(ByVal hwnd%, ByVal hwndAfter%, _	ByVal x%, ByVal y%, ByVal cx%, _	ByVal cy%, ByVal swp%)

3. Select Form from the Object box. Add the following code to the FormClick event:

 Sub Form_Click ()	Const SWP_NOSIZE% = &H1	Const SWP_NOMOVE% = &H2	AppActivate "Notepad - (Untitled)"	x = FindWindow(0, "Notepad - (Untitled)")	SetWindowPos x, 0, 0, 0, 0, 0, _		SWP_NOSIZE Or SWP_NOMOVE	Debug.Print Hex$(x) 	' Print return code from 	' FindWindow API function.End Sub

4. Start Notepad in Windows NT. 5. Start the Visual Basic program, or press the F5 key. Click on theform to activate Notepad. When finished, close the form to end the VisualBasic program.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist