Solved

Controlling other programs thru vb5

Posted on 1998-10-05
6
274 Views
Last Modified: 2010-04-30
I want to read and then change the url a web page in an iexplorer window.  For example, if the vb5 program reads that ie4 is at www.disney.com, I want the vb5 program to change it and take me to www.mtv.com
In other words, I want to modify an external program's properties and manipulate its methods.  I know a little about api calls.
0
Comment
Question by:Armandito
  • 3
  • 2
6 Comments
 

Author Comment

by:Armandito
ID: 1438348
Edited text of question
0
 
LVL 1

Expert Comment

by:abhinavm
ID: 1438349
You can do it very easily. goto menu project -> reference then select the application name you want to control if application name is not there you can't control that app. for example controlling MS word you need Microsoft word 8.0 object library.
 if it is present then select it and press OK.
now you can useobjects define in library. i will give you example of word. add this code in command click event.

Dim WordApp As Word.Application
set WordApp=new Word.Application
WordApp.Activate
WordApp.Documents.Open "DocName"
WordApp.Documents.Close
WordApp.Quit

This code will start MSWord then open document given in paramtere to open method. then close that document and quit word. you can do other stuff also with that document
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 200 total points
ID: 1438350
You are lucky. Here is the code that works with IE3.
It searches the IE4 window and the editbox within the toolbar
then it retrieves the text and modifies the text

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Const WM_GETTEXT = &HD
Const WM_SETTEXT = &HC
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Sub Command1_Click()
    Dim hwndexpl As Long
    Dim hwndrebar As Long
    Dim hwndcomboex As Long
    Dim hwndcombo As Long
    Dim hwndsizerebar As Long
    Dim hwndedit As Long
    Dim editval As String
    'Find top level window of classs IEFrame with no caption
    hwndexpl = FindWindow("IEFrame", 0)
    hwndsizerebar = FindWindowEx(hwndexpl, 0, "SizableReBar", "")
    hwndrebar = FindWindowEx(hwndsizerebar, 0, "ReBarWindow32", "")
    hwndcomboex = FindWindowEx(hwndrebar, 0, "ComboBoxEx32", "")
    hwndcombo = FindWindowEx(hwndcomboex, 0, "ComboBox", "")
    hwndedit = FindWindowEx(hwndcombo, 0, "Edit", "")
    editval = String$(255, " ")
    Call SendMessageStr(hwndedit, WM_GETTEXT, 255, editval)
    editval = RTrim(editval)
    editval = Left(editval, Len(editval) - 1)
    If (editval = Text1.Text) Then
       Call SendMessageStr(hwndedit, WM_SETTEXT, 0, Text2.Text)
    End If
   
End Sub

0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:Armandito
ID: 1438351
Thanks Mirkwood.  
I tried the code, and it almost worked.  I had to tweak it a bit, though.  The RTrim function wasn't having any effect on editval, for some reason.  I replaced RTrim with a small routine that returns the what it should.  In the end, the program does put text2.text in the url address window.
The shortcoming of your answer is in that the browser does not take you there.  In other words, the program does detect if I am at www.disney.com, and the program changes the address to www.mtv.com, but it does not open www.mtv.com.  It just changes the text of the url window.  So your answer was great, but only half of what I need.
I tried for a few hours last night to make the program send a message that simulates an ENTER keypress (after having changed the url text).  I tried to use some of the API functions, but it didn't work.  Maybe I'm doing it wrong.  
I need more help.
Thanks!
Armandito
0
 

Author Comment

by:Armandito
ID: 1438352
Thanks Mirkwood.  
I tried the code, and it almost worked.  I had to tweak it a bit, though.  The RTrim function wasn't having any effect on editval, for some reason.  I replaced RTrim with a small routine that returns the what it should.  In the end, the program does put text2.text in the url address window.
The shortcoming of your answer is in that the browser does not take you there.  In other words, the program does detect if I am at www.disney.com, and the program changes the address to www.mtv.com, but it does not open www.mtv.com.  It just changes the text of the url window.  So your answer was great, but only half of what I need.
I tried for a few hours last night to make the program send a message that simulates an ENTER keypress (after having changed the url text).  I tried to use some of the API functions, but it didn't work.  Maybe I'm doing it wrong.  
I need more help.
Thanks!
Armandito
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1438353
Do a setfocus before the sendkey

Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

prevHwnd  = SetFocus (hwndedit)
Sendkeys here
SetFocus (prevHwnd)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 64
VB 6.0 printer how to align 6 62
VBS file using code from 2nd file (txt or vbs) 4 36
Hide vba in gp 7 94
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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