Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you get list of windows that are loaded

Status
Not open for further replies.

Cresby

Programmer
Aug 15, 2002
287
GB
I load a Teletext app from my VB6 because the Teletext insists on correcting the system clock even when de-selected (a bug). I have to check to see if the Teletext app has been "exitted" so that my VB6 can unload itself. The only way I can do this is to effectively to focus on the window which causes an error if the window has been unloaded. That bit works fine but it means that the Teletext pops-up in front of the TV every minute. If I had a list of windows all I would have to do is look for the "apploadnumber" without re-focussing.

any ideas? API's - URL's? speciffically for this?
I have looked for it here but what words phrases should I dial-in?
 
Hi,

Try this by starting a new project add a command button and a module (form) to the project. This is currently set to work by looking for the Calculator program. Using a timer, you can set your program to look for the program you need to kill... or some other means. I have taken this code from a website AllAPI.net - check it out. It's a great source.

Put this code in a module:

Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Put this in your form:

Private Sub Command1_Click()
Dim lRet

lRet = FindWindow(vbNullString, "Calculator")

If lRet > 0 Then 'if this window is there
'activate the app you wish to kill
AppActivate "Calculator"
'this is the name in titlebar
SendKeys "^{BREAK}", False
SendKeys "%{F4}", False
'kill/close this app
lRet = FindWindow(vbNullString, "Calculator")
SendMessage lRet, 16, 0, 0
End If
End Sub
 
FindWindow API function would be better

FindWindow - pass it the class name or titlebar text and it returns the window handle.

IsWindow - pass it the handle and it returns True/False

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

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

Function fIsWindow(ByVal strWindowName As String) As Boolean
  
 Dim hWnd As Long

 hWnd = FindWindow(vbNullString, strWindowName)
 'or if strClassName were the parameter
 'hWnd = FindWindow(strWindowName, vbNullString)
 If Not hWnd = 0 Then
  fIsWindow = True
 End If

End Function

There's a free utility, WinSpy, at my web site which lets you view open windows in an Explorer interface and shows properties such as the class name.

A more efficient way, if this suits your app, is to launch the teletext app and pause the VB app until the teletext app is closed. Then you don't have to constantly poll for its window. Details at
Paul Bent
Northwind IT Systems
 
Thanx. I have the page archived. Scratches head and peruses offline..........
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top