Connecting Tech Pros Worldwide Forums | Help | Site Map

Starting Process and Resizing Process Window in VB.NET

Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 9 '07
I've been studying this solution, yet can not duplicate.

http://www.thescripts.com/forum/thread351439.html


I have a form with a single button. When the button is clicked, I want Internet Explorer to launch on a specific monitor with a specific window size.

I assume the only way to do this is with the Windows API -- which I have never used.


Here is my code:

-------------------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Runtime.InteropServices
  3.  
  4. Public Class Form1
  5.  
  6.     Dim tom As New Process
  7.     Dim tomstyle As New ProcessWindowStyle
  8.     Dim hndtom As IntPtr
  9.  
  10.     Public Declare Auto Function SetWindowPos Lib "user32.dll" ( _
  11.     ByVal hWnd As IntPtr, _
  12.     ByVal hWndInsertAfter As IntPtr, _
  13.     ByVal X As Int32, _
  14.     ByVal Y As Int32, _
  15.     ByVal cx As Int32, _
  16.     ByVal cy As Int32, _
  17.     ByVal uFlags As UInt32 _
  18.     ) As Boolean
  19.  
  20.     Public Declare Auto Function MoveWindow Lib "user32.dll" ( _
  21.     ByVal hWnd As IntPtr, _
  22.     ByVal X As Int32, _
  23.     ByVal Y As Int32, _
  24.     ByVal nWidth As Int32, _
  25.     ByVal nHeight As Int32, _
  26.     ByVal bRepaint As Boolean _
  27.     ) As Boolean
  28.  
  29.  
  30.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  31.  
  32.         tomstyle = ProcessWindowStyle.Normal
  33.  
  34.         tom = Process.Start("c:\program files\internet explorer\iexplore.exe")
  35.  
  36.         hndtom = tom.MainWindowHandle
  37.  
  38.         MsgBox(MoveWindow(hndtom, 10, 10, 300, 400, True))
  39.  
  40.     End Sub
  41.  
  42. End Class
  43.  
  44.  
  45.  
-------------------------------------------------------------------------------------------

The message box returns false each time, and the window is not resized.

What am I missing??



Tom

Newbie
 
Join Date: Aug 2008
Posts: 1
#2: Aug 15 '08

re: Starting Process and Resizing Process Window in VB.NET


Answer : Please add the
Imports System.Threading namespace and then add Thread.Sleep(2000) to wait for some time before resize...

It works fine....Thanks for ur help your code works for me also...

Below is Corrected Code

Imports System.Runtime.InteropServices

'Add below namespace for sleep function
Imports System.Threading


Public Class Form1

Dim tom As New Process
Dim tomstyle As New ProcessWindowStyle
Dim hndtom As IntPtr

Public Declare Auto Function SetWindowPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal hWndInsertAfter As IntPtr, _
ByVal X As Int32, _
ByVal Y As Int32, _
ByVal cx As Int32, _
ByVal cy As Int32, _
ByVal uFlags As UInt32 _
) As Boolean

Public Declare Auto Function MoveWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal X As Int32, _
ByVal Y As Int32, _
ByVal nWidth As Int32, _
ByVal nHeight As Int32, _
ByVal bRepaint As Boolean _
) As Boolean


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

tomstyle = ProcessWindowStyle.Normal

tom = Process.Start("c:\program files\internet explorer\iexplore.exe")

'Put some wait so that it returns the proper handle after the process is launched

Thread.Sleep(2000)


hndtom = tom.MainWindowHandle

MsgBox(MoveWindow(hndtom, 0, 50, 1024, 700, True))

End Sub

End Class

Poonam..:)
Reply