MAIN FORM from PROCESS ?

  • Thread starter Thread starter pamela fluente
  • Start date Start date
P

pamela fluente

Given p (as a process) how do I get the MainForm (let's assume that it
might exist) ?

-P
 
Can you explan this a little bit more Pamela?


Yes.

I was wondering whether - given a windows application which has a
MainForm, for instance "Form1" - assuming that a function only knows
the process p, it would be possible to find the main form.


something like:

Function FindMainFormFromProcess(p System.DiagnosticProcess) as
Control
'... ?
end function



-P
 
Given p (as a process) how do I get the MainForm (let's assume that it
might exist) ?

-P

I have to ask you what the purpose of this is? Also is the process you
are looking for a program you designed or one that a third party
created?

Thanks,

Seth Rowe
 
I have to ask you what the purpose of this is? Also is the process you
are looking for a program you designed or one that a third party
created?

Thanks,

Seth Rowe

For now I am planning to use within "a program I designed", but, of
course,
it also would be nice to know the general answer, which, I guess,
could be quite complicate.

In other words, is it possible, given only the handle of a process to
get the MainForm?

-P
 
For now I am planning to use within "a program I designed", but, of
course,
it also would be nice to know the general answer, which, I guess,
could be quite complicate.

In other words, is it possible, given only the handle of a process to
get the MainForm?

-P

I guess my question is how do you define "MainForm"? In an MDI
application I would assume you are trying to find the MDI Parent, and
a single SDI would be the only shown form. You might be able to use
the Window's API and loop through the process handle's associated
windows and pick out the MainForm from there - but I'm not sure of a
reliable way of doing this.

By the way, what are the chances you would know the title of the
MainForm from the program that starts the process. If you know that,
you could easily use the FindWindow API to grab the MainForm.

I'm still curious, what are you planning to do to the MainForm once
you get a reference to it? Or is this just an academic exercise?

Thanks,

Seth Rowe
 
I guess my question is how do you define "MainForm"? In an MDI
application I would assume you are trying to find the MDI Parent, and
a single SDI would be the only shown form. You might be able to use
the Window's API and loop through the process handle's associated
windows and pick out the MainForm from there - but I'm not sure of a
reliable way of doing this.

By the way, what are the chances you would know the title of the
MainForm from the program that starts the process. If you know that,
you could easily use the FindWindow API to grab the MainForm.

I'm still curious, what are you planning to do to the MainForm once
you get a reference to it? Or is this just an academic exercise?

Thanks,

Seth Rowe- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

Assume that MainForm is the (only) one you define as the startup form
in the project properties.

Given the above is it possible to get it from the process?
 
Given p (as a process) how do I get the MainForm (let's assume that it
might exist) ?

You can't get a winforms Form object representing a window in another
process and do something useful with it, if that's what you're asking.
You can get the window handle, but that's about it.


Mattias
 
You can't get a winforms Form object representing a window in another
process and do something useful with it, if that's what you're asking.
You can get the window handle, but that's about it.

Mattias

I see. Thank you Mattias.

-P
 
Back
Top