// EditWnd.h : header file // // // Written by Kelly Marie Ward // of Microsoft Developer Support. // Copyright (c) 1998 Microsoft Corporation. All rights reserved. ///////////////////////////////////////////////////////////////////////////#if !defined(AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_) #define AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_#if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 ///////////////////////////////////////////////////////////////////////////// // CEditWnd windowclass CEditWnd : public CEdit { // Construction public: CEditWnd();// Attributes public:// Operations public:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEditWnd) //}}AFX_VIRTUAL// Implementation public: virtual ~CEditWnd(); // Generated message map functions protected: //{{AFX_MSG(CEditWnd) afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); //}}AFX_MSG DECLARE_MESSAGE_MAP() };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
// EditWnd.cpp : implementation file // // // Written by Kelly Marie Ward // of Microsoft Developer Support. // Copyright (c) 1998 Microsoft Corporation. All rights reserved. ///////////////////////////////////////////////////////////////////////////#include "editgrid.h" #include "EditWnd.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CEditWndCEditWnd::CEditWnd() { }CEditWnd::~CEditWnd() { } BEGIN_MESSAGE_MAP(CEditWnd, CEdit) //{{AFX_MSG_MAP(CEditWnd) ON_WM_CHAR() ON_WM_KEYDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CEditWnd message handlersvoid CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar != 13) CEdit::OnChar(nChar, nRepCnt, nFlags); }void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar == 27) //Esc { SetWindowText(""); ShowWindow(SW_HIDE); GetParent()->SetFocus(); } else if (nChar == 13) //Return GetParent()->SetFocus();
CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }
// EditGrid.h : header file // // // Written by Kelly Marie Ward // of Microsoft Developer Support. // Copyright (c) 1998 Microsoft Corporation. All rights reserved. ///////////////////////////////////////////////////////////////////////////#if !defined(AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_) #define AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_#include "flexgrid.h" #include "EditWnd.h"#if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000///////////////////////////////////////////////////////////////////////////// // CEditGrid windowclass CEditGrid : public CMSFlexGrid { // Construction public: CEditGrid();// Attributes public: CEditWnd m_edit; long m_lBorderWidth; long m_lBorderHeight;// Operations public:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEditGrid) //}}AFX_VIRTUAL// Implementation public: int m_nLogY; int m_nLogX; virtual ~CEditGrid(); // Generated message map functions protected: virtual void PreSubclassWindow();
afx_msg void OnKeyPressGrid(short FAR* KeyAscii); afx_msg void OnDblClickGrid(); afx_msg void OnUpdateGrid(); DECLARE_EVENTSINK_MAP() //{{AFX_MSG(CEditGrid) afx_msg UINT OnGetDlgCode(); afx_msg void OnSetFocus(CWnd* pOldWnd); //}}AFX_MSG DECLARE_MESSAGE_MAP() };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
好像很复杂啊。 但我在程序中用的MSFLEXGRID,能不能在这个控件上做修改?
// EditGrid.cpp : implementation file // // // Written by Kelly Marie Ward // of Microsoft Developer Support. // Copyright (c) 1998 Microsoft Corporation. All rights reserved. ///////////////////////////////////////////////////////////////////////////#include "stdafx.h" #include "editgrid.h" #include "EditGrid.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CEditGridCEditGrid::CEditGrid() { }CEditGrid::~CEditGrid() { } BEGIN_MESSAGE_MAP(CEditGrid, CMSFlexGrid) //{{AFX_MSG_MAP(CEditGrid) ON_WM_GETDLGCODE() ON_WM_SETFOCUS() //}}AFX_MSG_MAP END_MESSAGE_MAP()BEGIN_EVENTSINK_MAP(CEditGrid, CMSFlexGrid) //{{AFX_EVENTSINK_MAP(CEditGrid) //}}AFX_EVENTSINK_MAP ON_EVENT_REFLECT(CEditGrid, -603 /* KeyPress */, OnKeyPressGrid, VTS_PI2) ON_EVENT_REFLECT(CEditGrid, -601 /* DblClick */, OnDblClickGrid, VTS_NONE) ON_EVENT_REFLECT(CEditGrid, 72 /* LeaveCell */, OnUpdateGrid, VTS_NONE) END_EVENTSINK_MAP() ///////////////////////////////////////////////////////////////////////////// // CEditGrid message handlersvoid CEditGrid::PreSubclassWindow() { //Calculate border size SetRow(0); SetCol(0); m_lBorderWidth = GetCellLeft(); m_lBorderHeight = GetCellTop(); // To convert grid rect from twips to DC units // We need pixels per inch CDC* pDC = GetDC(); m_nLogX = pDC->GetDeviceCaps(LOGPIXELSX); m_nLogY = pDC->GetDeviceCaps(LOGPIXELSY); ReleaseDC(pDC);
//Create invisible edit control m_edit.Create(WS_CHILD|ES_MULTILINE|ES_WANTRETURN, CRect(0,0,0,0), this, GetDlgCtrlID()); }void CEditGrid::OnDblClickGrid() { short i = 13;
OnKeyPressGrid(&i); //Simulate a return }void CEditGrid::OnKeyPressGrid(short FAR* KeyAscii) {
我的信箱比较的慢。
//
//
// Written by Kelly Marie Ward
// of Microsoft Developer Support.
// Copyright (c) 1998 Microsoft Corporation. All rights reserved.
///////////////////////////////////////////////////////////////////////////#if !defined(AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
#define AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CEditWnd windowclass CEditWnd : public CEdit
{
// Construction
public:
CEditWnd();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEditWnd)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CEditWnd(); // Generated message map functions
protected:
//{{AFX_MSG(CEditWnd)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITWND_H__1F986763_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
//
//
// Written by Kelly Marie Ward
// of Microsoft Developer Support.
// Copyright (c) 1998 Microsoft Corporation. All rights reserved.
///////////////////////////////////////////////////////////////////////////#include "editgrid.h"
#include "EditWnd.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CEditWndCEditWnd::CEditWnd()
{
}CEditWnd::~CEditWnd()
{
}
BEGIN_MESSAGE_MAP(CEditWnd, CEdit)
//{{AFX_MSG_MAP(CEditWnd)
ON_WM_CHAR()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CEditWnd message handlersvoid CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar != 13)
CEdit::OnChar(nChar, nRepCnt, nFlags);
}void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == 27) //Esc
{
SetWindowText("");
ShowWindow(SW_HIDE);
GetParent()->SetFocus();
}
else if (nChar == 13) //Return
GetParent()->SetFocus();
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
//
//
// Written by Kelly Marie Ward
// of Microsoft Developer Support.
// Copyright (c) 1998 Microsoft Corporation. All rights reserved.
///////////////////////////////////////////////////////////////////////////#if !defined(AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
#define AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_#include "flexgrid.h"
#include "EditWnd.h"#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000/////////////////////////////////////////////////////////////////////////////
// CEditGrid windowclass CEditGrid : public CMSFlexGrid
{
// Construction
public:
CEditGrid();// Attributes
public: CEditWnd m_edit;
long m_lBorderWidth;
long m_lBorderHeight;// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEditGrid)
//}}AFX_VIRTUAL// Implementation
public:
int m_nLogY;
int m_nLogX;
virtual ~CEditGrid(); // Generated message map functions
protected: virtual void PreSubclassWindow();
afx_msg void OnKeyPressGrid(short FAR* KeyAscii);
afx_msg void OnDblClickGrid();
afx_msg void OnUpdateGrid();
DECLARE_EVENTSINK_MAP() //{{AFX_MSG(CEditGrid)
afx_msg UINT OnGetDlgCode();
afx_msg void OnSetFocus(CWnd* pOldWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITGRID_H__1F986762_FFEB_11D1_8540_00C04FAD7DBE__INCLUDED_)
但我在程序中用的MSFLEXGRID,能不能在这个控件上做修改?
//
//
// Written by Kelly Marie Ward
// of Microsoft Developer Support.
// Copyright (c) 1998 Microsoft Corporation. All rights reserved.
///////////////////////////////////////////////////////////////////////////#include "stdafx.h"
#include "editgrid.h"
#include "EditGrid.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CEditGridCEditGrid::CEditGrid()
{
}CEditGrid::~CEditGrid()
{
}
BEGIN_MESSAGE_MAP(CEditGrid, CMSFlexGrid)
//{{AFX_MSG_MAP(CEditGrid)
ON_WM_GETDLGCODE()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BEGIN_EVENTSINK_MAP(CEditGrid, CMSFlexGrid)
//{{AFX_EVENTSINK_MAP(CEditGrid)
//}}AFX_EVENTSINK_MAP
ON_EVENT_REFLECT(CEditGrid, -603 /* KeyPress */, OnKeyPressGrid, VTS_PI2)
ON_EVENT_REFLECT(CEditGrid, -601 /* DblClick */, OnDblClickGrid, VTS_NONE)
ON_EVENT_REFLECT(CEditGrid, 72 /* LeaveCell */, OnUpdateGrid, VTS_NONE)
END_EVENTSINK_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditGrid message handlersvoid CEditGrid::PreSubclassWindow()
{
//Calculate border size
SetRow(0);
SetCol(0);
m_lBorderWidth = GetCellLeft();
m_lBorderHeight = GetCellTop(); // To convert grid rect from twips to DC units
// We need pixels per inch
CDC* pDC = GetDC();
m_nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
m_nLogY = pDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pDC);
//Create invisible edit control
m_edit.Create(WS_CHILD|ES_MULTILINE|ES_WANTRETURN,
CRect(0,0,0,0), this, GetDlgCtrlID());
}void CEditGrid::OnDblClickGrid()
{
short i = 13;
OnKeyPressGrid(&i); //Simulate a return
}void CEditGrid::OnKeyPressGrid(short FAR* KeyAscii)
{
ASSERT (KeyAscii != NULL);
m_edit.SetWindowText(GetText()); if (*KeyAscii == 13)
{
m_edit.SetSel(0,-1);
}
else
{
char buf[] = " ";
buf[0] = (char)*KeyAscii;
m_edit.SetSel(-1,-1);
m_edit.ReplaceSel(buf);
}
//Adjust for border heigth and
//Convert from twips to screen units
m_edit.MoveWindow(((GetCellLeft() - m_lBorderWidth) * m_nLogX)/1440,
((GetCellTop() - m_lBorderHeight) * m_nLogY)/1440,
(GetCellWidth()* m_nLogX)/1440,
(GetCellHeight()* m_nLogY)/1440, FALSE); m_edit.ShowWindow(SW_SHOW);
m_edit.SetFocus();
}void CEditGrid::OnUpdateGrid()
{
//Check to see if edit is visible
BOOL bVisible = ::GetWindowLong(m_edit.GetSafeHwnd(), GWL_STYLE) & WS_VISIBLE; if (bVisible)
{
CString cStr;
m_edit.GetWindowText(cStr);
SetText(cStr);
m_edit.SetWindowText("");
m_edit.ShowWindow(SW_HIDE);
}
}UINT CEditGrid::OnGetDlgCode()
{
return DLGC_WANTALLKEYS;
}void CEditGrid::OnSetFocus(CWnd* pOldWnd)
{
CMSFlexGrid::OnSetFocus(pOldWnd);
OnUpdateGrid();
}
我的意思是说这样的方法思路上太过繁琐,希望能有MSFLEXGRID的方法直接实现或有其它的控件来替代它。
不过知识库中的例子我运行过了,和一般的电子表格比起来还是有一点的差距的。只是靠这些代码肯定是不够的。
在这先谢了。
给分。