第22课 在视频会议中加入共享白板

共享白板是视频会议中的常见功能,利用共享白板,参加会议的用户可以将己端绘制的图形分享给其他用户,这种功能可以作为桌面共享的有益补充存在,后期也可以用拓展成共享文档或共享画板。

一、共享白板实现的效果

共享白板

二、共享白板实现的原理

以画自由线为例,要将己端绘制的图形在对端同样绘制出来,就需要将己端所绘制图形的坐标等相关信息发送给对端,对端根据获取到的坐标依次将图形绘制出来即可。

通常将鼠标左键按下时鼠标所在的位置定为起点,鼠标左键松开时鼠标所在的位置定为终点,按住鼠标左键不松开时鼠标移动经过的坐标为中间绘制点。将这些坐标存入数组,然后依次连线即为所绘制的自由线图形。在己端可以边移动鼠标边连线,将数据传给对端时,对端可依据相关坐标信息依次将各点连线即可得到与己端相同的图形。

三、共享白板实现的主要代码

1.鼠标左键按下时记录起点

void whiteBoard::OnLButtonDown(UINT nFlags, CPoint point)

{

CDialogEx::OnLButtonDown(nFlags, point);

CPoint mousePos;

GetCursorPos(&mousePos);

CRect rect;

::GetClientRect(picContainer.GetSafeHwnd(), &rect);

::ScreenToClient(picContainer.GetSafeHwnd(), &mousePos);

if (rect.PtInRect(mousePos))

{

          TRACE("point.x:%d\n", mousePos.x);

          TRACE("point.y:%d\n", mousePos.y);

          originPoint.x = mousePos.x;

          originPoint.y = mousePos.y;

          isDrawing = true;

          msg="";             

}

}

2.鼠标左键松开时记录终点

void whiteBoard::OnLButtonUp(UINT nFlags, CPoint point)

{

CDialogEx::OnLButtonUp(nFlags, point);

isDrawing = false;

mainDlg->sendFreeLineMsg(msg);

msg = "";

}

3.鼠标移动时绘制并记录坐标

void whiteBoard::OnMouseMove(UINT nFlags, CPoint point)

{       

CDialogEx::OnMouseMove(nFlags, point);

CWnd *pwnd = GetDlgItem(IDC_PIC);

CDC *pDC = pwnd->GetWindowDC();

CPen myPen(PS_SOLID, 1, RGB(255, 0, 0));

pDC->SelectObject(&myPen);

CPoint mousePos;

GetCursorPos(&mousePos);

CRect rect;

::GetClientRect(picContainer.GetSafeHwnd(), &rect);

::ScreenToClient(picContainer.GetSafeHwnd(), &mousePos);

if (rect.PtInRect(mousePos))

{

          if (isDrawing)

          {

                  pDC->MoveTo(originPoint);

                  pDC->LineTo(mousePos);

                  CString tmpStr;

                  tmpStr.Format(_T("%ld"), originPoint.x);            

                  msg += tmpStr;

                  msg += ",";

                  tmpStr.Format(_T("%ld"), originPoint.y);

                  msg += tmpStr;

                  msg += ",";

                  tmpStr.Format(_T("%ld"), mousePos.x);

                  msg += tmpStr;

                  msg += ",";

                  tmpStr.Format(_T("%ld"), mousePos.y);

                  msg += tmpStr;

                  msg += ";";                         

                  originPoint = mousePos;

          }

}

}

4.对端接收到数据时依次绘制

void whiteBoard::drawFreeline(CString msg)

{

isDrawing = false;

CWnd *pwnd = GetDlgItem(IDC_PIC);

CDC *pDC = pwnd->GetWindowDC();

CPen myPen(PS_SOLID, 1, RGB(0, 0, 255));

pDC->SelectObject(&myPen);

CPoint originPoint;

CPoint mousePos;     

char s = { ';'};

CStringArray *pointArr = SplitString(msg, s);

int   size = pointArr->GetSize();       for (int i = 0; i < size; i++)

{   //的数据

          CString strTmp = pointArr->GetAt(i);

          char ss = { ',' };

          CStringArray *tmpArr = SplitString(strTmp, ss);

          if (tmpArr->GetSize() == 4){

         

                  CString x0 = tmpArr->GetAt(0);

                  CString y0 = tmpArr->GetAt(1);

                  CString x1 = tmpArr->GetAt(2);

                  CString y1 = tmpArr->GetAt(3);

                  //TRACE("******************\n");

                  //TRACE(x0);

                  //TRACE("******************\n");

                  originPoint.x = _ttol(x0);

                  originPoint.y = _ttol(y0);

                  pDC->MoveTo(originPoint);

                  mousePos.x = _ttol(x1);

                  mousePos.y = _ttol(y1);                      

                  pDC->LineTo(mousePos);

                  originPoint = mousePos;                     

          }

}      

}

你可能感兴趣的:(C++,ffmpeg,opencv,ffmpeg,opencv)