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)?
Printable View
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)?
You could do it with a small vb program using some APIs'. Would that be too much?
No, but I wouldn't know how.
I don't have VB right now. But it will be something like this,
(typing freehand, so this may not even compile. :D)
VB Code:
' Add a reference to Microsoft HTML Object Library Dim IE as InternetExplorer 'or as object - if you want to keep it lite and don't add the reference Set IE = New InternetExplorer ' or Set IE = CreateObject("InternetExplorer.Application") With IE .Top = 100 ' check if the propery names are correct .Left = 200 .Width = 1000 .Height = 500 .Visible = True .Navigate2 "http://www.vbforums.com" End With
Why bother so much when it could be done using simple Javascript.
Save the text as HTML on desktop, Dbl-click it to see the effect.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>
You can also use Top property of JS to set your browser's Top property. Just give me a minute to check it.
Or,
Create a html file on your desktop with following code.
edit: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>
Ahhhhh ! I'm too slow. :D
Here the whole code, and sorry, it was moveTo function and not Top property.
Lightweigt and better than VB crap.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>
...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.
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?Quote:
Originally Posted by Harsh Gupta
May be you have High security enabled ?
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:
Option Explicit 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_SHOWNORMAL As Long = 1 Private Sub Main() ShellExecute 0&, "Open", "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "C:\martin.htm", "C:\", SW_SHOWNORMAL End Sub 'File contents: <html> <body bgcolor="#FFFFFF"> <script language="JavaScript"> <!-- window.moveTo(100,50); window.resizeTo(300,400); window.location.href = "http://vbforums.com"; --> </script> </body> </html>
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!Quote:
Originally Posted by Harsh Gupta
@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"
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.Quote:
Originally Posted by MartinLiss
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.
This works without any scripting errors.
The hard way.... :D
VB Code:
Option Explicit Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI x As Long y As Long End Type Private Type WINDOWPLACEMENT Length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type Private Declare Function SetWindowPlacement Lib "user32.dll" ( _ ByVal hwnd As Long, _ ByRef lpwndpl As WINDOWPLACEMENT) As Long Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Const SW_SHOWNORMAL As Long = 1 Private Sub Main() On Error GoTo MyError Dim lRet As Long Dim wPlace As WINDOWPLACEMENT Dim rRect As RECT lRet = Shell("C:\Program Files\Internet Explorer\IEXPLORE.EXE", vbNormalFocus) Do While lRet = 0 lRet = FindWindow("IEFrame", "VBForums - Visual Basic and VB .NET Discussions and More! - Microsoft Internet Explorer") DoEvents Loop wPlace.Length = Len(wPlace) wPlace.showCmd = SW_SHOWNORMAL rRect.Left = 0 rRect.Top = 0 rRect.Right = (Screen.Width / Screen.TwipsPerPixelX) / 2 rRect.Bottom = (Screen.Height / Screen.TwipsPerPixelY) / 2 wPlace.rcNormalPosition = rRect lRet = SetWindowPlacement(lRet, wPlace) Exit Sub MyError: MsgBox Err.Number & " - " & Err.Description End Sub
I'll try that soon.Quote:
Originally Posted by RobDog888
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:
Option Explicit Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI x As Long y As Long End Type Private Type WINDOWPLACEMENT Length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type Private Declare Function SetWindowPlacement Lib "user32.dll" ( _ ByVal hwnd As Long, _ ByRef lpwndpl As WINDOWPLACEMENT) As Long Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function SetActiveWindow Lib "user32.dll" ( _ ByVal hwnd As Long) As Long Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMINIMIZED As Long = 2 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Sub Main() On Error GoTo MyError Dim lRet As Long Dim lRet2 As Long Dim wPlace As WINDOWPLACEMENT Dim rRect As RECT Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE", vbNormalFocus Do While lRet = 0 lRet = FindWindow("IEFrame", "VBForums - Visual Basic and VB .NET Discussions and More! - Microsoft Internet Explorer") Loop wPlace.Length = Len(wPlace) wPlace.showCmd = SW_SHOWNORMAL rRect.Left = 0 rRect.Top = 0 rRect.Right = (Screen.Width / Screen.TwipsPerPixelX) / 2 rRect.Bottom = (Screen.Height / Screen.TwipsPerPixelY) / 2 wPlace.rcNormalPosition = rRect lRet2 = SetWindowPlacement(lRet, wPlace) SetActiveWindow lRet Exit Sub MyError: MsgBox Err.Number & " - " & Err.Description End Sub
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?
Try changing your shell line of code to this...
Pass the site as a parameter.
VB Code:
Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE [b]http://vbforums.com[/b]", vbNormalFocus
Thanks Rob that works.