Du skal benytte API-kaldet FindWindow og derefter bruge API-kaldet SetWindowPos til at flytte og resize vinduet.
Brugte lige en 10 minutter på at sætte et eksempel sammen for dig.
Imports System.Runtime.InteropServices
Public Class Form1
''' <summary>
''' Fínder et vindue
''' </summary>
''' <param name="lpClassName">Vinduet's klasse</param>
''' <param name="lpWindowName">Vinduet's navn</param>
''' <returns>Hvis vinduet blev fundet returnéres dets handle, ellers returnéres IntPtr.Zero</returns>
''' <remarks>Man kan nøjes med kun at specificére klasse ELLER vindues-navn. Brug konstanten Nothing, til parametre der ikke skal bruges</remarks>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
ReadOnly HWND_BOTTOM As New IntPtr(1)
ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
ReadOnly HWND_TOP As New IntPtr(0)
ReadOnly HWND_TOPMOST As New IntPtr(-1)
Shared ReadOnly SWP_NOSIZE As UInt32 = Convert.ToUInt32(&H1)
Shared ReadOnly SWP_NOMOVE As UInt32 = Convert.ToUInt32(&H2)
Shared ReadOnly SWP_NOZORDER As UInt32 = Convert.ToUInt32(&H4)
Shared ReadOnly SWP_NOREDRAW As UInt32 = Convert.ToUInt32(&H8)
Shared ReadOnly SWP_NOACTIVATE As UInt32 = Convert.ToUInt32(&H10)
Shared ReadOnly SWP_FRAMECHANGED As UInt32 = Convert.ToUInt32(&H20)
Shared ReadOnly SWP_SHOWWINDOW As UInt32 = Convert.ToUInt32(&H40)
Shared ReadOnly SWP_HIDEWINDOW As UInt32 = Convert.ToUInt32(&H80)
Shared ReadOnly SWP_NOCOPYBITS As UInt32 = Convert.ToUInt32(&H100)
Shared ReadOnly SWP_NOOWNERZORDER As UInt32 = Convert.ToUInt32(&H200)
Shared ReadOnly SWP_NOSENDCHANGING As UInt32 = Convert.ToUInt32(&H400)
''' <summary>
''' Sætter vinduet's position og størrelse, samt nogle andre ting
''' </summary>
''' <param name="hWnd">Handle til vinduet</param>
''' <param name="hWndInsertAfter">Z index (Altså hvor dybt vinduet skal ligge)</param>
''' <param name="X">Vinduet's X position</param>
''' <param name="Y">Vinduet's Y position</param>
''' <param name="cx">Vinduet's bredde</param>
''' <param name="cy">Vinduet's højde</param>
''' <param name="uFlags">Flags</param>
''' <returns>Returnérer om funktionen lykkedes</returns>
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInt32) As Boolean
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim handle As IntPtr = IntPtr.Zero
handle = FindWindow("IEFrame", Nothing) 'Internet Explorer 8's class name er IEFrame. Jeg regner med at dette er tilfældet for alle tidligere IEs også. Ellers kan class id findes med Spy++ i Visual Studio tools i menuen start.
'Check om vinduet blev fundet
If handle = IntPtr.Zero Then
'Hvis IE ikke kører, så starter vi den lige
Dim p As System.Diagnostics.Process = System.Diagnostics.Process.Start("iexplore.exe")
'Bliv ved med at lede efter vinduet til vi finder det.
Do Until Not handle = IntPtr.Zero
handle = FindWindow("IEFrame", Nothing)
Loop
End If
'Set vinduet's position og størrelse
SetWindowPos(handle, HWND_TOP, 100, 100, 512, 512, SWP_SHOWWINDOW)
End Sub
End Class
Indlæg senest redigeret d. 06.11.2009 17:11 af Bruger #1927