⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridctrldemodlg.cpp

📁 一个用于地板厂家将不同长度的地板装箱的自动配比程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// GridctrlDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GridctrlDemo.h"
#include "GridctrlDemoDlg.h"
//#include "MdcTex.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 };
	CEdit	m_edsm;
	CString	m_edv;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_edv = _T("");
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_EDIT1, m_edsm);
	DDX_Text(pDX, IDC_EDIT1, m_edv);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGridctrlDemoDlg dialog

CGridctrlDemoDlg::CGridctrlDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGridctrlDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGridctrlDemoDlg)
	m_total = 0;
	m_step = 0;
	m_base = 0;
	m_chk = FALSE;
	m_end = 0;
	m_len = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGridctrlDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGridctrlDemoDlg)
	DDX_Control(pDX, IDC_EDIT5, m_ed5);
	DDX_Control(pDX, IDC_EDIT4, m_ed4);
	DDX_Control(pDX, IDC_SPIN5, m_sp5);
	DDX_Control(pDX, IDC_SPIN4, m_sp4);
	DDX_Control(pDX, IDC_BUTTON3, m_begin);
	DDX_Control(pDX, IDC_EDIT3, m_ed3);
	DDX_Control(pDX, IDC_EDIT2, m_ed2);
	DDX_Control(pDX, IDC_SPIN3, m_sp3);
	DDX_Control(pDX, IDC_SPIN2, m_sp2);
	DDX_Control(pDX, IDC_SPIN1, m_sp1);
	DDX_Text(pDX, IDC_EDIT1, m_total);
	DDV_MinMaxInt(pDX, m_total, 0, 32760);
	DDX_Text(pDX, IDC_EDIT2, m_step);
	DDV_MinMaxInt(pDX, m_step, 0, 3000);
	DDX_Text(pDX, IDC_EDIT3, m_base);
	DDX_Check(pDX, IDC_CHECK1, m_chk);
	DDX_Text(pDX, IDC_EDIT4, m_end);
	DDX_Text(pDX, IDC_EDIT5, m_len);
	//}}AFX_DATA_MAP
	DDX_GridControl(pDX, IDC_GRIDCTRL, m_GridCtrl);
	DDX_GridControl(pDX, IDC_GRIDCTRL2, m_Gr);
	DDX_GridControl(pDX, IDC_GRIDCTRL3, m_Grb);
	DDX_GridControl(pDX, IDC_GRIDCTRL4, m_Gre);

}

BEGIN_MESSAGE_MAP(CGridctrlDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CGridctrlDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_SPIN1, OnOutofmemorySpin1)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDCANCEL_WKH, OnWkh)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGridctrlDemoDlg message handlers

BOOL CGridctrlDemoDlg::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
   //set vars

    m_chk=false;
	m_base=300;
	m_step=50;
	m_total=26;
	m_end=1500;
	m_len=1800;
	m_way=1;
	UpdateData(false);

    
	m_GridCtrl.SetRowCount(20);
    m_GridCtrl.SetFixedRowCount(1);
    m_GridCtrl.SetColumnCount(2);
    m_GridCtrl.SetFixedColumnCount(0);
	//set the init status

	m_GridCtrl.SetColumnWidth (0,82);
	m_GridCtrl.SetColumnWidth (1,92);

		GV_ITEM Item1;
			Item1.mask = GVIF_TEXT|GVIF_FORMAT;
			Item1.row = 0;
			Item1.col = 0;
			Item1.szText.Format("%s","规格(厘米)");
	m_GridCtrl.SetItem (&Item1);
	    Item1.col=1;
    	Item1.szText.Format("%s","现有数量(块)");
	m_GridCtrl.SetItem (&Item1);

   

	
	//deal gr2
	m_Gr.SetRowCount(1);
    m_Gr.SetFixedRowCount(0);
    m_Gr.SetColumnCount(5);
    m_Gr.SetFixedColumnCount(0);
	m_Gr.SetEditable (false);
	m_Gr.SetBkColor (RGB(0,0,0));
	m_index=0;

	//deal gr3
	m_Grb.SetRowCount(1);
    m_Grb.SetFixedRowCount(0);
    m_Grb.SetColumnCount(3);
    m_Grb.SetFixedColumnCount(0);
	m_Grb.SetEditable (false);
	m_Grb.SetBkColor (RGB(255,0,255));
	m_index2=0;

	m_Gre.SetRowCount(1);
    m_Gre.SetFixedRowCount(0);
    m_Gre.SetColumnCount(7);
    m_Gre.SetFixedColumnCount(0);
	m_Gre.SetEditable (false);
	m_Gre.SetBkColor (RGB(20,10,200));
	m_index3=0;
	

	UpdateData(true);
	m_GridCtrl.SetRowCount(m_total+1);

	int col=0;
	int val=0;
	for (int row = 1; row < m_GridCtrl.GetRowCount(); row++)
		{ 
		   val=m_base+(row-1)*m_step;
		   if(val<=m_end)
		   {
			
			GV_ITEM Item;
			Item.mask = GVIF_TEXT|GVIF_FORMAT;
			Item.row = row;
			Item.col = col;
			Item.szText.Format("%d",val);
			m_GridCtrl.SetItem(&Item);
            m_GridCtrl.SetItemData(row,col,val);
			//enable cell
		   }
		}
	  m_GridCtrl.SetItemText (m_total,0,"1800");
    

   //input datas
	/*
	long temp[27]={0,6200,5600,4733,6100,4533,3250,2000,6895,1243,4457,6320,1032,1980,1756,1230,5000,1450,6455,1870,2300,1244,1588,1685,1230,1000,2235};
	col=1;
	for ( row = 1; row < m_GridCtrl.GetRowCount(); row++)
		{ 
		   val=temp[row];
			GV_ITEM Item;
			Item.mask = GVIF_TEXT|GVIF_FORMAT;
			Item.row = row;
			Item.col = col;
			Item.szText.Format("%d",val);
			m_GridCtrl.SetItem(&Item);
            m_GridCtrl.SetItemData(row,col,val);
		   
		}
	*/
	m_begin.EnableWindow (true);
    
  return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGridctrlDemoDlg::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 CGridctrlDemoDlg::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();
	}
}

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

void CGridctrlDemoDlg::OnOK() 
{
	// TODO: Add extra validation here
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
	
}

void CGridctrlDemoDlg::OnOutofmemorySpin1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_sp1.Invalidate (true);
	UpdateData(false);
	*pResult = 0;
}

void CGridctrlDemoDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		UpdateData(true);
		if(m_base>m_end) 
		{
		 AfxMessageBox("自动生成的终值必须大于或等于初值!!",MB_ICONWARNING);
         return;
		}
	m_GridCtrl.SetRowCount(m_total+1);
	if(m_chk)
	{
	int col=0;
	int val=0;
	for (int row = 1; row < m_GridCtrl.GetRowCount(); row++)
		{ 
		   val=m_base+(row-1)*m_step;
		   if(val<=m_end)
		   {
			
			GV_ITEM Item;
			Item.mask = GVIF_TEXT|GVIF_FORMAT;
			Item.row = row;
			Item.col = col;
			Item.szText.Format("%d",val);
			m_GridCtrl.SetItem(&Item);
            m_GridCtrl.SetItemData(row,col,val);
		   }
		}
	  m_GridCtrl.SetItemText (m_total,0,"1800");
   //input datas
	long temp[27]={0,6200,5600,4733,2100,4533,1250,1000,6895,1243,4457,6320,1032,1980,1756,1230,1000,1450,6455,870,2300,1244,1588,685,1230,1000,2235};
	col=1;
	for ( row = 1; row < m_GridCtrl.GetRowCount(); row++)
		{ 
		   val=temp[row];
			GV_ITEM Item;
			Item.mask = GVIF_TEXT|GVIF_FORMAT;
			Item.row = row;
			Item.col = col;
			Item.szText.Format("%d",val);
			m_GridCtrl.SetItem(&Item);
            m_GridCtrl.SetItemData(row,col,val);
		   
		}
	

	}

	m_begin.EnableWindow (true);
}

void CGridctrlDemoDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_chk)
	{
		m_ed2.EnableWindow (true);
	    m_ed3.EnableWindow (true);
		m_ed4.EnableWindow (true);
		m_sp2.EnableWindow (true);
		m_sp3.EnableWindow (true);
		m_sp4.EnableWindow (true);
	}
	else
	{
        m_ed2.EnableWindow (false);
	    m_ed3.EnableWindow (false);
		m_ed4.EnableWindow (false);
		m_sp2.EnableWindow (false);
		m_sp3.EnableWindow (false);
		m_sp4.EnableWindow (false);
	}
}

void CGridctrlDemoDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
    m_chk=false;
	m_base=300;
	m_step=50;
	m_total=26;
	m_end=1500;
	m_len=1800;
	UpdateData(false);
	m_ed2.EnableWindow (false);
	m_ed3.EnableWindow (false);
	m_ed4.EnableWindow (false);
    m_sp2.EnableWindow (false);
	m_sp3.EnableWindow (false);
    m_sp4.EnableWindow (false);
	m_begin.EnableWindow (false);
}


//////////////////////////////////////////////////////////////////Important area
void CGridctrlDemoDlg::computedata()
{
	 m_Gr.SetRowCount (1);
	 m_index=0;
	 m_Grb.SetRowCount (1);
	 m_index2=0;

⌨️ 快捷键说明

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