Moving windows

  • Thread starter Thread starter Nathaniel
  • Start date Start date
I am new to VB but I have done something simillar.
Hopefully this will get you on the right track if it isnt what you are
looking for.

You can do stuff to windows through their process... so

'Declare your processes array
Dim myProcesses() As System.Diagnostics.Process

'retrieve your processes ( lets say TextBox1.Text has a value of
"Notepad" ( do not put "Notepad.exe" )
myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))

'You can do a loop, but lets just work with the first instance of notepad. -
so it will be array pointer ( 0 )
If myProcesses.Length > 0 Then

'Use any one of these commands
ShowWindow(myProcesses(0).MainWindowHandle, SW_MAXIMIZE) 'show Maximized
ShowWindow(myProcesses(0).MainWindowHandle, SW_MINIMIZE) 'show Minimized
ShowWindow(myProcesses(0).MainWindowHandle, SW_SHOW) 'Show
ShowWindow(myProcesses(0).MainWindowHandle, 9) 'Restore
End If

'Now you are probably wondering where the SW_Maximize and SW_Minimze come
from... declare them on top
Private Const SW_RESTORE As Int32 = 9
Private Const SW_MAXIMIZE As Int32 = 3
Private Const SW_MINIMIZE As Int32 = 6
Private Const SW_SHOW As Int32 = 5

To find out what these values i cant re-find the website, but search google
groups for sw_restore or sw_maximize and in a
post somewhere, someone took the time to give you all the values.

Hope that helps

Miro
 
Ok, thanks for the help, but I have 2 more qustions;

1) How can I retrive a system process by the title, for example "Untitled -
Notpad"?

2)With this code I can Maximize, and minimize, how can I change the
position. There is no;

MyProcess.location...
 
To get a process by title, you will have to loop through it and search for

IF myProcesses(nCount).MainWindowTitle = "Untitled - Notepad"

I probably would "Upper" both sides just to be sure.

as for 2... I havnt learned that yet. Ive only been using vb.net for only a
couple weeks.
So thats why I mentioned that hopefully this will get you on the right
track.

We are probably very close, but I dont really know what to search for
online. - Sorry

I was hoping someone would add to this conversation as well. Perhaps start
a new thread
in the newsgroup? I would also Post it in 2 newsgroups at the same time.
Try to post it to
microsoft.public.dotnet.general ; microsoft.public.dotnet.languages.vb

Sorry,

Miro
 
Back
Top