Get the handle of a window from a process ID

  • Thread starter Thread starter Kevin McCartney
  • Start date Start date
K

Kevin McCartney

Hi Michel
Thanks for your help but what happens if I have several
Excel sessions running how do I now which one is the one
I'm looking for to destroy?

I'd really like to be able to pass the Process ID to a
function. Do you know of function that allows this?

Thanks for your time
KM
-----Original Message-----
Hi,


Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long



where we generally use vbNullString for the class name. The window has to
exist. The supplied name must be the EXACT name you look for (if the end
user can customize it, or if a * is append to it in some cases, you have to
use the customized caption, or the name with the * append to it, as
example). FindWindow does not search for child windows, FindWindowEx do. See
www.allapi.net


Hoping it may help,
Vanderghast, Access MVP





.
..
 
Hi,


Iterate over all the main windows, get their handle, supply that handle
to the first argument of the function GetWindowThreadProcessID, and you get
the processID in the returned (second) argument. The iteration stops if the
processID matches the one you seek. You can then post a message to end the
application.

Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long,
lpdwProcessId As Long) As Long

The result of the function call is the thread id that creates the said
window, if that may be of some importance to you.

Hoping it may help,
Vanderghast, Access MVP
 
Back
Top