VB and VBA Users Source Code: Determine if a dialog/window handle belongs to your application
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Determine if a dialog/window handle belongs to your application
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, March 22, 2001
Hits:
685
Category:
Windows API
Article:
There are a number of API calls which return dialog handles (eg. FindWindowA). It is not always obvious which application owns this dialogs. The routine below demonstrates how to check if a specific dialog belongs to your application. Option Explicit Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long Private Declare Function GetActiveWindow Lib "user32" () As Long 'Purpose : Determines if a dialog belongs to this application (process) 'Inputs : lHwnd The handle to the dialog/window 'Outputs : Returns True if the dialog belongs to this application (process) 'Author : Andrew Baker 'Date : 03/09/2000 14:17 'Notes : In VBA use the FindWindow API to get a dialogs window handle Function DialogIsMine(lHwnd As Long) As Boolean Dim lProcessID As Long If lHwnd <> 0 Then 'Get the process ID of the dialog Call GetWindowThreadProcessId(lHwnd, lProcessID) 'Check if this process ID is the same as this applications process ID If lProcessID = GetCurrentProcessId() Then 'Window is in same process DialogIsMine = True End If End If End Function 'Demonstration routine Sub Test() Debug.Print DialogIsMine(GetActiveWindow) End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder