This document is archived and information here might be outdated.  Recommended version.


Get hWnd for Current Application Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Get hWnd for Current Application Snippet

Get the Windows Handle (hWnd) of the application that is currently running.

[C#]
///<summary>Get the Windows Handle (hWnd) of the application that is currently running.</summary>
///
///<returns>A System.Int32 that is windows handle of the running application.</returns>
/// 
///<remarks>Note: If the code is running inside an ArcGIS desktop application, you should use the IApplicaiton.hWnd to get the Windows Handle.</remarks>
public System.Int32 GetHWndForCurrentApplication()
{
    return System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32();
}
[Visual Basic .NET]
'''<summary>Get the Windows Handle (hWnd) of the application that is currently running.</summary>
'''
'''<returns>A System.Int32 that is windows handle of the running application.</returns>
''' 
'''<remarks>Note: If the code is running inside an ArcGIS desktop application, you should use the IApplicaiton.hWnd to get the Windows Handle.</remarks>
Public Function GetHWndForCurrentApplication() As System.Int32

  Return System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()(0)).ToInt32()

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • System