Click to See Complete Forum and Search --> : Sending application to front
webnetworks
August 30th, 2001, 03:55 AM
Hi,
We have two applications, one for logging information and one DOS application that starts in a DOS-box.
What we want is that the logging application is always the top window when the DOS box is started (the logging application starts with Windows and can't be shutdown by the user).
How can this be done. I know it has something to do with ordering Windows.
Thanks for your time
Jeroen van den Bergh
DSJ
August 30th, 2001, 08:23 AM
Use the SetWindowPos api:
option Explicit
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
private Declare Sub 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)
private Sub Form_Activate()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'set the window position to topmost
SetWindowPos me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
webnetworks
August 30th, 2001, 10:52 AM
Hi,
This is not what I mean. Both applications are not programmed by me. I want to create an app running in the system tray (that's already done) that checks for the given application names (given from e.g. the command line, so can be variable).
It should be like this:
- App.One is started with Windows startup
- App.Two is started when the user wants to use the application
- The new application that controls the topmost Windows (this is were it's all about)
App.One is not necesseraly the topmost Window when started. When App.Two starts, App.One must become the topmost Window. This should be detected and controlled by the systray app that I want to create.
Jeroen
DSJ
August 30th, 2001, 11:31 AM
Your systray app will need to get the window handle of App.One somehow so it can send it the message to become the front window. You'll need to use either the EnumWindows API or FindWindow API to locate App.One, etc.
webnetworks
September 3rd, 2001, 12:49 PM
Okay,
That part I figured out myself, but how to do this?
Let's say both applicationnames are variables, how do I search with these API's to find a window or app. that's called like the name given?
Thanks for your support.
Jeroen.
DSJ
September 4th, 2001, 10:09 AM
option Explicit
private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string) as Long
private Sub Command1_Click()
Dim hWnd1 as Long
Dim hWnd2 as Long
Dim strWindow1 as string
Dim strWindow2 as string
strWindow1 = "Form1"
strWindow2 = "Form2"
hWnd1 = FindWindow(vbNullString, strWindow1)
hWnd2 = FindWindow(vbNullString, strWindow2)
MsgBox hWnd1 & " " & hWnd2
'Return value 0 means window not found...
End Sub
webnetworks
September 4th, 2001, 10:22 AM
Thanks for the support. This is just what I needed, it works fine now (in combination with topic found earlier to send a window to the front).
Jeroen van den Bergh
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.