measuredlg.cpp

来自「一个长度信息管理系统。主要包含了界面编程和对文件操作。」· C++ 代码 · 共 422 行

CPP
422
字号
// MeasureDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Measure.h"
#include "MeasureDlg.h"
#include "DanGeLuRuDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "PiliangPutin.h"
#include "LengthView.h"
#include "LengthInq.h"
#include "DataPutOut.h"
#include "BDialog.h"

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMeasureDlg dialog

CMeasureDlg::CMeasureDlg(CWnd* pParent /*=NULL*/)
: CBDialog(CMeasureDlg::IDD, pParent)
{
	m_brush.CreateSolidBrush(RGB(108,166,205));
//{{AFX_DATA_INIT(CMeasureDlg)
	//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMeasureDlg::DoDataExchange(CDataExchange* pDX)
{
	CBDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMeasureDlg)
	DDX_Control(pDX, IDC_EDIT1, m_shuoming);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Control(pDX, IDC_LIST2, m_list2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMeasureDlg, CBDialog)
//{{AFX_MSG_MAP(CMeasureDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DANGELURU, OnDangeluru)
ON_BN_CLICKED(IDC_PILIANGLURU, OnPiliangluru)
ON_BN_CLICKED(IDC_LIULAN, OnLiulan)
ON_BN_CLICKED(IDC_CHAXUN, OnChaxun)
ON_BN_CLICKED(IDC_shujudaochu, Onshujudaochu)
ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMeasureDlg message handlers

BOOL CMeasureDlg::OnInitDialog()
{
	CBDialog::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
	SetBitmapStyle(StyleStretch);
	SetBitmap(IDB_BITMAP1);

    m_list2.InsertItem(0,"长度信息管理程序");
	m_list2.InsertItem(1,"●数据录入");
	m_list2.InsertItem(2,"●长度浏览");
	m_list2.InsertItem(3,"●长度查询");
	m_list2.InsertItem(4,"●数据导出");
	
	//导入图片
	CWinApp* pApp = AfxGetApp();
    
	m_imglist.Create ( 48, 48, ILC_COLOR16 | ILC_MASK, 5, 1 );
	
    dglr = reinterpret_cast<HICON>(
		::LoadImage ( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_DGLR),
		IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR ));
	m_imglist.Add ( dglr );
    pllr = reinterpret_cast<HICON>(
		::LoadImage ( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_PLLR),
		IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR ));
	m_imglist.Add (pllr);
    cdll = reinterpret_cast<HICON>(
		::LoadImage ( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CDLL),
		IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR ));
	m_imglist.Add (cdll);
    cdcx = reinterpret_cast<HICON>(
		::LoadImage ( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CDCX),
		IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR ));
	m_imglist.Add (cdcx);
	
	sjdc = reinterpret_cast<HICON>(
		::LoadImage ( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SJDC),
		IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR ));
	m_imglist.Add (sjdc);
	
    m_list1.SetColumnWidth ( 0, LVSCW_AUTOSIZE );
    m_list1.SetExtendedStyle ( LVS_EX_FULLROWSELECT );
    m_list1.SetImageList ( &m_imglist, LVSIL_NORMAL );
	m_list1.InsertItem ( 0, _T("单个录入"), 0 );
	m_list1.InsertItem ( 1, _T("批量录入"), 1 );
	
	n=1;
	k=1;
	m_shuoming.SetWindowText("\r\n    本模块是数据录入模块,可实现“单个录\r\n入”、“批量录入”\
两种功能,当需要建立新\r\n数据请用“单个录入”,当需要调用系统已有\r\n的数据请用“批量录入”。");

	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMeasureDlg::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 CMeasureDlg::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
	{
		CBDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMeasureDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMeasureDlg::OnDangeluru() 
{
	// TODO: Add your control notification handler code here
	
}



void CMeasureDlg::OnPiliangluru() 
{
	// TODO: Add your control notification handler code here
	
}

void CMeasureDlg::OnLiulan() 
{
	// TODO: Add your control notification handler code here
    
	
}

void CMeasureDlg::OnChaxun() 
{
	// TODO: Add your control notification handler code here
    
}

void CMeasureDlg::Onshujudaochu() 
{
	// TODO: Add your control notification handler code here
    
	
}

void CMeasureDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	
	LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) pNMHDR;
	CString str;
	n=lpnmlv->iItem;
	str.Format("%d", n);
	
	m_list1.DeleteAllItems();
    m_list1.SetColumnWidth ( 0, LVSCW_AUTOSIZE );
    m_list1.SetExtendedStyle ( LVS_EX_FULLROWSELECT );
    m_list1.SetImageList ( &m_imglist, LVSIL_NORMAL );
	
      if(n==0)
	{
         switch(k)
		 {
		 case 1:
                m_list1.InsertItem ( 0, _T("单个录入"), 0 );
		        m_list1.InsertItem ( 1, _T("批量录入"), 1 );
				m_shuoming.SetWindowText("\r\n    本模块是数据录入模块,可实现“单个录\r\n入”、“批量录入”\
两种功能,当需要建立新\r\n数据请用“单个录入”,当需要调用系统已有\r\n的数据请用“批量录入”。");
				break;
		 case 2:
			    m_list1.InsertItem ( 0, _T("页面浏览"), 2 );
				m_shuoming.SetWindowText("\r\n    浏览已录入系统中的所有数据。列表中每\r\n页只显示10项,列表页数和当前页属性将显示\r\n在列表下的属性栏中。若要查看某页输入页数\r\n或点击“上页”、“下页”。");
				break;
		 case 3:
			    m_list1.InsertItem ( 0, _T("长度检索"), 3 );
				m_shuoming.SetWindowText("\r\n    查询需要的数据。若要得到某一长度值的\r\n信息,在“长度检索”输入其值,若要得到某\r\n一范围长度值的信息,在“范围检索”处输入\r\n其最大值和最小值。");
				break;
		 case 4:
			    m_list1.InsertItem ( 0, _T("导出数据"), 4 );
				m_shuoming.SetWindowText("\r\n    导出系统中需要保存的数据。将列表中选\r\n中的数据导出存放在*.txt格式的文件中,序\r\n号和长度值用“,”分开,前面是序号,后面\r\n是长度值,“;”结束。");
				break;
		 }
		
	}
	else if(n== 1)
	{	
		m_list1.InsertItem ( 0, _T("单个录入"), 0 );
		m_list1.InsertItem ( 1, _T("批量录入"), 1 );
		m_shuoming.SetWindowText("    \r\n本模块是数据录入模块,可实现“单个录\r\n入”、“批量录入”\
两种功能,当需要建立新\r\n数据请用“单个录入”,当需要调用系统已有\r\n的数据请用“批量录入”。");
		k=1;
	}
	else if(n== 2)
	{
		m_list1.InsertItem ( 0, _T("页面浏览"), 2 );
		m_shuoming.SetWindowText("\r\n    浏览已录入系统中的所有数据。列表中每\r\n页只显示10项,列表页数和当前页属性将显示\r\n在列表下的属性栏中。若要查看某页输入页数\r\n或点击“上页”、“下页”。");
				
		k=2;
	}
	else if(n== 3)
	{   
		m_list1.InsertItem ( 0, _T("长度检索"), 3 );
		m_shuoming.SetWindowText("\r\n    查询需要的数据。若要得到某一长度值的\r\n信息,在“长度检索”输入其值,若要得到某\r\n一范围长度值的信息,在“范围检索”处输入\r\n其最大值和最小值。");
		k=3;
	}
	else if(n== 4)
	{   
		m_list1.InsertItem ( 0, _T("导出数据"), 4 );
		m_shuoming.SetWindowText("\r\n    导出系统中需要保存的数据。将列表中选\r\n中的数据导出存放在*.txt格式的文件中,序\r\n号和长度值用“,”分开,前面是序号,后面\r\n是长度值,“;”结束。");
		k=4;
	}
	
	*pResult = 0;
}

void CMeasureDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_LIST1);
    ASSERT(pListCtrl != NULL);
	
	
	POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
	
	if (pos == NULL)
		TRACE0("No items were selected!\n");
	else
	{
		while (pos)
		{  
			int nItem=m_list1.GetNextSelectedItem(pos);
			
		if(k==1)	  
		{
				if(nItem==0)
					
				{
					CDanGeLuRuDlg dlg;
					dlg.DoModal();
				}
				
				else if(nItem==1)
				{
					CPiliangPutin dlg;
					dlg.DoModal();
				}
		}
		else if(k == 2)
		{
			if(nItem==0)
			{
				CLengthView dlg;
				dlg.DoModal();
			}
			
		}
		else if(k==3)
		{
				if(nItem==0)
				{
                    LengthInq dlg;
					dlg.DoModal();
				}
				
		}
		else if(k==4)
		{
				if(nItem==0)
				{
                    DataPutOut dlg;
					dlg.DoModal();
				}
				
		}
		}
	}
	
	*pResult = 0;
}

HBRUSH CMeasureDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	
	if(IDC_STATIC==pWnd->GetDlgCtrlID())
	{
		pDC->SetTextColor(RGB(255,255,225));
		pDC->SetBkMode(TRANSPARENT);
		//return m_brush;
	}
	if(IDC_EDIT1==pWnd->GetDlgCtrlID())
	{
		pDC->SetTextColor(RGB(255,255,225));
		pDC->SetBkMode(TRANSPARENT);
		//return m_brush;
	}
	return m_brush;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?