Knowledge Base Nr: 00116 VfWdraw.cpp - http://www.swe-kaiser.de

Downloads:

MFC: In einem Dialog in ein 'Video for Windows'-Fenster malen.
OnMouseMove(), OnLButtonUp(), OnLButtonDown funktionieren in diesem Fall nicht für ein FRAME-Control.

  
############### RC-file:
...
CONTROL "",IDC_FRAME,"Static",SS_BLACKFRAME | SS_NOTIFY,34,7,200,
139
...
POPUP "&Alarm"
BEGIN
MENUITEM "&linkes/oberes Eck", ID_ALARM_LINKSOBEN
MENUITEM "&rechtes/unteres Eck", ID_ALARM_RECHTSUNTEN
END
...
############### H-file:
...
RECT m_rAlarmZone:
...
############### CPP-file:
...
ON_COMMAND(ID_ALARM_LINKSOBEN, OnAlarmLinksoben)
ON_COMMAND(ID_ALARM_RECHTSUNTEN, OnAlarmRechtsunten)
...

void CVideoServerView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
...
SetTimer(0, 50, NULL);
}

void CVideoServerView::OnTimer(UINT nIDEvent)
{
static bool s_bLocked = false;
if (!s_bLocked)
{
s_bLocked = true;

...
DoSingleShot(); //video grabben und ausgeben (falls kein preview mode)
DrawSelection();

s_bLocked = false;
}

CFormView::OnTimer(nIDEvent);
}

void CVideoServerView::DrawSelection()
{
CDC* pDC = GetDlgItem(IDC_FRAME)->GetDC();

CBrush br(RGB(255,255,0));

pDC->FrameRect(&m_rAlarmZone, &br);

GetDlgItem(IDC_FRAME)->ReleaseDC(pDC);
}

void CVideoServerView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CWnd* pWndPreview = GetDlgItem(IDC_FRAME);

CPoint p(point);
ScreenToClient(&p);
CWnd* pWndHit = this->ChildWindowFromPoint(p);

if (pWndHit != pWndPreview) //contextmenü nur wenn rechte maustaste in video-frame gedrückt
return;

RECT rect;
GetDlgItem(IDC_FRAME)->GetWindowRect(&rect);
ScreenToClient(&rect);

m_nMouseX = p.x - rect.left;
m_nMouseY = p.y - rect.top;

CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);
menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
}

void CVideoServerView::OnAlarmLinksoben()
{
m_rAlarmZone.left = m_nMouseX;
m_rAlarmZone.top = m_nMouseY;

DrawSelection();
}

void CVideoServerView::OnAlarmRechtsunten()
{
m_rAlarmZone.right = m_nMouseX;
m_rAlarmZone.bottom = m_nMouseY;

DrawSelection();
}