|
-
Jan 29th, 2002, 01:43 PM
#1
Can VBS detect classname & title text ?
Hi
I want to detect the Internet Explorer's title text by VBS.
example:
When page1 is loaded, VBS should recognize the title
text and send another "Sendkey" sequence as when page2 is loaded in Internet Explorer.
Can VBS read the different title text ?
-
Jan 29th, 2002, 01:44 PM
#2
Black Cat
You should be able to get the <title> tag via HTML DOM.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jan 29th, 2002, 03:29 PM
#3
Fanatic Member
You'll need to find all the IE instances or your program's instances with FindWindowEx or EnumWindows. Then you can use GetWindowText to find out what the text is for each of the above windows. You'll want to use SendMessage with WM_Keydown and WM_Keyup to do the key pressing.
-
Jan 29th, 2002, 04:35 PM
#4
I only can use FindWindowEx in Visual Basic, but not
in VBS.
So, when i want to read window titles, i think i have to use
VB.
VBS can not do that - am i right?
(i only want to know if VBS can do that, or not)
-
Jan 29th, 2002, 05:32 PM
#5
Hyperactive Member
One of the problems with IE is that you cannot use the traditional GetObject on it and technially, every window opened by the operating system is a version of IE, though this version does not use the Application object. Anyway, to get what you want, you have to enumerate the windows that are opened, and read their titles. The code snippet below will locate any window that has VB in the browser's title. Basically, what it does is trap an error (I believe 438) to see if the Shell object supports the properties that I am asking for.
Code:
Dim objShell, objShellWindows, objWindow, objIEApp
Dim x , lng_Count
x=0
Set objShell = WScript.CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
lng_Count = objShellWindows.Count
For x=0 to lng_Count
On error Resume Next
Set objWindow = objShellWindows.Item(x)
'Every item here represents one instance of IE. If you have 3 instances open then you can get anyone of them by specifying 0,1 0r 2. You can get the count from objShellWindows.Count
Set objIEApp = objWindow.Application 'get the application object
if Instr(objIEApp.document.title, "VB")<>0 then
if Err=0 then
msgbox objIEApp.document.title
Exit For
Else
Err.number=0
End if
End if
Next
msgbox "Finished"
Hope this helps.
-
Jan 29th, 2002, 06:16 PM
#6
So, you have solved my problem.
I can use VBScript to detect **any** main window title
of an Internet Explorer application.
The last question would be:
Can i detect the window titles of other programs too (notepad, bestcrypt, paint shop pro .. ) (?)
-
Jan 29th, 2002, 06:52 PM
#7
Fanatic Member
Put this code in a .bas module:
VB Code:
Option Explicit
Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function IsWindowEnabled Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function GetParent Lib "user32" _
(ByVal hwnd As Long) As Long
Public Const MAX_PATH = 260
Public Function EnumWindowProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sTitle As String
Dim sClass As String
'eliminate windows that are not top-level.
If GetParent(hwnd) = 0& And _
IsWindowVisible(hwnd) And _
IsWindowEnabled(hwnd) Then
GetWindowInfo hwnd, sTitle, sClass
'add the items to the list
Form1.List1.AddItem sTitle & " (" & sClass & ")"
Form1.List1.ItemData(Form1.List1.NewIndex) = hwnd
End If
'To continue enumeration, return True
'To stop enumeration return False (0).
'When 1 is returned, enumeration continues
'until there are no more windows left.
EnumWindowProc = 1
End Function
Public Sub GetWindowInfo(hwnd As Long, Optional sTitle As String, Optional sClass As String)
'set up the strings to receive the class and window text
sTitle = Space$(MAX_PATH)
sClass = Space$(MAX_PATH)
Call GetClassName(hwnd, sClass, MAX_PATH)
Call GetWindowText(hwnd, sTitle, MAX_PATH)
'strip the trailing chr$(0)'s from the strings returned above
sClass = TrimNull(sClass)
sTitle = TrimNull(sTitle)
End Sub
Public Function TrimNull(s As String)
'remove string before the terminating null(s)
Dim pos As Long
pos = InStr(s, Chr$(0))
If pos Then
TrimNull = Left$(s, pos - 1)
Else
TrimNull = s
End If
End Function
Public Sub InitEnumWindows()
EnumWindows AddressOf EnumWindowProc, &H0
End Sub
Put this code inside form1, along with a list1 and command1:
VB Code:
Option Explicit
Private Sub Command1_Click()
List1.Clear
InitEnumWindows
End Sub
The title will appear first, the window's class is in parentheses.
-
Jan 29th, 2002, 07:27 PM
#8
-
Jan 29th, 2002, 07:48 PM
#9
Fanatic Member
VBS really isn't designed for this... what are you trying to do?
-
Jan 29th, 2002, 08:18 PM
#10
1
i'm wondering about VBS that can send keystrokes to every
app, like:
set ws = CreateObject("Wscript.shell")
ws.sendkeys("Hello!")
..but it doesn't recognize to which window it sends the keystrokes.
=============================================
2
On the desktop, i created a F9-hotkey-link to a vbs file.
-No matter which program runs, when i press F9, the vbs
file starts.
The vbs-code should detect, if Bestcrypt is running
(and if possible weather Bestcrypt's window is the foregroundwindow)
or iE is running (and if possible weather iE's window is the foregroundwindow).
-When iE is running, it sends Loginname/Password to the iE application.
-When it detects that Bestcrypt.exe is running, it should send
1xTab and the passwordphrase to the Bestcrypt window.
-The problem is that VBS does not recognice, if it sends the
keystrokes to the Internet Explorer or to the Bestcrypt
application.
But i only have *one* F9 hotkey, and therefore the VBS-code
*MUST* distinguish between these different apps.
============
That's the prob. (i know that i can use VB for it, but that's not my question)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|