?
Solved

Making the background application be a foreground one.

Posted on 2001-09-04
3
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 160 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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