Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

Tip: How to get Handles of Objects from SAP GUI for Windows

To locate an object of the SAP GUI for Windows, e.g. like one of the toolbars or the statusbar, you can’t use their titles, because none exists. So it is necessary to locate these objects via their class name. But the class names contains a dynamic part, this means a class names are not always constant. The dynamic part of the class name is the instance handle. An instance handle identifies the application that registered the class.

The following picture shows the UI object hierarchy of the SAP GUI for Windows. It is the hierarchy of the SAP Easy Access screen, as you can see on the title from the SAP_FRONTEND_SESSION window. The first toolbar (/app/con[0]/ses[0]/wnd[0]/tbar[0]) has the class name Afx:71790000:0:00010003:00000010:00000000. And as you can see, one part of the class name is the instance handle.


With this knowledge it is now possible to detect the handle of the toolbar, e.g. here with AutoIt:


  ;-Include files-------------------------------------------------------
    #Include "Include\Constants.au3"
    #Include "Include\WinAPI.au3"
    #Include "Include\WindowsConstants.au3"

    Const $WinTitle = "[CLASS:SAP_FRONTEND_SESSION]"

    Global $ToolBar1 = "[CLASS:Afx:"
    Global $ToolBar2 = ":0:00010003:00000010:00000000]"
    Global $ToolBar

  ;-Sub Main------------------------------------------------------------
    Func Main()

        Local $hWin, $hToolBar

      $hWin = WinGetHandle($WinTitle)
      $ToolBar = $ToolBar1 & _
        Hex(_WinAPI_GetWindowLong($hWin, $GWL_HINSTANCE)) & $ToolBar2
      $hToolBar = ControlGetHandle($WinTitle, "", $ToolBar)
      MsgBox(0, "Handle of the ToolBar", Hex($hToolBar))



With the handle of the object you have the possibility to manipulate the UI object.

Hint: You can find a window spy tool, called Window Detective, here. It is a free utility to select and view the properties of any window in the system.

Enjoy it.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.