Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm learning on how to use the Process class. I create a form and during the form load, I'd like to open the notepad as well. See my code below.

 

My problem is: After open the notepad, is it possible to get the handle of the notepad through process.Handle property?

 

I try the code as below but error occur as it come to

hwnd = myproc.Handle

 

Error :

An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll

 

Additional information: No process is associated with this object.

 

 

Can anybody tell me how to get its handle?

 

 

Thank you.

 

 
 Inherits System.Windows.Forms.Form
 Dim WithEvents myproc As System.Diagnostics.Process
 Dim hwnd As IntPtr

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   myproc = New System.Diagnostics.Process()
   ' Do not receive an event when the process exits.
   myproc.EnableRaisingEvents = True ' False
   ' Start Notepad, and assign it to the process component.    
   myproc.Start("Notepad.exe")

   ' This prevents the window from accepting a close before it has
   ' fully opened.
   'myproc.WaitForInputIdle()
   hwnd = myproc.Handle
 End Sub

Edited by divil
Posted
hWnd s are for windows not applications. Does notepad actually start?
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...