By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

task process application to set through button in vb.net 08

P: 56
hi freinds, I am making a application throught which I have to select a application from taskmgr and I did almost selecting the application from taskmgr and restoring it I did but what I want is after the application getting restore it will come in default position or what position I am giving to it.... but what i want is after the application get restore I cat set the location of it by moving throuh the button since long time I am stuck on it Please any body help me soon so that I can move forward. here is my cooding

Expand|Select|Wrap|Line Numbers
  1. Imports System.Windows
  2. Imports System.Drawing.Point
  3. Imports System.IO
  4. Imports Microsoft.Win32
  5. Imports System.Diagnostics
  6. Imports System.Runtime.InteropServices
  7. Module FileParse
  8.  
  9.     Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Int32, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Boolean
  10.  
  11.     Friend ApplicationProcess As System.Diagnostics.Process
  12.  
  13.     Friend ApplicationHandle As Long
  14.  
  15.  
  16. End Module
  17.  
  18. Module ManipulateWindows
  19.  
  20.     Public Const SW_HIDE As Integer = 0
  21.     Public Const SW_RESTORE As Integer = 1
  22.     Public Const SW_MINIMIZE As Integer = 2
  23.     Public Const SW_MAXIMIZE As Integer = 3
  24.  
  25.     <DllImport("User32")> _
  26.     Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal cmd As Integer) As Boolean
  27.     End Function
  28.  
  29. End Module
  30.  
  31. Public Class Form1
  32.  
  33.     Dim objectposition, objectposition1, cursurpoint As Point
  34.  
  35.     Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  36.  
  37.  
  38.         Dim process As New Process
  39.         process = process.GetCurrentProcess()
  40.         Dim count As Integer = 0
  41.         lstview.Items.Clear()
  42.         For Each process In process.GetProcesses(My.Computer.Name)
  43.             On Error Resume Next
  44.             Dim str1 As String = process.ProcessName
  45.             Dim STR2 As ListViewItem = New ListViewItem(str1)
  46.  
  47.             If Not lstview.Items.Contains(STR2) Then
  48.  
  49.                 lstview.Items.Add(process.ProcessName)
  50.  
  51.                 lstview.Items(count).SubItems.Add(FormatNumber(Math.Round(process.PrivateMemorySize64 / 1024), 0))
  52.                 lstview.Items(count).SubItems.Add(process.Responding)
  53.                 lstview.Items(count).SubItems.Add(process.StartTime.ToString)
  54.                 lstview.Items(count).SubItems.Add(process.Id)
  55.                 count += 1
  56.             End If
  57.         Next
  58.         ToolStripStatusLabel1.Text = " processes : " & lstview.Items.Count
  59.         For Each p As Process In process.GetProcesses()
  60.             If (ComboBox1.Items.Contains(p.ProcessName) = False) Then
  61.                 ComboBox1.Items.Add(p.ProcessName)
  62.             End If
  63.         Next
  64.  
  65.  
  66.     End Sub
  67.  
  68.     Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
  69.  
  70.         For Each Process As ListViewItem In lstview.SelectedItems
  71.             System.Diagnostics.Process.GetProcessById(Process.SubItems(4).Text).Kill()
  72.  
  73.         Next
  74.         Form1_Load(Nothing, Nothing)
  75.     End Sub
  76.  
  77.  
  78.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  79.         Form1_Load(Nothing, Nothing)
  80.     End Sub
  81.  
  82.  
  83.  
  84.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  85.  
  86.         'For Each p As Process In Process.GetProcessesByName("taskmgr")
  87.         '    ShowWindow(p.MainWindowHandle, SW_RESTORE)
  88.         'Next p
  89.  
  90.         OpenApplication()
  91.     End Sub
  92.  
  93.  
  94.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  95.         Dim p() As Process = Process.GetProcessesByName(ComboBox1.SelectedItem)
  96.         For Each pr As Process In p
  97.             ShowWindow(pr.MainWindowHandle, SW_RESTORE)
  98.         Next
  99.     End Sub
  100.  
  101.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  102.         Dim str As String = lstview.SelectedItems.Item(0).SubItems(0).Text
  103.         Dim p() As Process = Process.GetProcessesByName(str)
  104.         For Each pr As Process In p
  105.             ShowWindow(pr.MainWindowHandle, SW_RESTORE)
  106.         Next
  107.     End Sub
  108.     Public Function OpenApplication()
  109.  
  110.         ApplicationProcess = System.Diagnostics.Process.Start("c:\h.txt")
  111.  
  112.         System.Threading.Thread.Sleep(1000)
  113.  
  114.         ApplicationHandle = ApplicationProcess.MainWindowHandle
  115.  
  116.         MoveWindow(ApplicationHandle, 600, 600, 600, 600, True)
  117.  
  118.  
  119.         Return (True)
  120.  
  121.     End Function
  122.  
  123.     Public Sub renew()
  124.         objectposition = Button1.Location
  125.         'objectposition1 = OpenApplication().Location
  126.         cursurpoint = Cursor.Position
  127.  
  128.     End Sub
  129.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  130.         If Button3.Text = "move" Then
  131.             Button3.Text = "stop"
  132.             Timer2.Enabled = True
  133.             Timer2.Start()
  134.             renew()
  135.         ElseIf Button3.Text = "stop" Then
  136.             Button3.Text = "move"
  137.             Timer2.Stop()
  138.             renew()
  139.         End If
  140.     End Sub
  141.  
  142.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  143.         Button1.Location = objectposition - cursurpoint + Cursor.Position
  144.         'OpenApplication().Location = objectposition1 - cursurpoint + Cursor.Position
  145.     End Sub
  146.  
  147.  
  148. End Class
Dec 15 '12 #1

✓ answered by PsychoCoder

I'm sorry but I just don't understand what it is you're asking help for, can you be a little more clear please :)

Share this Question
Share on Google+
2 Replies


PsychoCoder
Expert Mod 100+
P: 465
I'm sorry but I just don't understand what it is you're asking help for, can you be a little more clear please :)
Dec 15 '12 #2

P: 56
I want to select the process from task manager and after selecting it should get maximise or restore and after its getting restore it will be in it default position. so through the button I want to set the position means moving up and down or right or left. Hope u got it what i want. help me out soon please since long time I m working on it . but didnt reach to the destination
Dec 16 '12 #3

Post your reply

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