Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 43,956 times

Contents

Related Categories

API Programming Series #3 - Bring a Window to Top - The code

sreejath

The code

As usual we start with the API declaration.

Create a new VB Standard EXE project.

When you created the project, a form Form1 should have been added to the project by default. Add another form to the project. Since this is only an example to illustrate the above API call, we'll not change the properties of the forms. So now we have two forms named Form1 and Form2 in the project. Add a command button each to both the forms. Leave their names as Command1 itself.

In the General | Declarations section of both the forms, type in the following code

Private Declare Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

In the Click event procedure of the button on Form1 add the following code:

Private Sub Command1_Click ()
   BringWindowToTop Form2.hwnd
End Sub

In the Click event procedure of the button on Form2 add the following code:

Private Sub Command1_Click ()
   BringWindowToTop Form1.hwnd
End Sub

Now in the load event of Form1 (which should be the default form of the project add the following code.

Private Sub Form_Load ()
Form2.Show
End Sub

Comments

  • Posted by sreejath on 31 Mar 2003

    Are you using IE?

  • Well, almost...

    Posted by mef on 25 Feb 2003

    Using VB6 in Windows 2000 this function brings my window to the top of other application windows, but will not bring it above a browser window. Any suggestions?

  • another nice 1

    Posted by fanen on 10 Jan 2003

    i've always used "form1.setfocus"....and most times, it just blinked the app in the taskbar...