📄 imagepercentdlg.cpp
字号:
// ImagePercentDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ImagePercent.h"
#include "ImagePercentDlg.h"
#include "olorForm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CImagePercentDlg dialog
CImagePercentDlg::CImagePercentDlg(CWnd* pParent /*=NULL*/)
: CDialog(CImagePercentDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CImagePercentDlg)
m_editSilder = 0;
m_number = _T("");
m_total = _T("");
m_group = _T("");
m_percent = _T("");
m_groupname = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CImagePercentDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CImagePercentDlg)
DDX_Control(pDX, IDC_SCROLLBAR, m_ScrollBar);
DDX_Text(pDX, IDC_EDIT_SILDER, m_editSilder);
DDX_Text(pDX, IDC_STATIC_NUMBER, m_number);
DDX_Text(pDX, IDC_STATIC_TOTAL, m_total);
DDX_Text(pDX, IDC_STATIC_GROUP, m_group);
DDX_Text(pDX, IDC_STATIC_PENCENT, m_percent);
DDX_Control(pDX, IDC_JPGSHOWCTLCTRL, m_show02);
DDX_Text(pDX, IDC_STATIC_GROUPNAME, m_groupname);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CImagePercentDlg, CDialog)
//{{AFX_MSG_MAP(CImagePercentDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_BUTTON_SET, OnButtonSet)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
ON_BN_CLICKED(IDC_BUTTON_TJ, OnButtonTj)
ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_GROUP, OnDeltaposSpinGroup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImagePercentDlg message handlers
BOOL CImagePercentDlg::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
// TODO: Add extra initialization here
x0 = 14;
x1 = 526;
y0 = 368;
y1 = 388;
pox = x0+1;
poy = y1;
m_editSilder = 0;
m_lmouseBottom = FALSE;
crect.left = x0-5;
crect.right = x1+5;
crect.top = y1;
crect.bottom = y1+10;
crectv.left = x0-5;
crectv.right = x1+5;
crectv.top = y0;
crectv.bottom = y1+10;
crectw.left = 543;
crectw.right = 595;
crectw.top = 212;
crectw.bottom = 231;
m_selectedPos = 0;
hasGroup = FALSE;
selStart = -1;
return TRUE; // return TRUE unless you set the focus to a control
}
void CImagePercentDlg::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 CImagePercentDlg::OnPaint()
{
int i;
CPaintDC dc(this); // device context for painting
dc.Rectangle(x0,y0,x1,y1);
for(i=0;i<256;i++)
{
CPen pen(PS_SOLID,1,RGB(255,i,0));
CPen* oldPen = dc.SelectObject(&pen);
dc.MoveTo(x0+1+i,y0+1);
dc.LineTo(x0+1+i,y1-1);
dc.SelectObject(oldPen);
}
for(i=1;i<256;i++)
{
CPen pen(PS_SOLID,1,RGB(255-i,255,0));
CPen* oldPen = dc.SelectObject(&pen);
dc.MoveTo(x0+255+i,y0+1);
dc.LineTo(x0+255+i,y1-1);
dc.SelectObject(oldPen);
}
CPen pen0(PS_SOLID,1,RGB(255,0,0));
CPen* oldPen0 = dc.SelectObject(&pen0);
dc.MoveTo(pox-2,poy+10);
dc.LineTo(pox,poy+1);
dc.LineTo(pox+2,poy+10);
dc.LineTo(pox-2,poy+10);
dc.SelectObject(oldPen0);
for(i=0;i<m_selectedPos;i++)
{
CPen pen1(PS_SOLID,1,RGB(0,0,255));
CPen* oldPen1 = dc.SelectObject(&pen1);
dc.MoveTo(selectedPos[i]+x0+1,y0+1);
dc.LineTo(selectedPos[i]+x0+1,y1-1);
dc.SelectObject(oldPen1);
}
if(hasGroup)
{
int n = crectw.right-crectw.left;
float sx = 1.0f*(selectedPos[selEnd]-selectedPos[selStart])/n;
for(int i=0;i<n;i++)
{
int v = crectw.left+i;
int pos = (int)(i*sx)+selectedPos[selStart];
if(pos<256)
{
CPen pen(PS_SOLID,1,RGB(255,pos,0));
CPen* oldPen = dc.SelectObject(&pen);
dc.MoveTo(v,crectw.top);
dc.LineTo(v,crectw.bottom);
dc.SelectObject(oldPen);
}
else
{
CPen pen(PS_SOLID,1,RGB(255-pos,255,0));
CPen* oldPen = dc.SelectObject(&pen);
dc.MoveTo(v,crectw.top);
dc.LineTo(v,crectw.bottom);
dc.SelectObject(oldPen);
}
}
}
CDialog::OnPaint();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CImagePercentDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CImagePercentDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,"jpg",".jpg",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"位图文件(*.JPG)|*.JPG|所有文件(*.*)|*.*|");
if(dlg.DoModal()==IDOK)
{
caculate();
CString str = dlg.GetPathName();
m_show02.ShowFileName(str);
//-----确定当前位图的位置
iPos=0;
while(family[iPos] != str) {iPos++;}
m_number.Format("第 %d 张",iPos+1);
m_total.Format("共 %d 张",picnum);
m_ScrollBar.SetScrollRange(0,picnum-1);
m_ScrollBar.SetScrollPos(iPos);
UpdateData(false);
}
}
void CImagePercentDlg::OnButtonSet()
{
// TODO: Add your control notification handler code here
m_editSilder = pox-x0-1;
selectedPos[m_selectedPos++] = m_editSilder;
DoSort();
if(m_selectedPos > 1)
{
hasGroup = TRUE;
if(selStart == -1)
{
selStart = 0;
selEnd = 1;
m_groupname.Format("第 %d 组",selStart+1);
}
}
UpdateData(FALSE);
InvalidateRect(crectv);
InvalidateRect(crectw);
}
void CImagePercentDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_lmouseBottom)
{
if(point.x > x0 && point.x < x1)
{
if(point.y > poy && point.y < poy+11)
{
pox = point.x;
InvalidateRect(crect,TRUE);
}
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CImagePercentDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_lmouseBottom = TRUE;
if(point.x > x0 && point.x < x1)
{
if(point.y > poy && point.y < poy+11)
{
pox = point.x;
InvalidateRect(crect,TRUE);
}
}
CDialog::OnLButtonDown(nFlags, point);
}
void CImagePercentDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_lmouseBottom = FALSE;
CDialog::OnLButtonUp(nFlags, point);
}
void CImagePercentDlg::caculate()
{
picnum=0;
CFileFind finder;
Work = finder.FindFile("*.JPG");
while(Work)
{
char FileName[250];
Work=finder.FindNextFile();
sprintf(FileName,"%s",finder.GetFilePath());
family[picnum++]=FileName;
}
iPos=-1;
}
void CImagePercentDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
switch(nSBCode)
{
case SB_LINERIGHT:
{
if(iPos<picnum-1)
{
iPos+=1;
m_ScrollBar.SetScrollPos(iPos);
m_number.Format("第 %d 张",iPos+1);
m_total.Format("共 %d 张",picnum);
m_show02.ShowFileName(family[iPos]);
}
}
break;
case SB_LINELEFT:
{
if(iPos>0)
{
iPos-=1;
m_ScrollBar.SetScrollPos(iPos);
m_number.Format("第 %d 张",iPos+1);
m_total.Format("共 %d 张",picnum);
m_show02.ShowFileName(family[iPos]);
}
}
break;
case SB_THUMBTRACK:
{
iPos=nPos;
m_ScrollBar.SetScrollPos(iPos);
m_show02.ShowFileName(family[iPos]);
m_number.Format("第 %d 张",iPos+1);
m_total.Format("共 %d 张",picnum);
}
break;
}
UpdateData(false);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CImagePercentDlg::OnButtonReset()
{
// TODO: Add your control notification handler code here
m_selectedPos = 0;
hasGroup = FALSE;
selStart = -1;
m_groupname.Format("");
UpdateData(false);
InvalidateRect(crectv);
InvalidateRect(crectw);
}
void CImagePercentDlg::DoSort()
{
int i,j,k;
for(i=0;i<m_selectedPos-1;i++)
{
for(j=i+1;j<m_selectedPos;j++)
{
if(selectedPos[i] > selectedPos[j])
{
k = selectedPos[i];
selectedPos[i] = selectedPos[j];
selectedPos[j] = k;
}
}
}
for(i=0;i<m_selectedPos-1;i++)
{
while(i < m_selectedPos-1 && selectedPos[i] == selectedPos[i+1])
{
for(j=i;j<m_selectedPos-1;j++) selectedPos[j] = selectedPos[j+1];
m_selectedPos--;
}
}
}
void CImagePercentDlg::OnButtonTj()
{
// TODO: Add your control notification handler code here
DoSort();
if(picnum < 1)
{
AfxMessageBox("无分析图片。");
return;
}
if(m_selectedPos > 1)
{
int i;
for(i=0;i<picnum;i++)
{
}
m_group.Format("第 %d 组",iPos+1);
m_percent.Format("含 %d %",percent[iPos][0]);
}
else
{
AfxMessageBox("分组不够。");
}
}
void CImagePercentDlg::OnOK()
{
// TODO: Add extra validation here
int i;
CFileDialog dlg(FALSE,"txt",".txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.TXT)|*.TXT||");
if(dlg.DoModal()==IDOK)
{
for(i=0;i<picnum;i++)
{
//执行输出
CBitmap bp;
}
}
}
void CImagePercentDlg::OnButtonTest()
{
// TODO: Add your control notification handler code here
ColorForm dlg;
dlg.DoModal();
}
void CImagePercentDlg::OnDeltaposSpinGroup(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -