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
Solved

Making the background application be a foreground one.

Posted on 2001-09-04
3
273 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

840 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