Article ID: 109262
Article Last Modified on 10/29/2003
APPLIES TO
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q109262
SYMPTOMS
Visual Basic's AppActivate statement fails to make a 32-bit application the active window under Windows NT.
To reproduce this behavior under Microsoft Windows NT, run Notepad (NOTEPAD.EXE). Then run the following code in Visual Basic:
Sub Form_Load () AppActivate "Notepad - (Untitled)" End Sub
Visual Basic fails to give focus to the Notepad session.
CAUSE
Under the 32-bit Windows NT system, 16-bit Windows-subsystem applications may not be fully available to other 16-bit programs. Visual Basic version 3.0 is a 16-bit program originally designed for the 16-bit Windows operating environment, so this behavior is by design.
WORKAROUND
To work around this behavior, use the FindWindow and SetWindowPos Windows API functions as follows:
- Start a new project in Visual Basic. Form1 is created by default.
Double-click 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, single line: Declare Sub SetWindowPos Lib "user" (ByVal hwnd%, ByVal hwndAfter%, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, ByVal swp%)
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, SWP_NOSIZE Or SWP_NOMOVE Debug.Print Hex$(x) ' Print return code from FindWindow API function. End Sub
- Start Notepad in Windows NT version 3.1.
- Start the Visual Basic program, or press the F5 key. Click the form to activate Notepad. When finished, close the form to end the Visual Basic program.
STATUS
This behavior is by design. It is under review and will be considered for enhancement in a future release of Visual Basic.
Additional query words: 3.00
Keywords: kbprb KB109262