📄 ch7demo7dlg.cpp
字号:
// Ch7Demo7Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Ch7Demo7.h"
#include "Ch7Demo7Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CCh7Demo7Dlg dialog
CCh7Demo7Dlg::CCh7Demo7Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CCh7Demo7Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCh7Demo7Dlg)
m_value = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCh7Demo7Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCh7Demo7Dlg)
DDX_Control(pDX, IDC_MSHFLEXGRID1, m_flexgrid);
DDX_Text(pDX, IDC_EDIT1, m_value);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCh7Demo7Dlg, CDialog)
//{{AFX_MSG_MAP(CCh7Demo7Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CHECKIN, OnCheckin)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCh7Demo7Dlg message handlers
BOOL CCh7Demo7Dlg::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
m_nRow=1;
m_nCol=1;
char* colHead[5]={"燕小六","李大嘴","白展堂","刑捕头","吕轻候"};
char* rowHead[3]={"英语","计算机","数学"};
m_flexgrid.SetRow(0); //定位到表格第一行
for(int nCol=0;nCol<3;nCol++) //添加行头
{
m_flexgrid.SetCol(nCol+1);
m_flexgrid.SetText(rowHead[nCol]);
}
m_flexgrid.SetCol(0); //定位到表格第一列
for(int nRow=0;nRow<5;nRow++) //添加列头
{
m_flexgrid.SetRow(nRow+1);
m_flexgrid.SetText(colHead[nRow]);
}
m_flexgrid.SetBackColor(RGB(255,255,200)); //设置表格背景色
GetDlgItem(IDC_EDIT1)->EnableWindow(false);//禁用编辑框
GetDlgItem(IDC_CHECKIN)->EnableWindow(false);//禁用提交按钮
return TRUE; // return TRUE unless you set the focus to a control
}
void CCh7Demo7Dlg::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 CCh7Demo7Dlg::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 CCh7Demo7Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCh7Demo7Dlg::OnCheckin()
{
// TODO: Add your control notification handler code here
m_flexgrid.SetRow(m_nRow);
m_flexgrid.SetCol(m_nCol);
m_flexgrid.SetFocus(); //表格捕获焦点
UpdateData(TRUE); //获取编辑框值
CString str;
str.Format("%01.1f",m_value); //格式化
m_flexgrid.SetText(str); //编辑框数据输入相应表格
GetDlgItem(IDC_EDIT1)->EnableWindow(false);//禁用编辑框
GetDlgItem(IDC_CHECKIN)->EnableWindow(false);//禁用提交按钮
}
BEGIN_EVENTSINK_MAP(CCh7Demo7Dlg, CDialog)
//{{AFX_EVENTSINK_MAP(CCh7Demo7Dlg)
ON_EVENT(CCh7Demo7Dlg, IDC_MSHFLEXGRID1, -601 /* DblClick */, OnDblClickMshflexgrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CCh7Demo7Dlg::OnDblClickMshflexgrid1()
{
// TODO: Add your control notification handler code here
CString szText=m_flexgrid.GetText();
m_value=atof(szText); //转换为double型传给编辑框变量
UpdateData(FALSE); //编辑框显示表格值
m_nRow=m_flexgrid.GetRow(); //获取表格当前行
m_nCol=m_flexgrid.GetCol(); //获取表格当前列
GetDlgItem(IDC_EDIT1)->EnableWindow(true);//激活编辑框
GetDlgItem(IDC_CHECKIN)->EnableWindow(true);//激活提交按钮
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -