📄 program2dlg.cpp
字号:
// TODO: Add extra initialization here
m_OK.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_Cancel.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSureExit::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSureExit)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSureExit, CDialog)
//{{AFX_MSG_MAP(CSureExit)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// SheetDlg dialog
class SheetDlg : public CDialog
{
// Construction
public:
SheetDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(SheetDlg)
enum { IDD = IDD_Sheet };
CWBButton m_OK;
CWBButton m_Cancel;
CString m_Sheet;
int m_TabelCols;
int m_TabelRows;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(SheetDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(SheetDlg)
virtual BOOL OnInitDialog();
afx_msg void OnUpdateTabelRows();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
SheetDlg::SheetDlg(CWnd* pParent /*=NULL*/)
: CDialog(SheetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(SheetDlg)
m_Sheet = _T("");
m_TabelCols = 0;
m_TabelRows = 0;
//}}AFX_DATA_INIT
}
BOOL SheetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_OK.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_Cancel.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void SheetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SheetDlg)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Text(pDX, IDC_Sheet, m_Sheet);
DDX_Text(pDX, IDC_TabelCols, m_TabelCols);
DDX_Text(pDX, IDC_TabelRows, m_TabelRows);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SheetDlg, CDialog)//消息传递函数接口
//{{AFX_MSG_MAP(SheetDlg)
ON_EN_UPDATE(IDC_TabelRows, OnUpdateTabelRows)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SheetDlg message handlers
void SheetDlg::OnUpdateTabelRows()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_TabelRows<1)
{
MessageBox(" 至少包含一行标题 ","出错啦");
m_TabelRows=1;
}
UpdateData(false);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CProGram2Dlg dialog
CProGram2Dlg::CProGram2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CProGram2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProGram2Dlg)
m_MeanRows = 0;
m_MeanCols = 0;
m_sChange = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CProGram2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProGram2Dlg)
//DEL DDX_Control(pDX, IDButtonRowUp, m_ButtonRowUp);
//DEL DDX_Control(pDX, IDButtonColUp, m_ButtonColUp);
//DEL DDX_Control(pDX, IDButtonColDown, m_ButtonColDown);
//DEL DDX_Control(pDX, IDBuntonRowDown, m_ButtonRowDown);
DDX_Control(pDX, IDC_EDIT1, m_Change);
DDX_Control(pDX, IDC_MSFLEXGRID1, m_FlexGrid);
DDX_Text(pDX, IDC_EDITMeanRows, m_MeanRows);
DDX_Text(pDX, IDC_EDITMeanCols, m_MeanCols);
DDX_Text(pDX, IDC_EDIT1, m_sChange);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProGram2Dlg, CDialog)
//{{AFX_MSG_MAP(CProGram2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_MENU1_EXIT, OnMenu1Exit)
ON_COMMAND(ID_MENU3_ABOUT, OnMenu3About)
ON_COMMAND(ID_MENU1_CLEARN, OnMenu1Clearn)
ON_COMMAND(ID_MENU1_NEW, OnMenu1New)
ON_BN_CLICKED(IDC_BuntonRowDown, OnBuntonRowDown)
ON_BN_CLICKED(IDC_ButtonColDown, OnButtonColDown)
ON_BN_CLICKED(IDC_ButtonColUp, OnButtonColUp)
ON_BN_CLICKED(IDC_ButtonRowUp, OnButtonRowUp)
ON_COMMAND(ID_MENU3_HELP, OnMenu3Help)
ON_COMMAND(ID_MENU2_MAIN, OnMenu2Main)
ON_COMMAND(ID_MENU2_ONorIN, OnMENU2ONorIN)
ON_COMMAND(ID_MENU2_FACTORS, OnMenu2Factors)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEditChange)
ON_COMMAND(ID_MENU1_GetIn, OnMENU1GetIn)
ON_COMMAND(ID_MENU1_PutOut, OnMENU1PutOut)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProGram2Dlg message handlers
BOOL CProGram2Dlg::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
m_IsDataHasTabel=0;
m_IsDataHasTabelOnCol=0;
//DEL m_ButtonRowUp.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
//DEL m_ButtonColUp.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
//DEL m_ButtonColDown.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
//DEL m_ButtonRowDown.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
// TODO: Add extra initialization here
///////////////////////////////////////////
///
///
///行列初始化
m_MeanRows=0;//有效行列初始化
m_MeanCols=0;
m_lRow=0;
m_lCol=0;
m_NumRows=300;
m_NumCols=100;
m_FlexGrid.SetCols(m_NumCols);
m_FlexGrid.SetRows(m_NumRows);
m_FlexGrid.SetRow(0);
m_FlexGrid.SetCol(0);
m_FlexGrid.SetText("品种\\性状");
m_FlexGrid.SetRow(0);
CString s;
for(int i=1;i<m_NumCols;i++)
{
m_FlexGrid.SetCol(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
m_FlexGrid.SetCol(0);
for(i=1;i<m_NumRows;i++)
{
m_FlexGrid.SetRow(i);
s.Format(" %d ",i);
m_FlexGrid.SetText(s);
}
/////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CProGram2Dlg::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 CProGram2Dlg::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 CProGram2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BEGIN_EVENTSINK_MAP(CProGram2Dlg, CDialog)
//{{AFX_EVENTSINK_MAP(CProGram2Dlg)
ON_EVENT(CProGram2Dlg, IDC_MSFLEXGRID1, -600 /* Click */, OnClickMsflexgrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
/////////////////////////////////////////////////////////////////////////////
///
///点击列表框
void CProGram2Dlg::OnClickMsflexgrid1()
{
long lRow = m_FlexGrid.GetRowSel();//获取点击的行号
long lCol = m_FlexGrid.GetColSel(); //获取点击的列号
// TODO: Add your control notification handler code here
if(lRow>m_NumRows-2 || lCol>m_NumCols-2) //如果点击区超过最大行号,则点击是无效的
return;
if(lRow==0 || lCol==0)
return;
m_lRow=lRow;
m_lCol=lCol;
///
///
///点击测试
// CString S;
// S.Format("%d行%d列",lRow,lCol);
// MessageBox(S);
///
///
///
CRect rect;
m_FlexGrid.GetWindowRect(rect); //获取表格控件的窗口矩形
ScreenToClient(rect); //转换为客户区矩形
// MSFlexGrid 控件的函数的长度单位是"缇(twips)",
//需要将其转化为像素,1440 缇 = 1 英寸
CDC* pDC=GetDC();
int nTwipsPerDotX=1440/pDC->GetDeviceCaps(LOGPIXELSX);
int nTwipsPerDotY=1440/pDC->GetDeviceCaps(LOGPIXELSY);
//计算选中格的左上角的坐标(象素为单位)
long y=m_FlexGrid.GetRowPos(lRow)/nTwipsPerDotY;
long x=m_FlexGrid.GetColPos(lCol)/nTwipsPerDotX;
//计算格子大小,3和2.5是调试总结的结果
long width=m_FlexGrid.GetColWidth(lCol)/nTwipsPerDotX+1;
long height=m_FlexGrid.GetRowHeight(lRow)/nTwipsPerDotY+1;
//形成选中所在的矩形区域
CRect rc(x,y,x+width,y+height);
//转换为相对对话框坐标
rc.OffsetRect(rect.left+3,rect.top+3);
CString strValue=m_FlexGrid.GetTextMatrix(lRow,lCol);
m_Change.ShowWindow(SW_SHOW);
m_Change.SetWindowText(strValue);
// m_sChange=strValue;
m_Change.SetFocus();
m_Change.SetSel(0,-1);
m_Change.MoveWindow(rc);
}
//////////////////////////////////////////////////////
///
///菜单函数
////////////////
///
///导入Excel数据
void CProGram2Dlg::OnMENU1GetIn()
{
// TODO: Add your command handler code here
CFileDialog File(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"表格(*.xls)|*.xls||");
if(File.DoModal()==IDOK)
{
CString sPath=File.GetPathName();
SheetDlg dlg;
dlg.m_Sheet="Sheet1";
dlg.m_TabelCols=0;
dlg.m_TabelRows=1;
if(dlg.DoModal()==IDOK)
{
CString s=dlg.m_Sheet;
int tabelRows=dlg.m_TabelRows;//记录数据原的标签行列数
int tabelCols=dlg.m_TabelCols;//
if(s=="")
return;
else
{
// AfxMessageBox(sPath+s);//表格位置检验
CSpreadSheet SS(sPath,s);
CStringArray Rows,Column;
///
// CString s;
// s.Format("表格行数:%d列数%d",SS.GetTotalRows(),SS.GetTotalColumns());//行列数检验
// MessageBox(s);
///
if(SS.GetTotalRows()<=0)
{
MessageBox(" 确定表格不为空 ","出错啦");
return;
}
else
{
//ShowWindow(SW_MINIMIZE);//隐藏窗口,在后台录入数据
//ShowWindow(SW_RESTORE);//显示窗口
OnMenu1New();//清空表格
ShowWindow(SW_MINIMIZE);
int i,j;
m_IsDataHasTabel=1;
if(tabelCols>0)
m_IsDataHasTabelOnCol=1;
///
/// CString s="";
/// SS.ReadColumn(Column,1);
/// s=Column.GetAt(0);
/// MessageBox(s);
///
UpdateData(true);
m_MeanRows=SS.GetTotalRows()-tabelRows;
m_MeanCols=SS.GetTotalColumns()-tabelCols;
UpdateData(false);
SS.ReadRow(Rows,tabelRows);
m_FlexGrid.SetRow(0);
for(i=1;i<=SS.GetTotalColumns();i++)//读入行标签
{
m_FlexGrid.SetCol(i);
m_FlexGrid.SetText(Rows.GetAt(i-1));
}
for(i=tabelRows+1;i<=SS.GetTotalRows();i++)
{
m_FlexGrid.SetRow(i-tabelRows);
SS.ReadRow(Rows,i);//读取第i行
if(tabelCols>0)//读标签列
{
m_FlexGrid.SetCol(0);
m_FlexGrid.SetText(Rows.GetAt(0));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -