本帖最后由 阿达 于 2010-3-17 15:20 编辑
用flash做界面很漂亮,但是用户系统很可能没有flash,我目前用以下方法处理:
用
- IsObject(CreateObject("shockwaveflash.shockwaveflash"))
复制代码
判断用户系统是否有flash
如果有
- Public WithEvents shockwaveFlash As VBControlExtender
- Set Frm_Main.shockwaveFlash = Frm_Main.Controls.Add("ShockwaveFlash.ShockwaveFlash", "Flash")
- Frm_Main.shockwaveFlash.object.LoadMovie 0, App.Path & "ui.swf"
复制代码
这样来动态创建flash控件,好处是这样程序在用户系统没有flash的情况下也可以正常运行,不会报错。
如果用户系统没有,就用个容器,里面放些死的图片,实现同样的功能。
通信方面,flash调用vb的:
- Private Sub shockwaveFlash_ObjectEvent(info As EventInfo)
- Select Case info.Name
- Case "FSCommand"
- 'info.EventParameters("command").Value
- 'info.EventParameters("args").Value
- '上面两句可以拿到fscommand的两个参数
- Case Else '其他事件
- End Select
- End Sub
复制代码
flash中 fscommand(xxx, xxx); 就可以啦
vb调用flash的:
- //flash中增加、声明一个回调函数供vb调用
- ExternalInterface.addCallback("vbCallBack", vbCallBack);
- function vbCallBack(valA:String, valB:String):void
- {
- //
- }
- 'vb中这样搞
- shockwaveFlash.object.CallFunction "<invoke name=""vbCallBack"" returntype=""xml""><arguments><string>参数a</string><string>参数b</string></arguments></invoke>"
复制代码
这样就好啦,就是来回都只能用string类型,如果是图片,得先base64成字符串,然后传来解析。
另外如果一个程序中同时有几个flash之间要通信,可以用flash的管道,不需要通过程序转。
再付上一个屏蔽flash右键的
- Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
- Public Const GWL_WNDPROC = -4
- Private Const WM_RBUTTONDOWN = &H204
- Public ret As Long
- Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- If Msg = WM_RBUTTONDOWN Then Exit Function '这里可以还增加自己的代码用于响应flash中的右键行为
- WindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
- End Function
- '由于vb中flash控件没有hwnd,记得delphi中是有的,当时让我很郁闷,调用得如下:
- ret = SetWindowLong(FindWindowEx(Picture1.hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString), GWL_WNDPROC, AddressOf WindowProc)
复制代码
收工~~~~ |