?? 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 + -