Skip to Content

Hello community,

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.

002.JPG

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

;-Begin-----------------------------------------------------------------

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

  ;-Constants-----------------------------------------------------------
    Const $WinTitle = "[CLASS:SAP_FRONTEND_SESSION]"

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

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

      ;-Variables-------------------------------------------------------
        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))

    EndFunc
   
  ;-Main----------------------------------------------------------------
    Main()

;-End-------------------------------------------------------------------

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

Hint: You can find WinSpy++ here. It is a free utility to select and view the properties of any window in the system.

Enjoy it.

Cheers

Stefan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply