jdwarren
asked on
Handling Multiple Instances
Reference:
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(hWn dMe)
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(hWn dYou) Then
' Ignore if module name is different
If sExeMe = ExeNameFromWnd(hWndYou) Then
' Return first with same module, different process
GetFirstInstWnd = hWndYou
Exit Function
End If
End If
' Get next sibling
hWndYou = GetWindow(hWndYou, GW_HWNDNEXT)
Loop
End Function
>>>>>
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.
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(hWn
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(hWn
' Ignore if module name is different
If sExeMe = ExeNameFromWnd(hWndYou) Then
' Return first with same module, different process
GetFirstInstWnd = hWndYou
Exit Function
End If
End If
' Get next sibling
hWndYou = GetWindow(hWndYou, GW_HWNDNEXT)
Loop
End Function
>>>>>
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
TimCottee,
Thanks for the code example. I will accept your answer.
ameba,
your answer is also correct in that it actually provides the source code that was referenced in my question. I gave the points to TimCottee only because I ended up using his approach. Thanks very much for this link as other may find it useful.
Thanks for the code example. I will accept your answer.
ameba,
your answer is also correct in that it actually provides the source code that was referenced in my question. I gave the points to TimCottee only because I ended up using his approach. Thanks very much for this link as other may find it useful.
http://www.vb-zone.com/upload/free/features/vbpj/1999/mckinney/mckinney2a.asp