????????最近玩RectTracker有点意思,进一步优化了简单的属性选择以及颜色选择功能,这样测试程序会更加直观。?
?
????????8个Handle手柄的颜色可以调节,大小可以调节,方向键移动步距可以调剂,画框的颜色可以选择,8个Handle手柄的Inside属性和Outside属性可以设置,此程序只为演示RectTracker类的应用,没有实际意义。 年底了比较闲散,抽时间写些VS2019 MFC类库的应用例程,和各位初学者们一起学习!
工程文件 CPP源代码:
#include "pch.h"
#include "framework.h"
#include "MFCApplicationCRectTracker.h"
#include "MFCApplicationCRectTrackerDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
COLORREF SolidRgb = RGB(0, 255, 0);
COLORREF DashaRgb = RGB(0, 0, 255);
COLORREF m_ColorHandle = RGB(0, 0, 255);
COLORREF m_RectangeRgb= RGB(255, 0, 0);
CPen m_SPen(PS_SOLID, 1, SolidRgb);
CPen m_DPen(PS_DASHDOT, 1, DashaRgb);
CRect m_GetPictureRect;
CBrush m_newBrush;
CBrush* m_oldBrush;
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
EnableActiveAccessibility();
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
CMFCApplicationCRectTrackerDlg::CMFCApplicationCRectTrackerDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_MFCAPPLICATIONCRECTTRACKER_DIALOG, pParent)
{
EnableActiveAccessibility();
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_IsChose = FALSE;
m_IsDraw = FALSE;
m_rectNum = 0;
m_rectChoseNum = 0;
m_FlaMoveStep = 1;
m_dirct = 0;
}
void CMFCApplicationCRectTrackerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBOSTYLE, m_Style);
DDX_Control(pDX, IDC_COMBOFLAMOVESTEP, m_MoveStep);
DDX_Control(pDX, IDC_CHECKRESIZEINSIDE, m_ResizeInside);
DDX_Control(pDX, IDC_CHECKRESIZEOUTSIDE, m_ResizeOutside);
DDX_Control(pDX, IDC_SLIDERHANDLESIZE, m_HandleSize);
DDX_Control(pDX, IDC_STATICSOLIDRGB, m_SolidRGB);
DDX_Control(pDX, IDC_STATICDASHAPENRGB, m_DashRGB);
DDX_Control(pDX, IDC_STATICHANDLERGB, m_handleRGB);
DDX_Control(pDX, IDC_STATICRECTANGE, m_RectRGB);
}
BEGIN_MESSAGE_MAP(CMFCApplicationCRectTrackerDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_KEYDOWN()
ON_BN_CLICKED(IDC_BUTTONDRAW, &CMFCApplicationCRectTrackerDlg::OnBnClickedButtondraw)
ON_BN_CLICKED(IDC_BUTTONSAVEPICTURE, &CMFCApplicationCRectTrackerDlg::OnBnClickedButtonsavepicture)
ON_BN_CLICKED(IDC_CHECKRESIZEINSIDE, &CMFCApplicationCRectTrackerDlg::OnBnClickedCheckresizeinside)
ON_BN_CLICKED(IDC_CHECKRESIZEOUTSIDE, &CMFCApplicationCRectTrackerDlg::OnBnClickedCheckresizeoutside)
ON_WM_LBUTTONUP()
ON_WM_SIZE()
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERHANDLESIZE, &CMFCApplicationCRectTrackerDlg::OnNMCustomdrawSliderhandlesize)
END_MESSAGE_MAP()
BOOL CMFCApplicationCRectTrackerDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != nullptr)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
ShowWindow(SW_MAXIMIZE);
m_Style.SetCurSel(1);
m_MoveStep.SetCurSel(0);
m_HandleSize.SetRange(0, 50);
m_HandleSize.SetRangeMax(50);
m_HandleSize.SetRangeMin(0);
m_HandleSize.SetPos(10);
m_HandleSize.SetLineSize(1);
int m_GetSliderValue = m_HandleSize.GetPos();
SetDlgItemInt(IDC_STATICSLIDERVALUE,m_GetSliderValue);
m_HandleSize.SetDlgItemInt(IDC_SLIDERHANDLESIZE,10);
m_ResizeInside.SetCheck(BST_CHECKED);
m_rctCurTracker.m_rect.SetRect(0,0,0,0);
m_rctCurTracker.m_nStyle = CMyCrectTracker::dottedLine | CMyCrectTracker::resizeInside;
m_rctCurTracker.m_nHandleSize = 10;
for (int i = 0; i < MAX_RECT_NUM; i++)
{
m_rctTracker[i].m_rect.SetRect(0,0,0,0);
m_rctTracker[i].m_nStyle= CMyCrectTracker::dottedLine | CMyCrectTracker::resizeInside;
m_rctTracker[i].m_nHandleSize = 10;
}
return TRUE;
}
void CMFCApplicationCRectTrackerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
void CMFCApplicationCRectTrackerDlg::OnPaint()
{
CPaintDC pDC(this);
m_newBrush.CreateSolidBrush(SolidRgb);
m_SolidRGB.GetWindowRect(&m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = pDC.SelectObject(&m_newBrush);
pDC.Rectangle(m_GetPictureRect);
pDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
m_newBrush.CreateSolidBrush(DashaRgb);
m_DashRGB.GetWindowRect(m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = pDC.SelectObject(&m_newBrush);
pDC.Rectangle(m_GetPictureRect);
pDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
m_newBrush.CreateSolidBrush(m_ColorHandle);
m_handleRGB.GetWindowRect(m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = pDC.SelectObject(&m_newBrush);
pDC.Rectangle(m_GetPictureRect);
pDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
m_newBrush.CreateSolidBrush(m_RectangeRgb);
m_RectRGB.GetWindowRect(m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = pDC.SelectObject(&m_newBrush);
pDC.Rectangle(m_GetPictureRect);
pDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
{
if (m_IsChose)
m_rctCurTracker.Draw(&pDC,&m_SPen,&m_DPen,m_ColorHandle);
CPen m_Pen(PS_SOLID, 1, m_RectangeRgb);
CPen* m_OldPen;
m_OldPen = NULL;
m_OldPen = pDC.SelectObject(&m_Pen);
CBrush* m_CBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
pDC.SelectObject(m_CBrush);
CRect rct;
m_rctCurTracker.GetTrueRect(&rct);
pDC.Rectangle(&rct);
CSize rct_size;
for (int i = 0; i < MAX_RECT_NUM; i++)
{
m_rctTracker[i].GetTrueRect(&rct);
rct_size = m_rctTracker[i].m_rect.Size();
if (rct_size.cx * rct_size.cy == 0 || i == m_rectChoseNum)
{
continue;
}
pDC.Rectangle(&rct);
}
m_Pen.DeleteObject();
}
}
}
HCURSOR CMFCApplicationCRectTrackerDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
BOOL CMFCApplicationCRectTrackerDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_KEYDOWN)
{
switch (pMsg->wParam)
{
case VK_LEFT:
m_dirct = 1;
break;
case VK_RIGHT:
m_dirct = 2;
break;
case VK_UP:
m_dirct = 3;
break;
case VK_DOWN:
m_dirct = 4;
break;
case VK_DELETE:
m_dirct = 5;
break;
default:
m_dirct = 0;
break;
}
ChangeRectPt(m_dirct);
}
return CDialogEx::PreTranslateMessage(pMsg);
}
void CMFCApplicationCRectTrackerDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
BOOL IsInRct = FALSE;
int i = 0;
do
{
if (m_rctTracker[i].HitTest(point)<0)
{
IsInRct = FALSE;
}
else
{
IsInRct = TRUE;
m_rectChoseNum = i;
m_rctCurTracker = m_rctTracker[m_rectChoseNum];
m_IsChose = TRUE;
break;
}
i++;
} while (i<m_rectNum);
if (!IsInRct)
{
CMyCrectTracker temRectTracker;
CRect p_rect;
temRectTracker.TrackRubberBand(this,point);
temRectTracker.m_rect.NormalizeRect();
if (p_rect.IntersectRect(temRectTracker.m_rect,m_rctCurTracker.m_rect))
m_IsChose = TRUE;
else
{
m_IsChose = FALSE;
if (m_IsDraw)
{
m_rctTracker[m_rectNum].m_rect = temRectTracker.m_rect;
m_rctCurTracker.m_rect = temRectTracker.m_rect;
CClientDC dc(this);
m_rctCurTracker.Draw(&dc, &m_SPen, &m_DPen, m_ColorHandle);
m_rectChoseNum = m_rectNum;
m_rectNum++;
if (m_rectNum>MAX_RECT_NUM)
{
m_rectNum = MAX_RECT_NUM;
MessageBox(_T("已画区域超出上限,不能继续绘画!"),_T("警告!"),MB_OK|MB_ICONWARNING);
}
m_IsChose = TRUE;
m_IsDraw = FALSE;
Invalidate();
}
}
Invalidate();
}
else
{
CClientDC pc(this);
int m_StyleIndex = 0;
int m_GetMoveStep = 0;
int m_GetHandleSize = 0;
m_StyleIndex = m_Style.GetCurSel();
m_GetMoveStep = m_MoveStep.GetCurSel() + 1;
m_FlaMoveStep = m_GetMoveStep;
m_GetHandleSize = m_HandleSize.GetPos();
switch (m_StyleIndex)
{
case 0:
StyleSelected = CMyCrectTracker::solidLine;
break;
case 1:
StyleSelected = CMyCrectTracker::dottedLine;
break;
default:
break;
}
if (m_ResizeInside.GetCheck() == BST_CHECKED)
{
HandleDirSelected = CMyCrectTracker::resizeInside;
}
if (m_ResizeOutside.GetCheck() == BST_CHECKED)
{
HandleDirSelected = CMyCrectTracker::resizeOutside;
}
m_rctCurTracker.m_nStyle = StyleSelected | HandleDirSelected;
m_rctCurTracker.m_nHandleSize = m_GetHandleSize;
m_rctCurTracker.Track(this,point);
m_rctCurTracker.m_rect.NormalizeRect();
m_rctTracker[m_rectChoseNum] = m_rctCurTracker;
m_IsChose = TRUE;
Invalidate();
}
CDialogEx::OnLButtonDown(nFlags, point);
}
BOOL CMFCApplicationCRectTrackerDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (pWnd==this&&m_rctCurTracker.SetCursor(this,nHitTest))
{
return TRUE;
}
return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
}
void CMFCApplicationCRectTrackerDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CDialogEx::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMFCApplicationCRectTrackerDlg::OnBnClickedButtondraw()
{
int m_StyleIndex=0;
int m_GetMoveStep=0;
int m_GetHandleSize=0;
m_StyleIndex =m_Style.GetCurSel();
m_GetMoveStep = m_MoveStep.GetCurSel()+1;
m_FlaMoveStep = m_GetMoveStep;
m_GetHandleSize = m_HandleSize.GetPos();
switch (m_StyleIndex)
{
case 0:
StyleSelected = CMyCrectTracker::solidLine;
break;
case 1:
StyleSelected = CMyCrectTracker::dottedLine;
break;
default:
break;
}
if (m_ResizeInside.GetCheck()==BST_CHECKED)
{
HandleDirSelected = CMyCrectTracker::resizeInside;
}
if (m_ResizeOutside.GetCheck() == BST_CHECKED)
{
HandleDirSelected = CMyCrectTracker::resizeOutside;
}
m_rctCurTracker.m_rect.SetRect(0, 0, 0, 0);
m_rctCurTracker.m_nStyle = StyleSelected | HandleDirSelected;
m_rctCurTracker.m_nHandleSize = m_GetHandleSize;
m_IsDraw = TRUE;
}
void CMFCApplicationCRectTrackerDlg::ChangeRectPt(int ChangeDir)
{
CRect rct;
CRect rect2;
CClientDC PDC(this);
int CPenOld=0 ;
rct = m_rctCurTracker.m_rect;
switch (ChangeDir)
{
case 1:
rct.TopLeft().x-= m_FlaMoveStep;
rct.BottomRight().x-= m_FlaMoveStep;
break;
case 2:
rct.TopLeft().x += m_FlaMoveStep;
rct.BottomRight().x+= m_FlaMoveStep;
break;
case 3:
rct.TopLeft().y-= m_FlaMoveStep;
rct.BottomRight().y-= m_FlaMoveStep;
break;
case 4:
rct.TopLeft().y+= m_FlaMoveStep;
rct.BottomRight().y+= m_FlaMoveStep;
break;
case 5:
m_rctCurTracker.m_rect.SetRect(-10, -10, -10, -10);
m_rctTracker[m_rectChoseNum] = m_rctCurTracker;
m_rctCurTracker.GetTrueRect(&rect2);
RedrawWindow();
Invalidate();
return;
}
m_rctCurTracker.m_rect.SetRect(rct.TopLeft(),rct.BottomRight());
m_rctTracker[m_rectChoseNum] = m_rctCurTracker;
if (ChangeDir!=0)
{
Invalidate();
}
m_dirct = 0;
}
void CMFCApplicationCRectTrackerDlg::OnBnClickedButtonsavepicture()
{
CBitmap m_PictureSaveToPC;
CDC m_DcSave;
CClientDC m_SaveDc(this);
CString CFilePathName;
TCHAR szFilter[] = _T("*.JPG图片文件(.JPG)|*.txt|配置文件(.ini)|*.ini|word文件(.doc)|*.doc|所有文件(*.*)|*.*||");
CFileDialog dlg(FALSE,_T(".JPG"), _T("m_PictureSaveToPC.JPG"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this, 0, TRUE);
if (dlg.DoModal() == IDCANCEL)
{
MessageBox(_T("保存文件已取消!"), _T("信息提示!"), MB_OK | MB_OKCANCEL | MB_ICONINFORMATION);
return;
}
CFilePathName = dlg.m_ofn.lpstrFile;
CFilePathName.TrimRight(_T(".txt"));
CFilePathName = CFilePathName + dlg.m_ofn.lpstrDefExt;
if (m_IsChose==TRUE)
{
m_PictureSaveToPC.CreateCompatibleBitmap(&m_SaveDc, m_rctCurTracker.m_rect.Width(), m_rctCurTracker.m_rect.Height());
m_DcSave.CreateCompatibleDC(&m_SaveDc);
m_DcSave.SelectObject(m_PictureSaveToPC);
m_DcSave.BitBlt(0,0, m_rctCurTracker.m_rect.Width(), m_rctCurTracker.m_rect.Height(),&m_SaveDc, m_rctCurTracker.m_rect.left, m_rctCurTracker.m_rect.top,SRCCOPY);
CImage m_Image;
m_Image.Attach((HBITMAP)m_PictureSaveToPC);
m_Image.Save(CFilePathName);
m_Image.Detach();
MessageBox(_T("选择区域已保存到:")+ CFilePathName+_T("目录下!"), _T("信息提示:"), MB_OK | MB_ICONINFORMATION);
m_PictureSaveToPC.DeleteObject();
m_DcSave.DeleteDC();
}
else
{
MessageBox(_T("当前要保存的区域没有选中,请先选中后重试!"),_T("信息提示:"),MB_OK|MB_ICONERROR);
}
}
void CMFCApplicationCRectTrackerDlg::OnBnClickedCheckresizeinside()
{
CheckDlgButton(IDC_CHECKRESIZEOUTSIDE,0);
}
void CMFCApplicationCRectTrackerDlg::OnBnClickedCheckresizeoutside()
{
CheckDlgButton(IDC_CHECKRESIZEINSIDE,0);
}
void CMFCApplicationCRectTrackerDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect m_ClickedRct;
CPoint ptCurPos;
GetCursorPos(&ptCurPos);
GetDlgItem(IDC_STATICSOLIDRGB)->GetWindowRect(&m_ClickedRct);
if (m_ClickedRct.PtInRect(ptCurPos))
{
CColorDialog DlgSolidRGB(SolidRgb);
CRect m_GetPictureRect;
CBrush m_newBrush;
CBrush* m_oldBrush;
CClientDC clientDC(this);
if (IDOK == DlgSolidRGB.DoModal())
{
SolidRgb = DlgSolidRGB.GetColor();
m_newBrush.CreateSolidBrush(SolidRgb);
m_SolidRGB.GetWindowRect(&m_GetPictureRect);
m_SPen.DeleteObject();
m_SPen.CreatePen(PS_SOLID,1,SolidRgb);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = clientDC.SelectObject(&m_newBrush);
clientDC.Rectangle(m_GetPictureRect);
clientDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
MessageBox(_T("已选择SolidStyle风格模式画笔颜色!"), _T("信息提示"), MB_ICONINFORMATION);
}
}
GetDlgItem(IDC_STATICDASHAPENRGB)->GetWindowRect(&m_ClickedRct);
if (m_ClickedRct.PtInRect(ptCurPos))
{
CColorDialog DlgDashaRGB(DashaRgb);
CRect m_GetPictureRect;
CBrush m_newBrush;
CBrush* m_oldBrush;
CClientDC clientDC(this);
if (IDOK == DlgDashaRGB.DoModal())
{
DashaRgb = DlgDashaRGB.GetColor();
m_newBrush.CreateSolidBrush(DashaRgb);
m_DashRGB.GetWindowRect(&m_GetPictureRect);
m_DPen.DeleteObject();
m_DPen.CreatePen(PS_DASHDOT, 1, DashaRgb);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = clientDC.SelectObject(&m_newBrush);
clientDC.Rectangle(m_GetPictureRect);
clientDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
MessageBox(_T("已选择DashDot风格模式画笔颜色!"), _T("信息提示"), MB_ICONINFORMATION);
}
}
GetDlgItem(IDC_STATICHANDLERGB)->GetWindowRect(&m_ClickedRct);
if (m_ClickedRct.PtInRect(ptCurPos))
{
CColorDialog DlgHandRGB(m_ColorHandle);
CRect m_GetPictureRect;
CBrush m_newBrush;
CBrush* m_oldBrush;
CClientDC clientDC(this);
if (IDOK == DlgHandRGB.DoModal())
{
m_ColorHandle = DlgHandRGB.GetColor();
m_newBrush.CreateSolidBrush(m_ColorHandle);
m_handleRGB.GetWindowRect(&m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = clientDC.SelectObject(&m_newBrush);
clientDC.Rectangle(m_GetPictureRect);
clientDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
MessageBox(_T("已成功选择Handle调节手柄的颜色!"), _T("信息提示"), MB_ICONINFORMATION);
}
}
GetDlgItem(IDC_STATICRECTANGE)->GetWindowRect(&m_ClickedRct);
if (m_ClickedRct.PtInRect(ptCurPos))
{
CColorDialog DlgRectangeRGB(m_RectangeRgb);
CRect m_GetPictureRect;
CBrush m_newBrush;
CBrush* m_oldBrush;
CClientDC clientDC(this);
if (IDOK == DlgRectangeRGB.DoModal())
{
m_RectangeRgb = DlgRectangeRGB.GetColor();
m_newBrush.CreateSolidBrush(m_RectangeRgb);
m_RectRGB.GetWindowRect(&m_GetPictureRect);
ScreenToClient(&m_GetPictureRect);
m_oldBrush = clientDC.SelectObject(&m_newBrush);
clientDC.Rectangle(m_GetPictureRect);
clientDC.SelectObject(m_oldBrush);
m_newBrush.DeleteObject();
MessageBox(_T("已成功选择绘制边框颜色!"), _T("信息提示"), MB_ICONINFORMATION);
}
}
CDialogEx::OnLButtonUp(nFlags, point);
}
void CMFCApplicationCRectTrackerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
}
void CMFCApplicationCRectTrackerDlg::OnNMCustomdrawSliderhandlesize(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
int m_GetSliderValue = m_HandleSize.GetPos();
SetDlgItemInt(IDC_STATICSLIDERVALUE, m_GetSliderValue);
*pResult = 0;
}
工程文件H头文件:?
#include"CMyCrectTracker.h"
#pragma once
class CMFCApplicationCRectTrackerDlg : public CDialogEx
{
public:
CMFCApplicationCRectTrackerDlg(CWnd* pParent = nullptr);
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MFCAPPLICATIONCRECTTRACKER_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CMyCrectTracker m_rctCurTracker; //当前选中的矩形区域
CMyCrectTracker m_rctTracker[MAX_RECT_NUM]; //存储自绘矩形区域
BOOL m_IsChose; //标记是否选中
BOOL m_IsDraw; //标记按钮是否按下
int m_rectNum; //当前实际已绘矩形的个数
int m_rectChoseNum; //当前选中矩形的编号
int m_FlaMoveStep; //键盘方向键没响应一次图像移动的像素单位上的步长
int m_dirct; //用于标记那个方向键按下。1:左,2:右,3:上,4:下,5:delete
UINT StyleSelected;
UINT HandleDirSelected;
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnBnClickedButtondraw();
afx_msg void ChangeRectPt(int ChangeDir);
afx_msg void OnBnClickedButtonsavepicture();
CComboBox m_Style;
CComboBox m_MoveStep;
CButton m_ResizeInside;
CButton m_ResizeOutside;
CSliderCtrl m_HandleSize;
afx_msg void OnBnClickedCheckresizeinside();
afx_msg void OnBnClickedCheckresizeoutside();
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
CStatic m_SolidRGB;
CStatic m_DashRGB;
CStatic m_handleRGB;
CStatic m_RectRGB;
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnNMCustomdrawSliderhandlesize(NMHDR* pNMHDR, LRESULT* pResult);
};
|