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

  ;-Include files-------------------------------------------------------
    #Include "..\include\Constants.au3"
    #Include "..\include\WinAPI.au3"
    #Include "..\include\WindowsConstants.au3"
  
  ;-Constants-----------------------------------------------------------
    Const $WM_MOUSELEAVE = 0x02A3 
  
  ;-Variables-----------------------------------------------------------
    Dim $hWin, $hToolBar1, $Quit
    Dim $hBtn_SCAP_Proc
    ;-Predefined variables----------------------------------------------
      Dim $WinTitle = "[CLASS:SAP_FRONTEND_SESSION]"
      Dim $ToolBar1 = "[CLASS:Afx:58DC0000:8:00010011:00000000:00000000]"
      Dim $ToolBar2 = "[CLASS:Afx:58DC0000:0:00010011:00000010:00000000]"
  
  ;-Function btnSCAP_CallBack-------------------------------------------
    Func btn_SCAP_CallBack($hWind, $uMsg, $wParam, $lParam)
      Switch $uMsg
        ;-ToolTip-------------------------------------------------------
          Case $WM_MOUSEMOVE
            ToolTip("Save & Check & Activate & Processing")
          Case $WM_MOUSELEAVE
            ToolTip("")
        ;-ButtonClick---------------------------------------------------    
          Case $WM_LBUTTONUP
            ControlFocus("", "", $ToolBar2)
            ;-Save------------------------------------------------------
              Send("^s")
              Sleep(1024)
            ;-Check-----------------------------------------------------  
              Send("^{F2}")
              Sleep(1024)
            ;-Activate--------------------------------------------------  
              Send("^{F3}")
              Sleep(1024)
              Send("{ENTER}")
              Sleep(1536)
            ;-Processing------------------------------------------------  
              Send("{F8}")
      EndSwitch
      Return _WinAPI_CallWindowProc($hbtn_SCAP_Proc, $hWind, $uMsg, _
        $wParam, $lParam)
    EndFunc

  ;-Procedure AddButton-------------------------------------------------
    Func AddButton()
      $hWin = WinGetHandle($WinTitle)
      $hToolBar1 = ControlGetHandle($WinTitle, "", $ToolBar1)
      ;-SCAP button-----------------------------------------------------
        Dim $hbtn_SCAP = _WinAPI_CreateWindowEx(0, "BUTTON", "SCAP", _
          $WS_VISIBLE + $WS_CHILD, 590, 6, 50, 20, $hToolBar1)
        $hbtn_SCAP_Proc = _WinAPI_GetWindowLong($hbtn_SCAP, _
          $GWL_WNDPROC)
        Dim $ptr_SCAP_CallBack = _
          DLLCallBackRegister("btn_SCAP_CallBack", "ptr", _
          "hwnd;uint;long;ptr")   
        _WinAPI_SetWindowLong($hbtn_SCAP, $GWL_WNDPROC, _
          DLLCallBackGetPtr($ptr_SCAP_CallBack))
      ;-Set tray--------------------------------------------------------
        Opt("TrayMenuMode",1)
        $Quit = TrayCreateItem("Exit")
        TraySetState()
      ;-MainLoop--------------------------------------------------------
        While 1
          Sleep(35)
          Switch TrayGetMsg()
            Case $Quit
              ExitLoop
          EndSwitch
        Wend
      _WinAPI_SetWindowLong($hToolBar1, $GWL_WNDPROC, $hbtn_SCAP_Proc) 
      DLLCallBackFree($ptr_SCAP_CallBack)
    EndFunc
    
  ;-Main----------------------------------------------------------------
    AddButton()    

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