void COpencvTestDlg: : OnLButtonDown (UINT nFlags, CPoint point)
{
CRect myshowwinrect;
GetDlgItem (IDC_SHOW_IAMGE_FC) - & gt; GetWindowRect (myshowwinrect);//get the screen coordinates
The ScreenToClient (& amp; Myshowwinrect);//to the relative coordinates of the client area
The CWnd * PWND=GetDlgItem (IDC_SHOW_IAMGE_FC);
HWND HWND=PWND - & gt; GetSafeHwnd ();
If (point x & gt;=myshowwinrect. Left & amp; & Point. X & lt;=myshowwinrect. Right & amp; &
Point. The y & gt;=myshowwinrect. Top & amp; & Point. The y & lt;=myshowwinrect. Bottom)//mouse in the Picture on the Control controls the click
{
M_startRect=TRUE;//the left mouse button click, setting can begin to draw a rectangle box
M_startPoint=point;//record starting point
M_OldPoint=point;//setting too old for starting point
CClientDC dc (this);//get the device handle
Dc. SetROP2 (R2_NOT);//drawing mode
Dc. SelectStockObject (NULL_BRUSH);//do not use a brush
Dc. A Rectangle (CRect (m_LastSartPoint m_LastStopPoint));//remove before painting rectangular
}
CDialogEx: : OnLButtonDown (nFlags, point);
}
Void COpencvTestDlg: : onm ouseMove (UINT nFlags, CPoint point)
{
CClientDC dc (this);//get the device handle
Dc. SetROP2 (R2_NOT);//drawing mode
Dc. SelectStockObject (NULL_BRUSH);//do not use a brush
If TRUE (==m_startRect)//according to whether there is a click determine whether can draw rectangle
{
Dc. A Rectangle (CRect (m_startPoint m_OldPoint));
Dc. A Rectangle (CRect (m_startPoint, point));
M_OldPoint=point;
}
CDialogEx: onm ouseMove (nFlags, point);
}
Void COpencvTestDlg: : OnLButtonUp (UINT nFlags, CPoint point)
{
M_startRect=FALSE;//reset draw a rectangle box sign
////blanking last a rectangle (the principle the same as the rectangular box drawing principle drag with)
CClientDC dc (this);
Dc. SetROP2 (R2_NOT);
Dc. SelectStockObject (NULL_BRUSH);
Dc. A Rectangle (CRect (m_startPoint m_OldPoint));
Dc. A Rectangle (CRect (m_startPoint, point));
CDialogEx: : OnLButtonUp (nFlags, point);
}
The code above is ok, but the rectangular frame is black, I want to change the color, but the color changed after dc. SetROP2 (R2_NOT); Can not eliminate the rectangle before, how can help break? Or do you have any other methods? Grateful to
CodePudding user response:
Rewrite the CStatic class, OnPaint function will draw graphics in the background (or OnEarseBkGnd map background), then draw the otherCodePudding user response:
Hello, is not very understand, have the description of the specific point? MFC novice, thank youCodePudding user response:
Dc. SetROP2 (R2_XORPEN)CodePudding user response:
Dc. SetROP2 (R2_XORPEN) @ # 3, with the tested today, or not