在SAP GUI 中使用Media Player Control

一种编程语言不可能是万能的,但通过各种接口技术可以集成其它技术以实现目标. 譬如, 在SAP GUI 屏幕编程中, SAP 提供了SAP GUI Control以提供可复用的控件, 这些控件可以以ActiveX或Java Bean实现. 在 SAP GUI for Windows中, SAP GUI Control 采用ActiveX实现, 安装GUI for windows后, 我们就可以通过这些控件调用SAP系统中的功能,譬如说在VBA中调用RFC. 而在SAP系统中,我们也可以调用系统已注册的ActiveX控件, 下面以Media Player Control为例说明:

确定Media Player 控件的ClassId,它是用来实例化控件时使用.
      
在ABAP 程序中实现Media Player 控件的wrapper class:

*-----------------------------------------------------------------
*       CLASS lcl_player DEFINITION
*-----------------------------------------------------------------
CLASS lcl_player DEFINITION INHERITING FROM cl_gui_control.

  PUBLIC SECTION.
    METHODS:
     constructor
        Importing
            cont type ref to CL_GUI_CUSTOM_CONTAINER
        EXCEPTIONS
          cntl_error
          cntl_install_error ,
     stop,
     play.

ENDCLASS.                    "lcl_player DEFINITION

*-----------------------------------------------------------------
*       CLASS lcl_player IMPLEMENTATION
*-----------------------------------------------------------------CLASS lcl_player IMPLEMENTATION.

  METHOD  constructor.
    CALL METHOD super->constructor
      EXPORTING
        clsid             = '{6BF52A52-394A-11d3-B153-00C04F79FAA6}'
        parent            = cont 
      EXCEPTIONS
        cntl_system_error = 1
        OTHERS            = 2.
    CASE sy-subrc .
      WHEN 1 .
        RAISE cntl_install_error .
      WHEN 2 .
        RAISE cntl_error .
    ENDCASE .

  ENDMETHOD.                    "constructor

  METHOD stop.

    CALL METHOD me->call_method
      EXPORTING
        method            = 'Close'
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDMETHOD.                    "STOP

  METHOD play.

    DATA: l_url TYPE char100.
    CHECK file IS NOT INITIAL.

    l_url = file.
    REPLACE ALL OCCURRENCES OF '\' IN l_url WITH '//'.

    CONCATENATE 'file://' l_url INTO l_url.

    CALL METHOD set_property
      EXPORTING
        property          = 'Url'
        value             = l_url
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2
        OTHERS            = 3.

  ENDMETHOD.                    "PLAY
ENDCLASS.                    "lcl_player IMPLEMENTATION

 

以上代码只是对Media Player 控件的简单封装调用

封装类的使用同其它GUI Control相同, 即需要在屏幕上建立Custom Container, 再实例化一个容器类,并传到封装类的构造器中. 
效果运行如下:

PS: 每种语言都有其最适合的地方, 要多想想编程语言的特点, 以后每个编程人员都需要会用两三种语言来结合起来工作,这也是一个趋势. 譬如SQL,,这恐怕是每个应用都需要用到的.

以前在AMS写过一个JS对Media Player的封装类, 当时就找了些关于Media Player Control 的资料,地址为

http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx

你可能感兴趣的:(编程,windows,bean,Microsoft,VBA)