Solved

Making the background application be a foreground one.

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

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