Click to See Complete Forum and Search --> : detecting Windows(or its name) in VB and use it in other program


September 20th, 1999, 02:41 PM
Is it possible to write a VB program that detects the name of a window and use it to interact with that window(finding captions or clicking buttons)?
What API functions should I use?

Vlad Chapranov
September 20th, 1999, 03:47 PM
Try this:

Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string)



It will return you a handle of window. As a parameters you can use either Caption of window or Window Class. Window Class of particular window you can find using Spy++ wich comes with VB (with Enterprise edition for sure). Example of finding MS Word:
lngHandle = FindWindow("OpusApp", vbNullString)
Example when you know Caption:
lngHandle = = FindWindow(vbNullString,"MyWindow")
HTH
Vlad