Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Give Focus To Another 16-Bit Application In NT

Note that in writing in VB3.0, Visual Basic's AppActivate statement fails 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 the 16-bit Windows subsystems may not be fully available to other 16-bit programs. To work around this, use the FindWindow and SetWindowPos Windows API functions like 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 Form Click 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, _
	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 the form to activate Notepad. When finished, close the form to end the Visual Basic program.
Douglas Haynes
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date