Link to home
Start Free TrialLog in
Avatar of SRG041808
SRG041808Flag for United States of America

asked on

how do I get IE to open maximized?

The code attached works fine the way it is... I just need IE to open maximized, not full screen or theater mode.
Option Strict Off
Option Explicit Off
Module Module1
 
    Public Const MOUSEEVENTF_MOVE As Integer = &H1
    Public Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    Public Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Public Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000
    Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
 
    Public Sub Main()
        Dim Window
        Window = CreateObject("InternetExplorer.Application")
        PWORD = "blahblahblah"
        Window.RegisterAsBrowser = True
        Window.Navigate("websitegoeshere" & PWORD)
        Window.MenuBar = True
        Window.ToolBar = False
        Window.AddressBar = True
        Window.StatusBar = True
        Window.FullScreen = False
        Window.Resizable = True
        Window.Visible = True
        Window.Width = 800
        Window.Height = 600
 
        Dim dest_x
        Dim dest_y
 
        dest_x = 18078
        dest_y = 18078
 
        ' Move the mouse to its final destination and click it.
        mouse_event( _
            MOUSEEVENTF_ABSOLUTE + _
            MOUSEEVENTF_MOVE + _
            MOUSEEVENTF_LEFTDOWN + _
            MOUSEEVENTF_LEFTUP, _
            dest_x, dest_y, 0, 0)
    End Sub
 
End Module

Open in new window

Avatar of SRG041808
SRG041808
Flag of United States of America image

ASKER

I know there is a thing called the windowstate but i couldn't get that to work
Avatar of leakim971
Now i get a MissingMemberException when i added this code piece


With Window("internetexplorer.application")
            With .document.parentWindow.screen
                Window.Width = .width
                Window.Height = .height
            End With
        End With

Option Strict Off
Option Explicit Off
Module Module1
 
    Public Const MOUSEEVENTF_MOVE As Integer = &H1
    Public Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    Public Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Public Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000
    Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
 
    Public Sub Main()
        Dim Window
        Window = CreateObject("InternetExplorer.Application")
        PWORD = "blahblahblah"
        Window.RegisterAsBrowser = True
        Window.Navigate("websitegoeshere" & PWORD)
        Window.MenuBar = True
        Window.ToolBar = False
        Window.AddressBar = True
        Window.StatusBar = True
        Window.FullScreen = False
        Window.Resizable = True
        Window.Visible = True
 
 
              With Window("internetexplorer.application")
            With .document.parentWindow.screen
                Window.Width = .width
                Window.Height = .height
            End With
        End With
 
        'Window.Width = 800
        'Window.Height = 600
 
        Dim dest_x
        Dim dest_y
 
        dest_x = 18078
        dest_y = 18078
 
        ' Move the mouse to its final destination and click it.
        mouse_event( _
            MOUSEEVENTF_ABSOLUTE + _
            MOUSEEVENTF_MOVE + _
            MOUSEEVENTF_LEFTDOWN + _
            MOUSEEVENTF_LEFTUP, _
            dest_x, dest_y, 0, 0)
    End Sub
 
End Module

Open in new window

Not a VBscript guru but the "window" identifier shouldn't be necessary since it's stated under your WITH block.
I think i found what i am looking for... its called SetWindowPos function......  I have tried declarations as long, as integer but at the SetWindowPos function it keeps telling me to find an integer less than infinity ....

        X = 0     'this sets x coordinate
        Y = 0      'this sets y coordinate
        cx = 1000   'this sets window size on x axis
        cy = 1000      'this sets window size on y axis
        uFlags = 0    'this is a variable to set window z order......on top, on bottom, movable, sizable etc.

        SetWindowPos(Window, 0, X, Y, cx, cy, 0)



Ideally I don't care how the window gets to a certain coordinate  (preferably top left corner area)..... just that it does so i can target my mouse clicks.....

I have found a bunch of examples and I cannot get any of them to work for my situation....   I have been googling for hours and I'm at my wits end

Bumping up points value for whoever has the holy grail of code snippet


thanks for the help
So I added the below script....it does not produce errors but will not open IE....


Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Private Const SW_MAXIMIZE = 3

ShellExecute(Window.hwnd, vbNullString, "google.com", vbNullString, "C:\Program Files\Internet Explorer\iexplore.exe", SW_MAXIMIZE)



Maybe try removing the direct link to google in IE. Maybe that's what confusing it.
Nope... still nothing


ShellExecute(window.hwnd, vbNullString, "", vbNullString, "C:\Program Files\Internet Explorer\iexplore.exe", SW_MAXIMIZE)
I think the following will work just fine once I get a proper declaration......I could be very wrong

here is link from microsoft --------------->   http://msdn.microsoft.com/en-us/library/ms633534%28VS.85%29.aspx

the error I get now is an   "InvalidCastException was unhandled" and that "Specified cast is not valid"    What does this mean?!?!?!  I'm not an expert programmer.

I have tried setting the "ByVal" as Integer... as Long...  none have worked so far.....the following is what I have at the moment




Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As  _
IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As _
Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean




hwnd = window                      'I dont know what else to do with this...it was what was used to create the window....supposed to be the handle of the window
        x = 0                                 'x is one coordinate in relation to the screen                        
        y = 0                                 'y is the other coordinate in relation to the screen
        nWidth = 1000                'you can resize the width with this variable
        nHeight = 1000              ' here you resize the height of window
        bRepaint = False           'here you say whether you want a screen refresh or not


MoveWindow(hwnd, x, y, nWidth, nHeight, bRepaint)    'here is where debugger stops with error



If i comment all this out the program will run fine


That's strange, that MoveWindow function shouldn't be producing an error
Any Ideas?

I tried commenting
                   'hwnd = window
                      'x = 0
                      'y = 0
                     'nWidth = 1000
                     'nHeight = 1000
                     'bRepaint = 0

I set this manually and it says to pick a number less than infinity.......obviously they are all less than infinity

MoveWindow(window, 100, 100, 1500, 1500, 0)


ASKER CERTIFIED SOLUTION
Avatar of SRG041808
SRG041808
Flag of United States of America 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
update...I got it so that I dont get any errors.....but my movewindow function is not working


 
Option Strict Off
Option Explicit Off
Module Module1
 
    Public Const MOUSEEVENTF_MOVE As Integer = &H1
    Public Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    Public Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Public Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000
    Private Const SWP_SHOWWINDOW As Integer = &H1
    Public Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As _
Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As _
Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Long
 
    Public Declare Function GetDesktopWindow Lib "user32" () As Long
    Public Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
 
    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
 
    Public Declare Function GetWindowHandle Lib "user32" (ByVal hwnd As Long)
 
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
    Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
 
 
    Public Sub Main()
        'MsgBox(&H1)
        'MsgBox(&H2)
 
        Dim window
 
        window = CreateObject("InternetExplorer.Application")
        PWORD = "password goes here"
        window.RegisterAsBrowser = True
        window.Navigate("website goes here" & PWORD)
        window.MenuBar = True
        window.ToolBar = True
        window.AddressBar = True
        window.StatusBar = True
        window.FullScreen = False
        window.Resizable = True
        window.Visible = True
        'window.theatermode = False
        
 
        Threading.Thread.Sleep(5000)
 
 
        'Public Sub MoveWindow()
 
 
        'Dim handle As Long
        hwnd = FindWindow(vbNullString, "title bar of IE goes here")  'this actually works
 
        
 
 
 
        
        'SetWindowPos(hwnd, 0, 100, 100, 100, 100, SWP_SHOWWINDOW)
        
 
 
 
 
        'handle = GetWindowHandle("handle goes here")
 
 
 
        'this section could set the window position... 
        'hwnd = window
        x = 0
        y = 0
        nWidth = 1000
        nHeight = 1000
        bRepaint = True
 
        'movewindow (handle, x, y, nwidth, nheigth, brepaint)
        'MoveWindow(hwnd, 5000, 5000, 800, 600, 1)
 
    
        'Move(ByVal Left As Long, ByVal Top As Long, ByVal Width As Long, ByVal Height As Long, Optional ByVal Repaint As Boolean = True)
 
        If Not MoveWindow(hwnd, x, y, nWidth, nHeight, True) Then     '<------function that wont work
           'the below message boxes return correct values
            MsgBox(hwnd)
            MsgBox(x)
            MsgBox(y)
            MsgBox(nHeight)
            MsgBox(nWidth)
            MsgBox(bRepaint)
            MsgBox("Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured.")
 
        End If
 
 
 
 
        'get the window size
        'iheight = Window.height
        'iwidth = Window.width
        'give app time to resize
        'Threading.Thread.Sleep(2000)
        'Window.theatermode = False
 
 
        'set the window size
        'window.Width = 1000
        'window.Height = 1000
        'Threading.Thread.Sleep(10000)
 
 
        'set the coordinates of the mouse
        Dim dest_x
        Dim dest_y
 
        dest_x = 30000
        dest_y = 8000
 
        'Move the mouse to 1000 pros.
        'mouse_event( _
        'MOUSEEVENTF_ABSOLUTE + _
        'MOUSEEVENTF_MOVE + _
        'MOUSEEVENTF_LEFTDOWN + _
        'MOUSEEVENTF_LEFTUP, _
        'dest_x, dest_y, 0, 0)
 
        'here is where the copy paste goes
 
 
 
 
 
 
 
        'now to move the mouse to the submit button
        'Threading.Thread.Sleep(1500)
        dest_x = 30000
        dest_y = 15000
 
        ' Move the mouse to submit button.
        'mouse_event( _
        'MOUSEEVENTF_ABSOLUTE + _
        'MOUSEEVENTF_MOVE + _
        'MOUSEEVENTF_LEFTDOWN + _
        'MOUSEEVENTF_LEFTUP, _
        'dest_x, dest_y, 0, 0)
 
        'quit IE...use this once above works
        'window.quit()
    End Sub
 
 
     
 
 
 
 
 
 
 
End Module

Open in new window