MSDN Library Visual Studio 6.0
HardCore Visual Basic
Handling Multiple Instances
Text From Example:
The GetFirstInstWnd function does the actual work. It works by looping through all the top windows until it finds one that has a different process ID, but the same module name. That?s the duplicate. The code (in MODTOOL.BAS) looks like this:
Function GetFirstInstWnd(hWndMe As Long) As Long
Dim hWndYou As Long, idMe As Long, sExeMe As String
' Get my own process ID and executable name
idMe = MWinTool.ProcIDFromWnd(hWndMe)
sExeMe = ExeNameFromWnd(hWndMe)
' Get first sibling to start iterating top-level windows
hWndYou = GetWindow(hWndMe, GW_HWNDFIRST)
Do While hWndYou <> hNull
' Ignore if process ID of target is same
If idMe <> MWinTool.ProcIDFromWnd(hWndYou) Then
' Ignore if module name is different
If sExeMe = ExeNameFromWnd(hWndYou) Then
' Return first with same module, different process
GetFirstInstWnd = hWndYou
' Get next sibling
hWndYou = GetWindow(hWndYou, GW_HWNDNEXT)
The above discussion was found in Visual Studio 6.0 help. If you inspect the above wording a reference is made to MODTOOL.BAS which I suspet is in a CD that comes with the HardCore Visual Basic Book.
I do not have this CD or book but suspect that the ExeNameFromWnd function referenced in the above code is comprised of several Windows API CALLs that somehow produces the name of a process (in string format) given the Window's hWnd.
How was this done? A code sample is what I am looking for here.