Link to home
Start Free TrialLog in
Avatar of nksraja
nksraja

asked on

control ie in vb programming

I am Programming in VB6,and window os.I want to run automaticaly my program.exe when the user open the Internet explore.if my program allows the user to use the explore then only the user can access the net if not the internet explore shoud close.

I don't no how to contol the ie?
please give me the solution as soon as posible.
ASKER CERTIFIED SOLUTION
Avatar of roverm
roverm
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi nksraja, you closed this question without any comment.
What do you want me to do? Do you want the example?
Avatar of alibabas
alibabas

roverm...
can you provide the code.. as I am looking for something similar.. and I would appreciate the code..
I have subscribed to the questino.. and currently.. I don't have anypoint to give.. as I am already putting all my points toward another question.. maybe you can help there.?? the link is:
https://www.experts-exchange.com/questions/20786460/VB6-Access-Timed-scehduler.html#9736383

Thanks.
Ok, here you go.
First the main function and declarations. Place it in a module.

Option Explicit

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpclassname As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Const WM_CLOSE = &H10

Public colHandles As Collection
Public hwnd As Long
Public iCounter As Integer

Public Function EnumWindowsProc(ByVal hwnd As Long, _
  ByVal lParam As Long) As Boolean
Dim sName As String
Dim lRet As Long

    If colHandles Is Nothing Then _
        Set colHandles = New Collection
   
    sName = Space(256)
    lRet = GetClassName(hwnd, sName, 256)
    sName = UCase(Left$(sName, lRet))
    If sName = "IEFRAME" Then
        iCounter = iCounter + 1
        colHandles.Add CStr(hwnd), CStr(hwnd)
    End If
    EnumWindowsProc = True

End Function

In this function each found IE will be added to the colHandles collection.
This way you can use it later if you want to do something with the open windows, like closing them all:

Public Sub CloseAll()
Dim i As Integer
Dim sHandle As String

    Set colHandles = Nothing
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
   
    For i = 1 To colHandles.Count
        sHandle = colHandles(i)
        PostMessage CLng(sHandle), WM_CLOSE, 0, 0
    Next i
    Set colHandles = Nothing
    iCounter = 0
   
End Sub

To get all windows you need to add this to your Main Form:

EnumWindows AddressOf EnumWindowsProc, ByVal 0&

That's one part.

If you want to know whether a new window has opened you need to monitor the SHDOCVW.
Set a reference to 'Microsoft Internet Controls'.
Then add this to the top of your main form:

Public WithEvents shIE As SHDocVw.ShellWindows

Then add these events:

Private Sub shIE_WindowRegistered(ByVal lCookie As Long)
    iCounter = iCounter + 1
    'increment the counter
End Sub

Private Sub shIE_WindowRevoked(ByVal lCookie As Long)
    iCounter = iCounter - 1
    'dec counter
End Sub

D'Mzz!
RoverM
Avatar of nksraja

ASKER

Nice,excellent