| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1012 人关注过本帖
标题:@吹水佬 帮我看看这段代码有什么问题?
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
结帖率:96.72%
收藏
已结贴  问题点数:20 回复次数:6 
@吹水佬 帮我看看这段代码有什么问题?
帮主,帮我看看这段代码有什么问题,关闭时发生错误,系统就退出了。
程序代码:
loformset=CREATEOBJECT("oformset")
loformset.frmmain.show()
loformset.frmctrl.show()

    **************************************************
*-- Formset:      formset (d:\documents\visual foxpro 项目\usecamera.scx)
*-- ParentClass:  formset
*-- BaseClass:    formset
*-- Time Stamp:   10/27/21 03:01:04 PM
*
DEFINE CLASS oformset AS formset


    DataSession = 1
    AutoRelease = .T.
    Name = "Formset"


    ADD OBJECT ofrmmain AS frmmain WITH ;
        DoCreate = .T., ;
        AutoCenter = .T., ;
        Caption = "frmmain", ;
        Name = "frmmain"
    
    ADD OBJECT frmctrl AS form WITH ;
        Top = 0, ;
        Left = 0, ;
        Height = 480, ;
        Width = 680, ;
        DoCreate = .T., ;
        Caption = "viewindow", ;
        Name = "frmctrl"
    PROCEDURE frmctrl.activate 
        READ EVENTS
     ENDPROC 

ENDDEFINE

DEFINE class frmmain as form    
    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        Caption = "摄像头控制实例", ;
        Height = 16, ;
        Left = 10, ;
        Top = 10, ;
        Width = 86, ;
        Name = "Label1"


    ADD OBJECT line1 AS line WITH ;
        Height = 0, ;
        Left = 10, ;
        Top = 30, ;
        Width = 351, ;
        Name = "Line1"


    ADD OBJECT line2 AS line WITH ;
        Height = 0, ;
        Left = 11, ;
        Top = 31, ;
        Width = 351, ;
        BorderColor = RGB(255,255,255), ;
        Name = "Line2"


    ADD OBJECT cmdcloseview AS commandbutton WITH ;
        AutoSize = .T., ;
        Top = 40, ;
        Left = 10, ;
        Height = 25, ;
        Width = 66, ;
        Caption = "closeview", ;
        Enabled = .F., ;
        Name = "cmdcloseview"


    ADD OBJECT cmdsave AS commandbutton WITH ;
        Top = 70, ;
        Left = 10, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "save", ;
        Enabled = .F., ;
        Name = "cmdsave"


    ADD OBJECT cmdrec AS commandbutton WITH ;
        Top = 100, ;
        Left = 10, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "record", ;
        Enabled = .F., ;
        Name = "cmdrec"


    ADD OBJECT cmdstp AS commandbutton WITH ;
        Top = 130, ;
        Left = 10, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "stop", ;
        Enabled = .F., ;
        Name = "cmdstp"


    ADD OBJECT cmdview AS commandbutton WITH ;
        Top = 160, ;
        Left = 10, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "View", ;
        Name = "cmdview"


    ADD OBJECT cmdquit AS commandbutton WITH ;
        Top = 190, ;
        Left = 10, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "quit", ;
        Name = "cmdquit"

    PROCEDURE Load
        *--定义:一般放到主程序或表单(集)的Load事件中
                Public WM_CAP_DRIVER_DISCONNECT
                Public hwndc,WM_CAP_SAVEDIB,WM_CAP_FILE_SET_CAPTURE_FILEA,WM_CAP_SEQUENCE,WM_CAP_STOP
                Declare Integer capCreateCaptureWindowA In "AVICAP32.DLL" String lpszWindowName ,Integer dwStyle ,;
                    Integer x, Integer Y, Integer nWidth ,Integer nHeight,Integer ParentWin,Integer nId
                Declare Integer SendMessage In "user32" Integer HWnd, Integer wmsg,Integer wpar1, Integer wpar2
                Declare Integer SendMessage In "user32" As SendMessageA Integer HWnd, Integer wmsg,Integer wpar1, String wpar2
    ENDPROC


    PROCEDURE Unload
        thisformset.Release
        CLEAR EVENTS
    ENDPROC


    PROCEDURE cmdcloseview.Click
        SendMessage(hWndC,WM_CAP_DRIVER_DISCONNECT, 0, 0)
        hWndC=0
        thisform.cmdview.Enabled=.t.
    ENDPROC


    PROCEDURE cmdsave.Click
                    *--保存图像:
                    *--无法控制生成的文件尺寸,因为是由摄像头本身默认的,不过可用Image控件显示时进行等比缩小的。
                    ss=Getfile("bmp;Jpg")
                    If !Empty(ss)
                        SendMessageA(hWndC,WM_CAP_SAVEDIB,0,SS)
                    Endif
    ENDPROC


    PROCEDURE cmdrec.Click
        *--录像:
                    ss = Getfile("avi")
                    If !Empty(ss)
                        This.Enabled=.F.
                        Thisform.MousePointer= 0
                        Thisform.cmdstp.Enabled=.T.
                        thisform.cmdstp.setfocus
                        SendMessageA(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,ss)
                        SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0)

                    ENDIF 
    ENDPROC


    PROCEDURE cmdstp.Click
        *--停止录像:
                    SendMessage(hWndC, WM_CAP_STOP, 0, 0)
                    Thisform.cmdrec.Enabled=.T.
                    This.Enabled=.F.
    ENDPROC


    PROCEDURE cmdview.Click
                WM_USER = 1024
                WM_CAP_START = WM_USER
                _CAP_STOP = WM_CAP_START + 68
                WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
                WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
                WM_CAP_SAVEDIB = WM_CAP_START + 25
                WM_CAP_GRAB_FRAME = WM_CAP_START + 60
                WM_CAP_SEQUENCE = WM_CAP_START + 62
                WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
                WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63
                WM_CAP_SET_OVERLAY =WM_CAP_START+ 51
                WM_CAP_SET_PREVIEW =WM_CAP_START+ 50
                WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6
                WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2
                WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3
                WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5
                WM_CAP_SET_SCALE=WM_CAP_START+ 53
                WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52
                hWndC = capCreateCaptureWindowA('My Own Capture Window',0x50000000,0,0,640,480,thisformset.frmctrl.HWnd ,0) &&1342177280=0x50000000
                If hWndC <> 0
                    SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)
                    SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0)
                    SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)
                    SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)
                    SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0)
                    SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0)
                    SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0)
                    SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0)
                * THISFORM.ACTIVATE
                ENDIF
                this.Enabled=.f.
                thisform.setall("enabled",.t.,"commandbutton")
    ENDPROC


    PROCEDURE cmdquit.Click
        thisform.Release
    ENDPROC
ENDDEFINE 
*
*-- EndDefine: formset
**************************************************
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: ADD Integer OBJECT WITH Name 
2021-10-27 22:26
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
附上错误日志,不知道是不是我的vfp缩水版有问题,还是程序有问题。
---不过得有摄像头才行。。。
图片附件: 游客没有浏览图片的权限,请 登录注册
2021-10-27 22:33
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:10 
回复 2楼 sam_jiang
贴出来的代码看不到frmctrl类的定义?
2021-10-28 09:53
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:10 
说真的,内容太多,难于消化,也只有你自己琢磨了。
2021-10-28 10:06
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
cantreply with chinese in my phone锛
2021-10-28 15:36
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
回复 3楼 吹水佬
有的,只有短短几句代码。
图片附件: 游客没有浏览图片的权限,请 登录注册
2021-10-28 18:54
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
我自己找到了原因了,错误排除了。。。@吹水佬

问题出在frmmain的unload里面,直接释放表单集引起的,应该在释放表单集前把表单frmctrl先释放了,不然设置了on error 命令都没用,这应该是FoxPro的一个bug,按理说释放表单集,它就会自动释放表单集里所有的表单。

    PROCEDURE Unload
        thisformset.frmctrl.Release && 加这一句就搞定了。
        thisformset.release
        CLEAR EVENTS
    ENDPROC
2021-10-28 20:26
快速回复:@吹水佬 帮我看看这段代码有什么问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052642 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved