📄 cursoreditordlg.cpp
字号:
// CursorEditorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CursorEditor.h"
#include "CursorEditorDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "CorrectCursorSizeDlg.h"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
VOID CALLBACK func(int x, int y, LPARAM lpdata)
{
CPoint point;
CRect rect;
CCursorEditorDlg *CurDlg=(CCursorEditorDlg *)lpdata;
point.x=x;
point.y=y;
// TRACE("FUNC %d,%d\n",x,y);
// for(int i=0; i<CurDlg->m_nMaxSelCurPointCount; i++)
// {
// CurDlg->m_pSelCur[i].m_nColor=RGB(0,0,0);
// }
CurDlg->EditLineCurDrawRect(point);
// CurDlg->PreviewDrawLineCur();
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCursorEditorDlg dialog
CCursorEditorDlg::CCursorEditorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCursorEditorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCursorEditorDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCursorEditorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCursorEditorDlg)
DDX_Control(pDX, IDC_STATIC3, m_static3);
DDX_Control(pDX, IDC_STATIC1, m_static1);
DDX_Control(pDX, IDC_PICTURE1, m_Picture);
DDX_Control(pDX, IDC_STATIC2, m_pStatic);
DDX_Control(pDX, IDC_COMBO1, m_combo1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCursorEditorDlg, CDialog)
//{{AFX_MSG_MAP(CCursorEditorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTTON1, OnLoadCurFile)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON2, OnSetPointMode)
ON_BN_CLICKED(IDC_BUTTON3, OnSetLineMode)
ON_BN_CLICKED(IDC_BUTTON4, OnSaveCurToFile)
ON_BN_CLICKED(IDC_BUTTON5, OnAddCurToFile)
ON_BN_CLICKED(IDC_BUTTON6, OnDeleteCursorInFile)
ON_BN_CLICKED(IDC_BUTTON7, OnCorrectCursorSize)
ON_BN_CLICKED(IDC_BUTTON8, OnClearButton)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCursorEditorDlg message handlers
BOOL CCursorEditorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CCorrectCursorSizeDlg CurSizeDlg;
m_nMaxCol=m_nMaxRow=CurSizeDlg.m_nEditCurSize;
CWnd *cbutton;
cbutton=GetDlgItem(IDC_BUTTON2);
CString btstr;
btstr="【画点】";
cbutton->SetWindowText(btstr);
m_pStatic.cCellSize.cx=5;
m_pStatic.cCellSize.cy=5;
strszfile="";
m_nMaxSelCurPointCount=m_nMaxCol*m_nMaxRow;
m_ncurcount=0;
startCurBuf=0;
m_nComboSel=-1;
m_pSelCur=new CursorBuffer[m_nMaxSelCurPointCount];
m_pLineCur=NULL;
staticRow=0;
staticCol=0;
IsSave=1;
m_pMaxCurBuffer.RemoveAll();
CursorBuffer pBuffer;
pBuffer.m_nCol=0;
pBuffer.m_nColor=RGB(0,0,0);
pBuffer.m_nRow=0;
for(int k=0; k<m_nMaxSelCurPointCount; k++)
{
m_pMaxCurBuffer.Add(pBuffer);
}
for(int i=0; i<m_nMaxRow; i++)
{
for(int j=0; j<m_nMaxCol; j++)
{
m_pSelCur[i*m_nMaxRow+j].m_nCol=j;
m_pSelCur[i*m_nMaxRow+j].m_nRow=i;
m_pSelCur[i*m_nMaxRow+j].m_nColor=RGB(0,0,0);
}
}
CUR_EDIT_MODE=PICTURE_POINT_MODE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CCursorEditorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCursorEditorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
m_pStatic.MoveWindow(CRect(130, 70,
130+m_pStatic.cCellSize.cx*m_nMaxCol,70+m_pStatic.cCellSize.cy*m_nMaxRow));
m_Picture.MoveWindow(CRect(320,340,320+m_nMaxCol,340+m_nMaxRow));
CString strsize;
strsize.Format("%d X %d",m_nMaxCol,m_nMaxRow);
m_static3.SetWindowText(strsize);
CDC *pDc;
pDc=m_pStatic.GetDC();
CBrush pBrush(RGB(0,0,0));
CRect prect;
m_pStatic.GetClientRect(&prect);
pDc->FillRect(&prect,&pBrush);
int pmultiple=0; //刷新编辑部分m_pStatic
CRect pcrect;
m_pStatic.GetClientRect(&pcrect);
pmultiple=m_pStatic.cCellSize.cx;
int xlef=0; int xright=0; int ybottom=0; int ytop=0;
for(int j=startCurBuf; j<(startCurBuf+m_nMaxSelCurPointCount); j++)
{
if(m_pSelCur[j-startCurBuf].m_nColor!=RGB(0,0,0))
{
xlef=(m_pSelCur[j-startCurBuf].m_nCol)*pmultiple;
ytop=(m_pSelCur[j-startCurBuf].m_nRow)*pmultiple;
xright=(m_pSelCur[j-startCurBuf].m_nCol+1)*pmultiple;
ybottom=(m_pSelCur[j-startCurBuf].m_nRow+1)*pmultiple;
CRect picRect(xlef,ytop,xright,ybottom);
pDc->FillSolidRect(&picRect,m_pSelCur[j-startCurBuf].m_nColor);
}
}
CRect rectDraw = prect;
CPen cPen(PS_SOLID,0,RGB(255,0,0));
CPen *pOldPen=(CPen *)pDc->SelectObject(&cPen);
for(int x=prect.left; x<=prect.right; x+=m_pStatic.cCellSize.cx)
{
pDc->MoveTo(x,prect.top);
pDc->LineTo(x,prect.bottom);
}
for(int y=prect.top; y<=prect.bottom; y+=m_pStatic.cCellSize.cy)
{
pDc->MoveTo(prect.left,y);
pDc->LineTo(prect.right,y);
}
pDc->SelectObject(pOldPen);
m_pStatic.ReleaseDC(pDc);
CRect crect;
m_Picture.GetClientRect(&crect);
CDC *cpDC; //刷新预览部分m_Picture;
cpDC=m_Picture.GetDC();
cpDC->FillRect(&crect,&pBrush);
for(int i=startCurBuf; i<(startCurBuf+m_nMaxSelCurPointCount); i++)
{
xlef=(m_pSelCur[i-startCurBuf].m_nCol);
ytop=(m_pSelCur[i-startCurBuf].m_nRow);
xright=(m_pSelCur[i-startCurBuf].m_nCol+1);
ybottom=(m_pSelCur[i-startCurBuf].m_nRow+1);
CRect picRect(xlef,ytop,xright,ybottom);
cpDC->FillSolidRect(&picRect,m_pSelCur[i-startCurBuf].m_nColor);
}
m_Picture.ReleaseDC(cpDC);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCursorEditorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
HBRUSH CCursorEditorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
CWnd * pdWnd =GetDlgItem(IDC_STATIC2);
CDC * ppDC=pdWnd->GetDC();
pdWnd->Invalidate();
pdWnd->UpdateWindow();
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CCursorEditorDlg::OnLoadCurFile()
{
CString szFileter= _T("dat files(*.dat)|*.dat|all files(*.*)|*.*||");
CFileDialog file(TRUE,"dat","*.dat",OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER ,szFileter);
if(file.DoModal()==IDOK)
{
strszfile=file.GetPathName();
m_combo1.SetEditSel(0,-1);
for(int j=m_ncurcount; j>=0; j--)
{
m_combo1.DeleteString(j);
}
if(SaveCurToClass())
{
CString strcombo;
for(int i=1;i<=m_ncurcount;i++)
{
strcombo.Format(_T(">>--%d--<<"),i);
m_combo1.AddString(strcombo);
}
m_combo1.SetCurSel(m_nComboSel);
}
}
Invalidate(TRUE);
}
BOOL CCursorEditorDlg::SaveCurToClass()
{
FILE *fp;
fp=fopen(strszfile,"r");
if(!fp) return FALSE;
CWnd *cbutton1,*cbutton2;
cbutton1=GetDlgItem(IDC_BUTTON2);
cbutton2=GetDlgItem(IDC_BUTTON3);
cbutton1->EnableWindow(TRUE);
cbutton2->EnableWindow(TRUE);
CUR_EDIT_MODE=PICTURE_POINT_MODE;
char txt[256];
fgets(txt,sizeof(txt)-1,fp);
CString strcur;
char *b;
b=txt;
int s=0;
while(*b)
{
if((*b==' ' || *b=='\n') && s==0)
{
s++;
m_ncurcount=atol(strcur);
strcur.Empty();
b++;
continue;
}
if((*b==' ' || *b=='\n') && s==1)
{
s++;
m_nMaxCol=atol(strcur);
strcur.Empty();
b++;
continue;
}
if((*b==' ' || *b=='\n') && s==2)
{
s++;
m_nMaxRow=atol(strcur);
strcur.Empty();
b++;
continue;
}
strcur+=*b;
b++;
}
m_nMaxSelCurPointCount=m_nMaxRow*m_nMaxCol; //所打开文件中每个光标所含象素个数
int Maxcur=m_ncurcount*m_nMaxSelCurPointCount; //该文件所有光标象素总个数
m_pMaxCurBuffer.RemoveAll();
if(m_ncurcount==0)
{
fclose(fp);
delete m_pSelCur;
m_pSelCur=new CursorBuffer[m_nMaxSelCurPointCount];
for(int m=0; m<m_nMaxRow; m++)
{
for(int n=0; n<m_nMaxCol; n++)
{
m_pSelCur[m*m_nMaxRow+n].m_nCol=n;
m_pSelCur[m*m_nMaxRow+n].m_nRow=m;
m_pSelCur[m*m_nMaxRow+n].m_nColor=RGB(0,0,0);
}
}
m_nComboSel=-1;
cbutton1->EnableWindow(FALSE);
cbutton2->EnableWindow(FALSE);
CUR_EDIT_MODE=INVALID_MODE;
MessageBox("您的文件没有光标",NULL,MB_OK);
return false;
}
CursorBuffer pBuffer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -