Results 1 to 21 of 21

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

Hybrid View

  1. #1
    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

  2. #2

    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?

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