Question on Process.Start

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

I have a program that starts a second program with Process p =
Process.Start(...). I expect p.Handle to hold the handle of the
started process, which I then use in a series of SendMessage Calls,
eg, SendMessage (p.Handle, 0x800+1, 0, 0).

However, p.Handle is not the handle of the started process. I know
this because, when the new process starts, it writes its own handle in
the caption of the window, and it does not match p.Handle. Also, if I
jigger the first program in the debugger, and use what I know to be
the handle in the SendMessage calls, it works fine.

What is going wrong?
 
Dom said:
I have a program that starts a second program with Process p =
Process.Start(...). I expect p.Handle to hold the handle of the
started process, which I then use in a series of SendMessage Calls,
eg, SendMessage (p.Handle, 0x800+1, 0, 0).

However, p.Handle is not the handle of the started process. I know
this because, when the new process starts, it writes its own handle in
the caption of the window, and it does not match p.Handle. Also, if I
jigger the first program in the debugger, and use what I know to be
the handle in the SendMessage calls, it works fine.

What is going wrong?

What handle are you expecting? The Process.Handle property is the Win32
HANDLE representing the Win32 process object. To send a message, you
need a _window_ handle, that is a Win32 HWND value.

It may be that all you need to do is use the Process.MainWindowHandle
property instead.

Pete
 
What handle are you expecting?  The Process.Handle property is the Win32
HANDLE representing the Win32 process object.  To send a message, you
need a _window_ handle, that is a Win32 HWND value.

It may be that all you need to do is use the Process.MainWindowHandle
property instead.

Pete

Thanks. That's exactly what I needed. I was a little suspicious
because I knew that in most objects, like controls, the "Handle"
property returns the handle of the control itself. I just couldn't
find any other property that looked like what I needed.
 
Back
Top