Solved

Making the background application be a foreground one.

Posted on 2001-09-04
3
268 Views
Last Modified: 2008-03-06
Our Customer wanted to be upgraded from Win NT to Windows 2000.

We have 2 Applications, the Foreground one and the Background one, so to speak.  The Foreground one calls the background one that is supposed to display a UI for the User and became an Active.  We use an API call SetForegroundWindow for this.  It worked well with Win NT.  When using Windows 2000, it only shows that UI flashing on a task bar and User has to bring it up manually, if that UI not modal.  If UI IS modal, User simply doesn't see it.  These 2 applications are VB applications and worked fine in Win NT.

How do we make it work in Win 2000 with minimal efforts?  Any ideas?

Thanks!

0
Comment
Question by:MayaP
  • 3
3 Comments
 
LVL 4

Expert Comment

by:wileecoy
ID: 6455238
Try this api call.

In a module copy-paste:

Public Declare Function SetWindowPos _
                Lib "user32" _
               (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
                ByVal x As Long, ByVal y As Long, _
                ByVal cx As Long, ByVal cy As Long, _
                ByVal wFlags As Long) As Long

Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

'Constants for topmost.
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE



In the usage in Form_Load:

Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)



I also added other constants to use.

hth.

Wileecoy.
0
 
LVL 4

Accepted Solution

by:
wileecoy earned 40 total points
ID: 6455300
Alternatively, Microsoft has an example at:




Open a standard exe and add 3 command buttons (command1, command2, command3)  Then copy-paste the following code to Form1.


******** begin code Form1

     Option Explicit
      Dim THandle As Long

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

      Private Declare Function FindWindow Lib "user32" Alias _
         "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName _
         As Any) As Long

      Private Sub Form_Load()
         Command1.Caption = "Run the Calculator"
         Command2.Caption = "Find Calculator's Handle"
         Command3.Caption = "Bring Calculator To The Top"
         Command2.Enabled = False
         Command3.Enabled = False
      End Sub

      Private Sub Command1_Click()
         Dim X As Long
         X = Shell("Calc.exe", 1)
         If X <> 0 Then
            Command2.Enabled = True
         End If
      End Sub

      Private Sub Command2_click()
         THandle = FindWindow(vbEmpty, "Calculator")
         If THandle = 0 Then
            Command3.Enabled = False
            MsgBox "Sorry, the calculator is running"
            Exit Sub
         End If
         Command3.Enabled = True
      End Sub

      Private Sub Command3_click()
         Dim iret As Long
         iret = BringWindowToTop(THandle)
      End Sub


******** end code Form1


hth.


Wileecoy.

0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6471769
Glad to help - Thanks.

Wileecoy.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now