;-Begin-----------------------------------------------------------------
;-
;- Program to activate the I18N functionality in SAP GUI, to make it
;- possible to switch to a individual font
;-
;-----------------------------------------------------------------------

  ;-Global variables----------------------------------------------------
    Dim $WinTitle = "[CLASS:SAP_FRONTEND_SESSION]"
    Dim $Options = "[TITLE:Options; CLASS:#32770]"
    Dim $OptionsTab = "[CLASS:SysTabControl32]"
    
    Dim $I18N = "[TEXT:Activate the multi-byte functionalities to " & _
      "support:;CLASS:Button]"

  ;-Procedure SetWindow-------------------------------------------------
    Func SetWindow($Title, $Max)
      WinActivate($Title)
      WinSetState($Title, "", @SW_SHOW)
      If $Max Then
        WinSetState($Title, "", @SW_MAXIMIZE)
      EndIf  
    EndFunc
  
  ;-Procedure SwitchEditorDesign----------------------------------------
    Func SwitchFont()

      SetWindow($WinTitle, 1)

      ;-Start tooltip---------------------------------------------------
        ToolTip("Switch the font for the SAP GUI", _
          @DesktopWidth / 2 - 100, @DesktopHeight / 2 - 50, _
          "Switch font")
        Sleep(4000)

      ;-Open customize local layout-------------------------------------
        ToolTip("Type Alt+F12 to open customize local layout", 350, _
          45, "Open customize local layout")
        Sleep(4000)
        ToolTip("")
        Sleep(500)
        Send("!{F12}")

      ;-Choose options--------------------------------------------------
        ToolTip("Type p to open the options", 450, 75, _
          "Use options dialog")
        Sleep(4000)
        ToolTip("")
        Sleep(500)
        Send("p")
  
      ;-Activate option window------------------------------------------
        SetWindow($Options, 0)
      
      ;-Send cursor key to choose I18N---------------------------------- 
        ControlFocus($Options, "", $OptionsTab)
        Sleep(500)
        ControlSend($Options, "", $OptionsTab, "{LEFT}{LEFT}{LEFT}" & _
          "{LEFT}{LEFT}{LEFT}")
        Sleep(500)
        ToolTip("Choose I18N tab", 450, 200, "Choose I18N")
        ControlSend($Options, "", $OptionsTab, "{RIGHT}")
        Sleep(250)  
        ControlSend($Options, "", $OptionsTab, "{RIGHT}")
        Sleep(4000)
        ToolTip("")
        Sleep(500)
        
      ;-Is multi-byte functionality activate----------------------------  
        If ControlCommand($Options, "", $I18N, "IsChecked") Then
          ;-Hint--------------------------------------------------------
            ToolTip("The multi-byte functionality is activate", 450, _
              250, "Important hint")
            Sleep(4000)
            ToolTip("")
            Sleep(500)
          ;-Close option window-----------------------------------------  
            Send("{ESC}")
          ;-Open font in customize local layout-------------------------  
            Send("!{F12}F")
        Else
          ;-Enable the multi-byte functionality-------------------------
            ControlCommand($Options, "", $I18N, "Check")
            ToolTip("Activate the multi-byte functionality", 450, _
              240, "Activate")
            Sleep(4000)
            ToolTip("")
            Sleep(500)
          ;-Click Ok button---------------------------------------------  
            ToolTip("Press OK button", 450, 600, "Press OK")
            Sleep(4000)
            ToolTip("")
            Sleep(500)
            ControlClick($Options, "", "[TEXT:OK;CLASS:Button]")
          ;-Log off the SAP GUI-----------------------------------------  
            ToolTip("Now log off the SAP GUI and restart it", _
              @DesktopWidth / 2 - 100, @DesktopHeight / 2 - 50, _
              "Log off and restart SAP GUI")
            Sleep(4000)
            SetWindow($WinTitle, 1)
            Sleep(500)
            ToolTip("")
            Send("!YF{TAB}{SPACE}")
          ;-Restart SAP GUI---------------------------------------------  
            ShellExecute("SAPStartGUI.au3")
          ;-Open font in customize local layout-------------------------  
            Sleep(6500)
            Send("!{F12}F")
        EndIf
    EndFunc

  ;-Main----------------------------------------------------------------
    SwitchFont()

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