473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Starting Process and Resizing Process Window in VB.NET

1
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
Mar 9 '07 #1
1 11567
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..:)
Aug 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger...
0
by: TJ Talluto | last post by:
<facts> I have a "month calendar" that always displays exactly 42 days... and alongside is a vertical box that displays the detail (form fields) of any particular select event that appears on the...
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
2
by: Ale | last post by:
I try to start a program with process.start method. It normally starts but no window is displayed, i only see the application process running on the taskmanager. I think the process is executed...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
by: cvetomir.todorov | last post by:
We have an app which must be single instance. When we start the app we check if it is already running (using the Process object in the System.Diagnostics namespace) locating it by the name of the...
0
by: Mark Henry | last post by:
I wrote a Desktop class for manipulating desktops and window stations. The class is being used by a service for starting applications on the interactive desktop (the service cannot run as Local...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
1
by: ropo | last post by:
I have a .NET 2.0 app that at one point starts an old MFC App through System.Diagnostics.Process.Start from a model form/ I then wait for it to finish by calling StartedProcess.WaitForExit(); ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.