Results 1 to 21 of 21

Thread: [RESOLVED] Open an IE Window with a give size and position

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Open an IE Window with a give size and position

    Is it possible to create some sort of script that when used as a shortcut on my desktop would open a new IE window of a given size and postition (both constant) for a given site (always the same)?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    You could do it with a small vb program using some APIs'. Would that be too much?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Open an IE Window with a give size and position

    I don't have VB right now. But it will be something like this,
    (typing freehand, so this may not even compile. )
    VB Code:
    1. ' Add a reference to Microsoft HTML Object Library
    2. Dim IE as InternetExplorer 'or as object - if you want to keep it lite and don't add the reference
    3.  
    4. Set IE = New InternetExplorer
    5. ' or Set IE = CreateObject("InternetExplorer.Application")
    6. With IE
    7.    .Top = 100 ' check if the propery names are correct
    8.    .Left = 200
    9.    .Width = 1000
    10.    .Height = 500
    11.  
    12.    .Visible = True
    13.    .Navigate2 "http://www.vbforums.com"
    14. End With
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Open an IE Window with a give size and position

    Why bother so much when it could be done using simple Javascript.
    HTML Code:
    <html>
      <head>
        <script type="text/javascript">
          function somefunc()
          {
            top.resizeTo(800,600)
            window.navigate('http://www.google.com');
          }
        </script>
      </head>
    
      <body onLoad="somefunc()"/>
    </html>
    Save the text as HTML on desktop, Dbl-click it to see the effect.

    You can also use Top property of JS to set your browser's Top property. Just give me a minute to check it.
    Show Appreciation. Rate Posts.

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Open an IE Window with a give size and position

    Or,
    Create a html file on your desktop with following code.
    HTML Code:
    <html>
    <body bgcolor="#FFFFFF">
    
    <script language="JavaScript">
    <!--
    window.moveTo(100,50);
    window.resizeTo(300,400);
    window.location.href = "http://www.google.com";
    -->
    </script>
    
    </body>
    </html>
    edit:
    Ahhhhh ! I'm too slow.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Open an IE Window with a give size and position

    Here the whole code, and sorry, it was moveTo function and not Top property.
    HTML Code:
    <html>
      <head>
        <script type="text/javascript">
          function somefunc()
          {
            window.moveTo(100,100)
    	window.resizeTo(800,600)
            window.navigate('http://www.google.com');
          }
        </script>
      </head>
    
      <body onLoad="somefunc()"/>
    </html>
    Lightweigt and better than VB crap.
    Show Appreciation. Rate Posts.

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Open an IE Window with a give size and position

    ...but as the HTML file will open in the default browser,
    If you specifically need IE, better create a link to IE and pass the file as argument.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open an IE Window with a give size and position

    Quote Originally Posted by Harsh Gupta
    Here the whole code, and sorry, it was moveTo function and not Top property.
    HTML Code:
    <html>
      <head>
        <script type="text/javascript">
          function somefunc()
          {
            window.moveTo(100,100)
    	window.resizeTo(800,600)
            window.navigate('http://www.google.com');
          }
        </script>
      </head>
    
      <body onLoad="somefunc()"/>
    </html>
    Lightweigt and better than VB crap.
    I tried it and IE gives me an "To help protect your security Internet Explorer has restricted active content that could access your computer...." It lets me manually accept the risk but is there any way to avoid the message altogether?

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Open an IE Window with a give size and position

    May be you have High security enabled ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    Too much trouble to use all apis but this is a good mix. Takem script from iPrank.

    Note: If running in IE SP-2 you may get the active content blocked toolbar notification. To will have to click to allow the javascript to run.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    4.                         ByVal hwnd As Long, _
    5.                         ByVal lpOperation As String, _
    6.                         ByVal lpFile As String, _
    7.                         ByVal lpParameters As String, _
    8.                         ByVal lpDirectory As String, _
    9.                         ByVal nShowCmd As Long) As Long
    10.  
    11. Private Const SW_SHOWNORMAL As Long = 1
    12.  
    13. Private Sub Main()
    14.     ShellExecute 0&, "Open", "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "C:\martin.htm", "C:\", SW_SHOWNORMAL
    15. End Sub
    16.  
    17.  
    18. 'File contents:
    19. <html>
    20. <body bgcolor="#FFFFFF">
    21.  
    22. <script language="JavaScript">
    23. <!--
    24. window.moveTo(100,50);
    25. window.resizeTo(300,400);
    26. window.location.href = "http://vbforums.com";
    27. -->
    28. </script>
    29.  
    30. </body>
    31. </html>
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open an IE Window with a give size and position

    Quote Originally Posted by Harsh Gupta
    Here the whole code, and sorry, it was moveTo function and not Top property.
    HTML Code:
    <html>
      <head>
        <script type="text/javascript">
          function somefunc()
          {
            window.moveTo(100,100)
    	window.resizeTo(800,600)
            window.navigate('http://www.google.com');
          }
        </script>
      </head>
    
      <body onLoad="somefunc()"/>
    </html>
    Lightweigt and better than VB crap.
    I thought I could use this but apparently not since it only worked the first time I tried it. After that I tried experimenting with the 100, 100 with no effect and as a matter of fact when I changed it back to 100,100 it opened IE full screen!

  13. #13
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Open an IE Window with a give size and position

    @RobDog
    You don't need an exe. Just create a shortcut to IE passing the file as argument (post#8)
    Code:
    "I:\Program Files\Internet Explorer\IEXPLORE.EXE" "C:\Martin.htm"
    Last edited by iPrank; Sep 24th, 2006 at 05:22 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  14. #14
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Open an IE Window with a give size and position

    Quote Originally Posted by MartinLiss
    I thought I could use this but apparently not since it only worked the first time I tried it. After that I tried experimenting with the 100, 100 with no effect and as a matter of fact when I changed it back to 100,100 it opened IE full screen!
    I don't know, but I posted that code after checking it. I tried different values for moveTo and resizeTo and it worked on my PC without failing.
    Show Appreciation. Rate Posts.

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    Yes, thats where I referenced your file code from but you would have to create a shortcut to the htm file but that wouldnt guarentee that it be opened in IE if its not the default browser.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    This works without any scripting errors.

    The hard way....

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type RECT
    4.     Left As Long
    5.     Top As Long
    6.     Right As Long
    7.     Bottom As Long
    8. End Type
    9.  
    10. Private Type POINTAPI
    11.     x As Long
    12.     y As Long
    13. End Type
    14.  
    15. Private Type WINDOWPLACEMENT
    16.     Length As Long
    17.     flags As Long
    18.     showCmd As Long
    19.     ptMinPosition As POINTAPI
    20.     ptMaxPosition As POINTAPI
    21.     rcNormalPosition As RECT
    22. End Type
    23.  
    24. Private Declare Function SetWindowPlacement Lib "user32.dll" ( _
    25.                         ByVal hwnd As Long, _
    26.                         ByRef lpwndpl As WINDOWPLACEMENT) As Long
    27.  
    28. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    29.                         ByVal lpClassName As String, _
    30.                         ByVal lpWindowName As String) As Long
    31.  
    32. Private Const SW_SHOWNORMAL As Long = 1
    33.  
    34. Private Sub Main()
    35.     On Error GoTo MyError
    36.     Dim lRet As Long
    37.     Dim wPlace As WINDOWPLACEMENT
    38.     Dim rRect As RECT
    39.    
    40.     lRet = Shell("C:\Program Files\Internet Explorer\IEXPLORE.EXE", vbNormalFocus)
    41.     Do While lRet = 0
    42.         lRet = FindWindow("IEFrame", "VBForums - Visual Basic and VB .NET Discussions and More! - Microsoft Internet Explorer")
    43.         DoEvents
    44.     Loop
    45.     wPlace.Length = Len(wPlace)
    46.     wPlace.showCmd = SW_SHOWNORMAL
    47.     rRect.Left = 0
    48.     rRect.Top = 0
    49.     rRect.Right = (Screen.Width / Screen.TwipsPerPixelX) / 2
    50.     rRect.Bottom = (Screen.Height / Screen.TwipsPerPixelY) / 2
    51.     wPlace.rcNormalPosition = rRect
    52.     lRet = SetWindowPlacement(lRet, wPlace)
    53.     Exit Sub
    54. MyError:
    55.     MsgBox Err.Number & " - " & Err.Description
    56. End Sub
    Last edited by RobDog888; Sep 24th, 2006 at 05:42 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open an IE Window with a give size and position

    Quote Originally Posted by RobDog888
    This works without any scripting errors.

    The hard way....

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type RECT
    4.     Left As Long
    5.     Top As Long
    6.     Right As Long
    7.     Bottom As Long
    8. End Type
    9.  
    10. Private Type WINDOWPLACEMENT
    11.     Length As Long
    12.     flags As Long
    13.     showCmd As Long
    14.     ptMinPosition As POINTAPI
    15.     ptMaxPosition As POINTAPI
    16.     rcNormalPosition As RECT
    17. End Type
    18.  
    19. Private Declare Function SetWindowPlacement Lib "user32.dll" ( _
    20.                         ByVal hwnd As Long, _
    21.                         ByRef lpwndpl As WINDOWPLACEMENT) As Long
    22.  
    23. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    24.                         ByVal lpClassName As String, _
    25.                         ByVal lpWindowName As String) As Long
    26.  
    27. Private Const SW_SHOWNORMAL As Long = 1
    28.  
    29. Private Sub Main()
    30.     On Error GoTo MyError
    31.     Dim lRet As Long
    32.     Dim wPlace As WINDOWPLACEMENT
    33.     Dim rRect As RECT
    34.    
    35.     lRet = Shell("C:\Program Files\Internet Explorer\IEXPLORE.EXE", vbNormalFocus)
    36.     Do While lRet = 0
    37.         lRet = FindWindow("IEFrame", "VBForums - Visual Basic and VB .NET Discussions and More! - Microsoft Internet Explorer")
    38.         DoEvents
    39.     Loop
    40.     wPlace.Length = Len(wPlace)
    41.     wPlace.showCmd = SW_SHOWNORMAL
    42.     rRect.Left = 0
    43.     rRect.Top = 0
    44.     rRect.Right = 1000
    45.     rRect.Bottom = 1000
    46.     wPlace.rcNormalPosition = rRect
    47.     lRet = SetWindowPlacement(lRet, wPlace)
    48.     Exit Sub
    49. MyError:
    50.     MsgBox Err.Number & " - " & Err.Description
    51. End Sub
    I'll try that soon.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    Bah! Had some code missing as I had several methods applied in the temp project. Here is the fully working code.

    Place in a standard module and change the window title to what ever site you want.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type RECT
    4.     Left As Long
    5.     Top As Long
    6.     Right As Long
    7.     Bottom As Long
    8. End Type
    9.  
    10. Private Type POINTAPI
    11.     x As Long
    12.     y As Long
    13. End Type
    14.  
    15. Private Type WINDOWPLACEMENT
    16.     Length As Long
    17.     flags As Long
    18.     showCmd As Long
    19.     ptMinPosition As POINTAPI
    20.     ptMaxPosition As POINTAPI
    21.     rcNormalPosition As RECT
    22. End Type
    23.  
    24. Private Declare Function SetWindowPlacement Lib "user32.dll" ( _
    25.                         ByVal hwnd As Long, _
    26.                         ByRef lpwndpl As WINDOWPLACEMENT) As Long
    27.  
    28. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    29.                         ByVal lpClassName As String, _
    30.                         ByVal lpWindowName As String) As Long
    31.  
    32. Private Declare Function SetActiveWindow Lib "user32.dll" ( _
    33.                         ByVal hwnd As Long) As Long
    34.  
    35.  
    36. Private Const SW_SHOWNORMAL As Long = 1
    37. Private Const SW_SHOWMINIMIZED As Long = 2
    38. Private Const SW_SHOWMAXIMIZED As Long = 3
    39.  
    40. Private Sub Main()
    41.     On Error GoTo MyError
    42.     Dim lRet As Long
    43.     Dim lRet2 As Long
    44.     Dim wPlace As WINDOWPLACEMENT
    45.     Dim rRect As RECT
    46.    
    47.     Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE", vbNormalFocus
    48.     Do While lRet = 0
    49.         lRet = FindWindow("IEFrame", "VBForums - Visual Basic and VB .NET Discussions and More! - Microsoft Internet Explorer")
    50.     Loop
    51.     wPlace.Length = Len(wPlace)
    52.     wPlace.showCmd = SW_SHOWNORMAL
    53.     rRect.Left = 0
    54.     rRect.Top = 0
    55.     rRect.Right = (Screen.Width / Screen.TwipsPerPixelX) / 2
    56.     rRect.Bottom = (Screen.Height / Screen.TwipsPerPixelY) / 2
    57.     wPlace.rcNormalPosition = rRect
    58.     lRet2 = SetWindowPlacement(lRet, wPlace)
    59.     SetActiveWindow lRet
    60.     Exit Sub
    61. MyError:
    62.     MsgBox Err.Number & " - " & Err.Description
    63. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open an IE Window with a give size and position

    Rob that also opens my default home page and puts the target website behind it. Is there a way to prevent that, preferabbly by not opening the default home page?

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open an IE Window with a give size and position

    Try changing your shell line of code to this...
    Pass the site as a parameter.

    VB Code:
    1. Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE [b]http://vbforums.com[/b]", vbNormalFocus
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width