最近做的视频播放控件,我在播放的时候创建串口调用Create,关闭的时候释放pVideoImport指针,代码片段是这样的,其中pVideoImport是CWnd定义的对象,WndRecvVideoScreen是通过一个按钮句柄创建的Cwind对象,可不知道为什么来回开关200次左右,create函数返回了false,创建窗口失败,打印出error。这种情况在用VC对话框程序调用控件时候不会发生,可是在放在网页上之后,来回开关200次肯定会出现,我不好跟踪错误。
请问Create函数什么时候返回false??或者说其他可能引起错误的原因。谢啦~
if ( !pVideoImport->Create(
NULL,
NULL,
WS_CHILD,
CRect( 0, 0, 0, 0 ),
WndRecvVideoScreen,//this,
0,
NULL
) )
{
AfxMessageBox("error");
return 0;
}
请问Create函数什么时候返回false??或者说其他可能引起错误的原因。谢啦~
if ( !pVideoImport->Create(
NULL,
NULL,
WS_CHILD,
CRect( 0, 0, 0, 0 ),
WndRecvVideoScreen,//this,
0,
NULL
) )
{
AfxMessageBox("error");
return 0;
}
不知道網頁和用控件什么區別,制作過用控件的
1、可以使用相应的工具测试,如:BoundsCheck。在Debug的情况下测试
2、观察window资源管理器,看看该进程的使用情况
解决办法:
1、new 对应 delete
create 对应 Destroy
2、如果200次都是Create。那么再次创建前 对应Destroy
3、在设计上作修改。一次创建 多次使用。最后释放资源。如果每次都创建浪费资源
可以使用hide show 配合播放控件的play stop replay 去控制.
相信一定会成功的.哈哈
如不可以,请贴出代码 大家分析
没DestroyWindow,但我每次关会delete pVideoImport,估计就是这个问题了,DestroyWindow怎么用?参数?
没有参数。
//开始接收视频流
VideoRecvStart(HWND hWnd,int port)
{
if(true == bVideoRecv)
return -1;
pVideoImport = new CImport(0);
CWnd* WndRecvVideoScreen = (CWnd*) CWnd::FromHandle(hWnd);
CRect rectWnd;
if(NULL == pVideoImport)
return -1;
if ( !pVideoImport->Create(
NULL,
NULL,
WS_CHILD,
CRect( 0, 0, 0, 0 ),
WndRecvVideoScreen,//this,
0,
NULL
) )
{
AfxMessageBox("加载失败!");
return 0;
} pVideoImport->SelectThisPane(TRUE);
WndRecvVideoScreen->GetWindowRect(&rectWnd);
pVideoImport->SetWindowPos(
NULL,
0,
0,
rectWnd.Width()-2,
rectWnd.Height()-2,
SWP_SHOWWINDOW
);
pVideoImport->VideoRecvStart(port);
pVideoImport->ShowWindow(SW_SHOW); bVideoRecv = true;
return 1;
}
//关闭接收和播放窗口
extern "C" int __stdcall VideoRecvStop()
{
if(false == bVideoRecv)
return -1;
if(NULL != pVideoImport)
{
pVideoImport->VideoRecvStop();
}
pVideoImport->DestroyWindow();
SAFE_DELETE(pVideoImport);
bVideoRecv = false;
return 1;
}
这个宏就是delete pVideoImport而且我用VC自己调用的时候,不会出错,就是控件在网页上才会出错